Esempio n. 1
0
 /**
  * @param User $user
  *
  * @return string
  * @throws exceptions\DBDuplicateEntryException
  * @throws exceptions\DBForeignKeyException
  */
 public function store(User $user)
 {
     $query = 'INSERT INTO users (name, mail) VALUES (:name, :mail);';
     $this->db->prepare($query);
     $this->db->bindValue(':name', $user->getName());
     $this->db->bindValue(':mail', $user->getMail());
     $this->db->execute();
     return $this->db->lastInsertId();
 }
Esempio n. 2
0
 /** @noinspection PhpUnusedPrivateMethodInspection
  * @param Request $request
  *
  * @return bool|int
  */
 private function changePassword(Request $request)
 {
     $password = Validator::sanitizeText($request->post('password'));
     if (!$password || !$this->auth->validateLogin($this->user->getName(), $password)) {
         $this->errors[] = 'Invalid current password';
         return false;
     }
     $password_new = Validator::sanitizeText($request->post('password_new'));
     $password_confirm = Validator::sanitizeText($request->post('password_confirm'));
     if (!$password_new || !$password_confirm) {
         $this->errors[] = 'New password required but invalid';
         return false;
     }
     if ($password_new !== $password_confirm) {
         $this->errors[] = 'Entered passwords are not the same';
         return false;
     }
     return $this->auth->setPassword($this->user->getName(), $password_new);
 }