示例#1
0
 /**
  * Authenticate the user
  *
  * @access public
  * @param  string  $username  Username
  * @param  string  $password  Password
  * @return boolean
  */
 public function authenticate($username, $password)
 {
     $result = $this->findUser($username, $password);
     if (is_array($result)) {
         $user = $this->user->getByUsername($username);
         if ($user) {
             // There is already a local user with that name
             if ($user['is_ldap_user'] == 0) {
                 return false;
             }
         } else {
             // We create automatically a new user
             if ($this->createUser($username, $result['name'], $result['email'])) {
                 $user = $this->user->getByUsername($username);
             } else {
                 return false;
             }
         }
         // We open the session
         $this->user->updateSession($user);
         // Update login history
         $this->lastLogin->create(self::AUTH_NAME, $user['id'], Request::getIpAddress(), Request::getUserAgent());
         return true;
     }
     return false;
 }
示例#2
0
 /**
  * Authenticate a user
  *
  * @access public
  * @param  string  $username  Username
  * @param  string  $password  Password
  * @return boolean
  */
 public function authenticate($username, $password)
 {
     $user = $this->db->table(User::TABLE)->eq('username', $username)->eq('is_ldap_user', 0)->findOne();
     if ($user && password_verify($password, $user['password'])) {
         // Update user session
         $this->user->updateSession($user);
         // Update login history
         $this->lastLogin->create(self::AUTH_NAME, $user['id'], Request::getIpAddress(), Request::getUserAgent());
         return true;
     }
     return false;
 }
示例#3
0
 /**
  * Authenticate a Google user
  *
  * @access public
  * @param  string  $google_id   Google unique id
  * @return boolean
  */
 public function authenticate($google_id)
 {
     $user = $this->user->getByGoogleId($google_id);
     if ($user) {
         // Create the user session
         $this->user->updateSession($user);
         // Update login history
         $this->lastLogin->create(self::AUTH_NAME, $user['id'], Request::getIpAddress(), Request::getUserAgent());
         return true;
     }
     return false;
 }
示例#4
0
 /**
  * Authenticate the user with the HTTP header
  *
  * @access public
  * @return bool
  */
 public function authenticate()
 {
     if (isset($_SERVER[REVERSE_PROXY_USER_HEADER])) {
         $login = $_SERVER[REVERSE_PROXY_USER_HEADER];
         $user = $this->user->getByUsername($login);
         if (!$user) {
             $this->createUser($login);
             $user = $this->user->getByUsername($login);
         }
         // Create the user session
         $this->user->updateSession($user);
         // Update login history
         $this->lastLogin->create(self::AUTH_NAME, $user['id'], Request::getIpAddress(), Request::getUserAgent());
         return true;
     }
     return false;
 }
示例#5
0
 /**
  * Authenticate the user with the cookie
  *
  * @access public
  * @return bool
  */
 public function authenticate()
 {
     $credentials = $this->readCookie();
     if ($credentials !== false) {
         $record = $this->find($credentials['token'], $credentials['sequence']);
         if ($record) {
             // Update the sequence
             $this->writeCookie($record['token'], $this->update($record['token']), $record['expiration']);
             // Create the session
             $this->user->updateSession($this->user->getById($record['user_id']));
             $this->acl->isRememberMe(true);
             // Update last login infos
             $this->lastLogin->create(self::AUTH_NAME, $this->acl->getUserId(), Request::getIpAddress(), Request::getUserAgent());
             return true;
         }
     }
     return false;
 }
示例#6
0
 public function onSuccess(AuthEvent $event)
 {
     $this->lastLogin->create($event->getAuthType(), $event->getUserId(), Request::getIpAddress(), Request::getUserAgent());
 }
示例#7
0
 /**
  * Validate user login form
  *
  * @access public
  * @param  array   $values           Form values
  * @return array   $valid, $errors   [0] = Success or not, [1] = List of errors
  */
 public function validateForm(array $values)
 {
     $v = new Validator($values, array(new Validators\Required('username', t('The username is required')), new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50), new Validators\Required('password', t('The password is required'))));
     $result = $v->execute();
     $errors = $v->getErrors();
     if ($result) {
         if ($this->authenticate($values['username'], $values['password'])) {
             // Setup the remember me feature
             if (!empty($values['remember_me'])) {
                 $credentials = $this->backend('rememberMe')->create($this->userSession->getId(), Request::getIpAddress(), Request::getUserAgent());
                 $this->backend('rememberMe')->writeCookie($credentials['token'], $credentials['sequence'], $credentials['expiration']);
             }
         } else {
             $result = false;
             $errors['login'] = t('Bad username or password');
         }
     }
     return array($result, $errors);
 }
示例#8
0
 /**
  * Create remember me session if necessary
  *
  * @access private
  * @param  array   $values           Form values
  */
 private function createRememberMeSession(array $values)
 {
     if (REMEMBER_ME_AUTH && !empty($values['remember_me'])) {
         $credentials = $this->backend('rememberMe')->create($this->userSession->getId(), Request::getIpAddress(), Request::getUserAgent());
         $this->backend('rememberMe')->writeCookie($credentials['token'], $credentials['sequence'], $credentials['expiration']);
     }
 }