/**
  * 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;
 }
Example #2
0
 /**
  * This method expects a __UsernameIdentity to retrieve
  * the username and call to the model to get the user.
  *
  */
 public function &loadUser(__IUserIdentity $user_identity)
 {
     $return_value = null;
     if ($user_identity instanceof __UsernameIdentity) {
         $username = $user_identity->getUsername();
         $return_value = $this->loadUserByUsername($username);
     }
     return $return_value;
 }
 /**
  * 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;
 }
 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;
 }
 /**
  * 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;
 }