I'm trying to determine if a user has changed their email address via a front-end form. From what I've gleaned, the best way to do this would be by checking the existing record during users.beforeSaveUser
, store the old email, then compare to the new email during users.onSaveUser
.
However, when I get a user's record during users.beforeSaveUser
, the newly-submitted email address has already overwritten their record.
craft()->on('users.beforeSaveUser', function(Event $event)
{
if(!$event->params['isNewUser'])
{
$currentUser = craft()->users->getUserById($user->id);
exit($currentUser->email);
}
}
This code shows the new email, not the old one.
Is this expected behaviour? Any other way to accomplish what I need to?