/**
  * Execute this validator.
  *
  * @param mixed A file or parameter value/array.
  * @param error An error message reference.
  *
  * @return bool true, if this validator executes successfully, otherwise
  *              false.
  */
 public function execute(&$value, &$error)
 {
     $actionName = $this->getContext()->getActionStack()->getFirstEntry()->getActionName();
     if (isset($actionName) and 'add' == $actionName) {
         $addError = $this->getContext()->getRequest()->getError('nickname');
         if (isset($addError)) {
             $error = $addError;
             return false;
         }
         //see if there are other errors
         if (count($this->getContext()->getRequest()->getErrorNames())) {
             $error = null;
             return false;
         }
     }
     $password_param = $this->getParameterHolder()->get('password');
     $password = $this->getContext()->getRequest()->getParameter($password_param);
     $login = $value;
     // anonymous is not a real user
     if ($login == 'anonymous') {
         $error = $this->getParameterHolder()->get('login_error');
         return false;
     }
     if ($user = UserPeer::getAuthenticatedUser($login, $password)) {
         $this->getContext()->getUser()->signIn($user);
         return true;
     }
     $error = $this->getParameterHolder()->get('login_error');
     return false;
 }
Ejemplo n.º 2
0
 private function authenticateUser()
 {
     if (isset($_SERVER['PHP_AUTH_USER'])) {
         if ($user = UserPeer::getAuthenticatedUser($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
             $this->getContext()->getUser()->signIn($user);
             return $user;
         }
     }
     header('WWW-Authenticate: Basic realm="askeet API"');
     header('HTTP/1.0 401 Unauthorized');
 }
Ejemplo n.º 3
0
 /**
  * Execute this validator.
  *
  * @param mixed A file or parameter value/array.
  * @param error An error message reference.
  *
  * @return bool true, if this validator executes successfully, otherwise
  *              false.
  */
 public function execute(&$value, &$error)
 {
     $password_param = $this->getParameterHolder()->get('password');
     $password = $this->getContext()->getRequest()->getParameter($password_param);
     $login = $value;
     // anonymous is not a real user
     if ($login == 'anonymous') {
         $error = $this->getParameterHolder()->get('login_error');
         return false;
     }
     if ($user = UserPeer::getAuthenticatedUser($login, $password)) {
         $this->getContext()->getUser()->signIn($user);
         return true;
     }
     $error = $this->getParameterHolder()->get('login_error');
     return false;
 }
Ejemplo n.º 4
0
 /**
  * Validates a user user login
  *
  * @param string $strUsername
  * @param string $strPassword
  * @param bool $bolSetLocal Optional. Stores the validated domain and user.
  *     Default is TRUE.
  * @param bool $bolSetSession Optional. Sets the user session. Default is FALSE.
  * @param bool $bolSetCookie Optional. Default is FALSE.
  * @return User
  */
 public function validateUser($strUsername, $strPassword = false, $bolSetLocal = true, $bolSetSession = false, $bolSetCookie = false, PropelPDO $con = null)
 {
     $defaultAccountName = \Xily\Config::get('app.account', 'string', '');
     if ($defaultAccountName !== '' and strpos($strUsername, '/') === false) {
         $strUsername = $defaultAccountName . '/' . $strUsername;
     }
     $user = UserPeer::getAuthenticatedUser($strUsername, $strPassword, $con);
     if ($user === null or $user->getDeleted()) {
         return null;
     }
     if ($bolSetLocal) {
         $this->user = $user;
     }
     if ($bolSetSession) {
         $this->setUserSession($user->getId());
     }
     if ($bolSetCookie) {
         setcookie('autologin', $this->createCookieToken($user->getFQN($con), $this->cookieDuration), time() + 86400 * $this->cookieDuration);
     }
     return $user;
 }