public function confirmEmail($User, $EmailKey)
{
$Attributes = val('Attributes', $User);
$StoredEmailKey = val('EmailKey', $Attributes);
$UserID = val('UserID', $User);
if (!$StoredEmailKey || $EmailKey != $StoredEmailKey) {
$this->Validation->addValidationResult('EmailKey', '@' . t('Couldn\'t confirm email.', 'We couldn\'t confirm your email. Check the link in the email we sent you or try sending another confirmation email.'));
return false;
}
$confirmRoleIDs = RoleModel::getDefaultRoles(RoleModel::TYPE_UNCONFIRMED);
$defaultRoles = RoleModel::getDefaultRoles(RoleModel::TYPE_MEMBER);
// Update the user's roles.
$UserRoles = $this->getRoles($UserID);
$UserRoleIDs = [];
while ($UserRole = $UserRoles->nextRow(DATASET_TYPE_ARRAY)) {
$UserRoleIDs[] = $UserRole['RoleID'];
}
// Sanitize result roles
$Roles = array_diff($UserRoleIDs, $confirmRoleIDs);
if (!sizeof($Roles)) {
$Roles = $defaultRoles;
}
$this->EventArguments['ConfirmUserID'] = $UserID;
$this->EventArguments['ConfirmUserRoles'] =& $Roles;
$this->fireEvent('BeforeConfirmEmail');
$this->saveRoles($UserID, $Roles, false);
// Remove the email confirmation attributes.
$this->saveAttribute($UserID, ['EmailKey' => null]);
$this->setField($UserID, 'Confirmed', 1);
return true;
}