コード例 #1
0
 /**
  * Get the user identity and returns a user corresponding
  * to the given identity.
  * 
  * Note that the returned user contains his
  * credentials in order to be used by the security
  * framework
  * 
  */
 public function &loadUser(__IUserIdentity $user_identity)
 {
     $user = null;
     if ($user_identity instanceof __UsernameIdentity) {
         //connect to the database:
         $dbh = new PDO('mysql:host=localhost;dbname=my_db_name', $db_user, $db_password);
         //find the user by filtering by login:
         $statement = $dbh->prepare("SELECT * \n                                        FROM users \n                                        WHERE login = ?");
         $login = $user_identity->getUsername();
         $statement->execute(array($login));
         //if the query has result in a single row:
         if ($statement->rowCount() == 1) {
             $statement->setFetchMode(PDO::FETCH_ASSOC);
             $user_info = $arrValues = $stmt->fetch();
             //create a user instance and set the credentials:
             $user = new __User();
             $credentials = new __PasswordCredentials();
             $credentials->setPassword($user_info['password']);
             $user->setCredentials($credentials);
             //now load roles asssociated to him:
             $roles = $this->_loadRoles($dbh, $user_info['id']);
             //and finally assign them to the user:
             $user->setRoles($roles);
         }
         //close the connection
         $dbh = null;
     }
     return $user;
 }
コード例 #2
0
 public function defaultAction()
 {
     $model_and_view = new __ModelAndView('logon');
     $request = __Client::getInstance()->getRequest();
     //Check credentials:
     $login = $request->getParameter('login');
     $password = $request->getParameter('password');
     $user_identity = new __UsernameIdentity();
     $user_identity->setUsername($login);
     $credentials = new __PasswordCredentials();
     $credentials->setPassword($password);
     try {
         $result_logon = __AuthenticationManager::getInstance()->logon($user_identity, $credentials);
     } catch (__SecurityException $e) {
         $result_logon = false;
         $error_message = $e->getMessage();
     }
     if ($result_logon == false) {
         //Now will include smarty as ORS template engine:
         if ($error_message == '') {
             $error_message = __ResourceManager::getInstance()->getResource('ERR_LOGON_ERROR')->getValue();
         }
         $model_and_view->errorMsg = $error_message;
     } else {
         if ($request->getParameter('destination_page')) {
             $model_and_view->redirectPage = $request->GetParameter('destination_page');
         } else {
             $model_and_view->redirectPage = __UriFactory::getInstance()->createUri()->setActionCode('index')->addParameter(__ApplicationContext::getInstance()->getPropertyContent('REQUEST_LION_ADMIN_AREA'), 1)->getUrl();
         }
     }
     //Return the view code to use:
     return $model_and_view;
 }
コード例 #3
0
 public function logon($login, $password)
 {
     //set both the user identity and the
     //credentials with given login and password:
     $user_identity = new __UsernameIdentity();
     $user_identity->setUsername($login);
     $credentials = new __PasswordCredentials();
     $credentials->setPassword($password);
     //call the authentication manager in order to
     //authenticate the user:
     $return_value = __AuthenticationManager::getInstance()->logon($user_identity, $credentials);
     return $return_value;
 }
コード例 #4
0
 /**
  * Get the user identity and returns a user corresponding
  * to the given identity.
  * 
  * Note that the returned user contains his
  * credentials in order to be used by the security
  * framework
  * 
  */
 public function &loadUser(__IUserIdentity $user_identity)
 {
     $user = null;
     if ($user_identity instanceof __UsernameIdentity) {
         //get the login string from the user identity:
         $login = $user_identity->getUsername();
         //check if the login correspond to any of our
         //valid logins:
         if (key_exists($login, $this->_user_and_passwords)) {
             //create a user instance and set the credentials:
             $user = new __User();
             $credentials = new __PasswordCredentials();
             $credentials->setPassword($this->_user_and_passwords[$login]);
             $user->setCredentials($credentials);
         }
     }
     return $user;
 }
コード例 #5
0
 public function &loadUser(__IUserIdentity $user_identity)
 {
     $return_value = null;
     if ($user_identity instanceof __AnonymousIdentity) {
         return $this->loadAnonymousUser();
     } else {
         if ($user_identity instanceof __UsernameIdentity) {
             $login = $user_identity->getUsername();
             if ($login == __ApplicationContext::getInstance()->getPropertyContent('LION_ADMIN_LOGIN')) {
                 $return_value = new __User();
                 $credentials = new __PasswordCredentials();
                 $credentials->setPassword(__ApplicationContext::getInstance()->getPropertyContent('LION_ADMIN_PASSWORD'));
                 $return_value->setCredentials($credentials);
                 $return_value->addRole(__RoleManager::getInstance()->getRole('admin'));
             }
         }
     }
     return $return_value;
 }
コード例 #6
0
 /**
  * Get the user identity and returns a user corresponding
  * to the given identity.
  * 
  * Note that the returned user contains his
  * credentials in order to be used by the security
  * framework
  * 
  */
 public function &loadUser(__IUserIdentity $user_identity)
 {
     $user = null;
     if ($user_identity instanceof __UsernameIdentity) {
         //get the login string from the user identity:
         $login = $user_identity->getUsername();
         //check if the login correspond to any of our
         //valid logins:
         if (key_exists($login, $this->_user_and_passwords)) {
             //create a user instance and set the credentials:
             $user = new __User();
             $credentials = new __PasswordCredentials();
             $credentials->setPassword($this->_user_and_passwords[$login]);
             $user->setCredentials($credentials);
             //get the role identified as REGISTERED_USER:
             $role = __RoleManager::getInstance()->getRole('REGISTERED_USER');
             //assign the role to the user:
             $user->addRole($role);
         }
     }
     return $user;
 }
コード例 #7
0
ファイル: User.class.php プロジェクト: laiello/lion-framework
 public function setPassword($password)
 {
     $credentials = new __PasswordCredentials();
     $credentials->setPassword($password);
     $this->setCredentials($credentials);
 }