コード例 #1
0
 public function processAction()
 {
     require_once 'Conjoon/Auth/Adapter/Db.php';
     /**
      * @todo Filter username and password!
      */
     $username = $this->_getParam('username');
     $password = $this->_getParam('password');
     $rememberMe = (bool) $this->_getParam('rememberMe');
     $lastUserRequest = (int) $this->_getParam('lastUserRequest');
     // Special case - the app was started and the user wants to re-login
     // since his session was lost. Check if the user object as returned by the
     // data storage has a property lastLogin which may not be greater than
     // the "lastUserRequest"-parameter - if that is teh case, most likely another
     // user has logged in so the user has to completely restart the application -
     // a redirect to the base url will happen
     if ($lastUserRequest) {
         /**
          * @see Conjoon_Modules_Default_User_Model_User
          */
         require_once 'Conjoon/Modules/Default/User/Model/User.php';
         $userTable = new Conjoon_Modules_Default_User_Model_User();
         /**
          * @see Conjoon_BeanContext_Decorator
          */
         require_once 'Conjoon/BeanContext/Decorator.php';
         $decorator = new Conjoon_BeanContext_Decorator($userTable);
         $userDto = $decorator->getUserForUserNameCredentialsAsDto($username, md5($password));
         if ($userDto && $lastUserRequest <= $userDto->lastLogin) {
             // special case - send an auth token failure with the response
             $this->_response->setHttpResponseCode(401);
             /**
              * @see Conjoon_Error
              */
             require_once 'Conjoon/Error.php';
             $error = new Conjoon_Error();
             $error->setCode(-1);
             $error->setLevel(Conjoon_Error::LEVEL_ERROR);
             $error->setFile(__FILE__);
             $error->setLine(__LINE__);
             $error->setMessage("Someone has signed in with your user credentials. Please sign in again.");
             $error->setType(Conjoon_Error::TOKEN_FAILURE);
             $this->view->tokenFailure = true;
             /**
              * @todo create filter
              */
             unset($userDto->authToken);
             $this->view->user = $userDto;
             $this->view->success = false;
             $this->view->error = $error->getDto();
             return;
         }
     }
     $auth = Zend_Registry::get(Conjoon_Keys::REGISTRY_AUTH_OBJECT);
     $authAdapter = new Conjoon_Auth_Adapter_Db(array('username' => $username, 'password' => $password, 'remember_me' => $rememberMe));
     // if the result is valid, the return value of the adapter will
     // be stored automatically in the supplied storage object
     // from the auth object
     $result = $auth->authenticate($authAdapter);
     if ($result->isValid()) {
         $user = $result->getIdentity();
         if ($rememberMe && $user->getRememberMeToken() != null) {
             $this->setAutoLoginCookies(md5($user->getUserName()), $user->getRememberMeToken(), time() + 2592000);
         }
         $this->view->success = true;
     } else {
         $this->view->error = 'Wrong username or password';
         $this->view->success = false;
     }
 }