/**
  * 
  * @param array $data
  * @param string $e
  * @return array
  */
 public function register($data, $e)
 {
     try {
         Validator::validatePassword($data['password']);
         $entity = $this->_validateEntityAgainstUser($this->_getByPersonalCode($this->_validatePersonalCode($data), $e));
         $lisUser = $this->getEntityManager()->getRepository('Core\\Entity\\LisUser')->findOneBy(['email' => $data['email']]);
         if (!$lisUser) {
             //user does not exist create one
             $lisUser = $this->getEntityManager()->getRepository('Core\\Entity\\LisUser')->Create($data);
         }
         $entity->setLisUser($lisUser)->setEmail($data['email']);
         //associate
         $this->getEntityManager()->persist($entity);
         $this->getEntityManager()->flush($entity);
         return ['success' => true, 'email' => $entity->getEmail()];
     } catch (Exception $ex) {
         return ['success' => false, 'message' => $ex->getMessage()];
     }
 }
Beispiel #2
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'];
     }
 }