Ejemplo n.º 1
0
 /**
  * Log a user in
  * 
  * Look up in database for a matching row with a username and a
  * password
  *
  * @param string $a_user_name
  *        Username of the user
  * @param string $a_password
  *        Password of the user
  * @return boolean
  */
 public function login($a_user_name, $a_password)
 {
     if (!$this->is_logged_in()) {
         if (Apine\User\Factory\UserFactory::is_name_exist($a_user_name) || Apine\User\Factory\UserFactory::is_email_exist($a_user_name)) {
             $encode_pass = Apine\Core\Encryption::hash_password($a_password);
         } else {
             return false;
         }
         $user_id = Apine\User\Factory\UserFactory::authentication($a_user_name, $encode_pass);
         $request_server = Apine\Core\Request::server();
         if ($user_id) {
             $referer = isset($request_server['REMOTE_ADDR']) ? $request_server['REMOTE_ADDR'] : '';
             $agent = isset($request_server['HTTP_USER_AGENT']) ? $request_server['HTTP_USER_AGENT'] : '';
             $creation_time = time();
             $new_user_token = new Apine\User\UserToken();
             $new_user_token->set_user($user_id);
             $new_user_token->set_token(Apine\Core\Encryption::hash_api_user_token($a_user_name, $a_password, $creation_time));
             $new_user_token->set_origin($referer . $agent);
             $new_user_token->set_creation_date($creation_time);
             $new_user_token->save();
             $this->token = $new_user_token;
             $this->set_session_type($this->token->get_user()->get_type());
             $this->logged_in = true;
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 /**
  * Log a user in
  * Look up in database for a matching row with a username and a
  * password
  *
  * @param string $user_name
  *        Username of the user
  * @param string $password
  *        Password of the user
  * @param string[] $options
  *        Login Options
  * @return boolean
  */
 public function login($user_name, $password, $options = array())
 {
     if (!$this->is_logged_in()) {
         if (UserFactory::is_name_exist($user_name) || UserFactory::is_email_exist($user_name)) {
             $encode_pass = Encryption::hash_password($password);
         } else {
             return false;
         }
         $user_id = UserFactory::authentication($user_name, $encode_pass);
         if ($user_id) {
             $this->user_id = $user_id;
             $this->logged_in = true;
             $new_user = $this->get_user();
             $this->set_session_type($new_user->get_type());
             $this->session->set_var('apine_user_id', $user_id);
             $this->session->set_var('apine_user_type', $new_user->get_type());
             if (isset($options["remember"]) && $options["remember"] === true) {
                 $this->session->set_var('apine_session_permanent', true);
             }
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }