Revalidate E-Mail Address upon user changes E-Mail Address

Permalink
Hi all!

Is there a simple way to trigger the "user must validate his e-mail address" process?

Situation: User can register and then edit his personal data, so he can also change his email Address, which is ok, he might want to use another or...whatever

Problem: No revalidation of new Email-Address...

Is there a simple way?

Regards,
André

nforcer
 
olsgreen replied on at Permalink Reply
olsgreen
Yes but no!

If you have a look inside the login contoller, within /concrete/controllers/login.php, you will see the function:

// responsible for validating a user's email address
   public function v($hash) {
      $ui = UserInfo::getByValidationHash($hash);
      if (is_object($ui)) {
         $ui->markValidated();
         $this->set('uEmail', $ui->getUserEmail());
         $this->set('validated', true);
      }
   }


This is what is called to send the validation e-mail & setup the validation token.

The easiest way is to copy this function into your profile edit controller and then call it on edit, you will also need to set the validation entry within the users table back to false (to prevent the user logging in again until the address is revalidated. You could do this with another function in your profile controller like this:

//Changes the users record back to not validated
function markNotValidated($uID) {
         $db = Loader::db();
         $v = array($uID);
         $db->query("update Users set uIsValidated = 0 where uID = ?", $v);
         return true;
      }


Then you'll need to log the user out and tell them to check thier mail.

Should steer you in the right direction,

Oli
nforcer replied on at Permalink Reply
nforcer
Hi!

Thanks for the fast answer, but what exactly do I need v() for? To me it seems to mark the user as validated and does not send the mail... The later function (markNotValidated) seems more useful, but how do i create the new hash (do i have to?) and resend the mail?

Regards,
André
olsgreen replied on at Permalink Reply
olsgreen
The function i put together for you (markNotValidated) marks the users record as not being validated anymore.

After you run that function you will need to call v() to generate the new validation hash and send the new email to the user.

So yes, the v() function creates the new hash and sends the user the email containing it.

O