Пример #1
0
 /**
  * NB user can have many results
  * NB thin some way to deal brute force
  * 
  * @param array $data
  * @param string $role
  * @return array
  */
 public function authenticate($data, $role)
 {
     try {
         $this->logout(1);
         //logout first
         $email = Validator::validateEmail($data['email']);
         $password = Validator::validatePassword($data['password']);
         if ($role === 'administrator') {
             $this->auth($email, $password, 'Core\\Entity\\Administrator', $role);
         } else {
             if ($role === 'teacher') {
                 $this->auth($email, $password, 'Core\\Entity\\Teacher', $role);
             } else {
                 if ($role === 'student') {
                     $this->auth($email, $password, 'Core\\Entity\\Student', $role);
                 } else {
                     throw new Exception('NO_ROLE_SPECIFIED');
                 }
             }
         }
     } catch (Exception $ex) {
         return ['success' => false, 'message' => 'FALSE_ATTEMPT'];
     }
 }