communityii / yii2-user

Configurable Yii 2 user management module with social authentication and various controls
https://groups.google.com/d/forum/communityii
Other
50 stars 9 forks source link

Implement e-mailer with events #5

Open schmunk42 opened 10 years ago

schmunk42 commented 10 years ago
kartik-v commented 10 years ago

Extending on this thought... how do we handle e-mail exceptions/failures/errors? Currently there is no option for a newly registered user to get activated, if he does not receive an activation email, due to some error. I have found most user modules do not address this by default.

Solutions/Approaches:

  1. QUEUING: Offer a simple db queue to enqueue mails. Based on a module level setting, an email for activation or recovery can be chosen to be enqueued or sent directly. In either case, mails not sent will be available in the db queue with reason for failure. Admins can read this queue through an UI and take action or developers can also create a cron process to read this queue for batch email processing if needed. IMO, we should offer an option for this.. it requires an additional table with few fields.
  2. EVENTS: Just give options to developer to add in own code for mail processing, without changing the controller actions or models.
schmunk42 commented 10 years ago

It depends on the cause. If the user mistyped his email it is OK not to activate the account. Some cases are even covered by the e-mail validator. If we have an error in our code, well - we should test it before.

But we may also add a functionality to resend an activation email and to test the email functionality in general.

I just found out, that the event case is covered by some sample code in the docs... https://github.com/yiisoft/yii2/blob/master/docs/guide/events.md#triggering-events

I think it would be also pretty easy to use a queue with the event system. In fact, that's another reason for using events, since what happens after registration, activation, etc ... may be so complex.

kartik-v commented 10 years ago

The email sending errors could also be due to email server issues at that point, (due to system load, smtp timeout, or someone is using a third party service that is down at that point).

The use case is - the user may have registered with a genuine email - but he/she did not receive the activation email. The system would also have generated an activation key internally - but we have no way to validate it or send it to the user.

Queuing will offer an option to trace and retry such situations.

I agree, we could combine both the queue with event system as you said.

I will come out with a simple queue structure (which would be an optional plugin to this and enabled by default). You may wish to enhance this with the event system you proposed.

kartik-v commented 10 years ago

Queue structure is now available in the MailQueue model.

evercode1 commented 10 years ago

Just wanted to make sure I understood something. I'm assuming in Module.php that:

$this->registrationSettings += [ ... 'autoActivate' => true, ...
];

If this is set to true would mean that they do not need to confirm by email to be made an active user? Sorry if it's an obvious question, just checking, thanks.

schmunk42 commented 10 years ago

I think it depends on what you want. I saw some sites where you've registered and you were instantly able to start using the application. This is the "loosest" validation. Another one would be to auto-login the user after he has confirmed the e-mail address. The most strict validation would be to manually activate the user after reviewing his credentials.

schmunk42 commented 10 years ago

@kartik-v Could you explain a bit, why do we need a mail queue table? Is it mainly for logging? https://github.com/communityii/yii2-user/blob/master/migrations/m140402_143411_create_user_module.php#L98

If you have a component in your application which handles a mail queue, we can hand over the sending of a mail to the component. The only problem I see so far is how to return the result of sending the e-mail to the user module, when it is queued or delayed, I think we need an API for that (but maybe not in release 1.0)

kartik-v commented 10 years ago

@evercode1: If this is set to true would mean that they do not need to confirm by email to be made an active user?

Yes that's correct and as @schmunk42 elaborated

@schmunk42: Could you explain a bit, why do we need a mail queue table?

Usage is planned to be like below:

The key advantages: