add email verification users

This commit is contained in:
Guillermo Giuliana 2021-12-23 22:23:33 -03:00
parent bfb7256400
commit edfac8f3b2
1 changed files with 18 additions and 0 deletions

View File

@ -42,7 +42,11 @@ class EditEmail extends Controller{
$newEmail = Controller::request('newEmail');
$user = Controller::getLoggedUser();
$oldEmail = $user->email;
$this->verifyEmail($newEmail, $user);
$user->email = $newEmail;
$user->store();
$mailSender = MailSender::getInstance();
@ -55,4 +59,18 @@ class EditEmail extends Controller{
Response::respondSuccess();
}
private function verifyEmail($email, $logedUser){
$staff = Staff::getDataStore($email,'email');
$user = User::getDataStore($email,'email');
if($user->email == $email && $logedUser->email != $email){
throw new RequestException(ERRORS::INVALID_EMAIL);
}
if($staff->email == $email){
throw new RequestException(ERRORS::INVALID_EMAIL);
}
}
}