From edfac8f3b25019744d3976a9eef2601a99c1aa85 Mon Sep 17 00:00:00 2001 From: Guillermo Giuliana Date: Thu, 23 Dec 2021 22:23:33 -0300 Subject: [PATCH] add email verification users --- server/controllers/user/edit-email.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/controllers/user/edit-email.php b/server/controllers/user/edit-email.php index c7617373..d8cd7b5e 100755 --- a/server/controllers/user/edit-email.php +++ b/server/controllers/user/edit-email.php @@ -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); + } + } } \ No newline at end of file