How can we let other modules know that we've changed the Email? Do you think that adding a user hook invoke can be a solution?

I'm thinking on a solution (patch) like this in function function email_confirm_user_change_mail(). This is around line 187:

      watchdog('user', t('User %name used one-time e-mail change link at time %timestamp.', array('%name' => $account->name, '%timestamp' => $timestamp)));
      db_query("UPDATE {users} SET mail = '%s' WHERE uid = %d", $new_mail, $account->uid);
      user_module_invoke('mail_changed', array('new_mail' => $new_mail), $account);
      drupal_set_message(t('Your e-mail address is now %mail.', array('%mail' => $new_mail)));

This allow a module to invoke the hook in this way:

function mymodule_user($op, $edit, $account) {
  if ($op == 'mail_changed') {
    
    //... perform some tasks... You can use $edit['new_mail']
  
  }

}

I need this in a custom module but I want to take an approach that maybe will be included in future releases of the module.

Comments

claudiu.cristea’s picture

Version: 5.x-1.3 » 5.x-1.4
Status: Active » Needs review
StatusFileSize
new823 bytes

Here's a patch against 5.x-1.4.

jaydub’s picture

Version: 5.x-1.4 » 6.x-1.x-dev
Status: Needs review » Fixed

I've added a hook to Email Confirm to allow any module to act on email change requests as well as the successful confirmation of an email change request. This means that any sort of tracking that one would want to do is now possible but I'm leaving the implementation of that tracking open to anyone's particular needs by supplying the hook.

The hook follows this model:

hook_email_confirm($op, $uid, $old_email, $new_email)

Where $op is either 'email change' or 'email confirmation' corresponding to the request to change email address and the confirmation of the email change via clicking the confirmation link in the email sent out as a result of the request to change. The other parameters are self-explanatory.

claudiu.cristea’s picture

Thank you. Is this fixed also in 5.x?

jaydub’s picture

yes the hook is implemented the same way in both 5.x and 6.x. I'll put together a new release for both in the next day or two.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.