Example #1
0
 /** @noinspection PhpUnusedPrivateMethodInspection
  * @param Request $request
  *
  * @return bool|int
  */
 private function changeMail(Request $request)
 {
     $password = Validator::sanitizeText($request->post('password'));
     if (!$password || !$this->auth->validateLogin($this->user->getName(), $password)) {
         $this->errors[] = 'Invalid password';
         return false;
     }
     $mail = Validator::sanitizeEmail($request->post('mail'));
     $mail_confirm = Validator::sanitizeEmail($request->post('mail_confirm'));
     if (!$mail || !$mail_confirm) {
         $this->errors[] = 'New email address is required but invalid';
         return false;
     }
     if ($mail !== $mail_confirm) {
         $this->errors[] = 'Entered email addresses are not the same';
         return false;
     }
     try {
         return $this->model->update($this->user->getId(), array('mail' => $mail));
     } catch (DBDuplicateEntryException $e) {
         $this->errors[] = 'This email address is already in use';
         return false;
     }
 }