Exemplo n.º 1
0
 /**
  * Authenticate a user with a combination of a user name and a
  * token string.
  *
  * @param string $a_name
  *        Username
  * @param string $a_token
  *        Token string
  * @param int $a_delay
  * @return boolean
  */
 public static function authentication($a_name, $a_token, $a_delay)
 {
     $user = UserFactory::create_by_name($a_name);
     if (!is_null($user)) {
         $database = new Database();
         $token_statement_id = $database->prepare('SELECT `id` FROM `apine_api_users_tokens` WHERE `user_id` = ? AND `token` = ? AND `last_access_date` > ? AND `disabled` = false');
         $ar_token = $database->execute(array($user->get_id(), $a_token, date('d M Y H:i:s', time() - $a_delay)), $token_statement_id);
         if ($ar_token) {
             $connect = end($ar_token);
             $return = (int) $connect['id'];
         } else {
             $return = false;
         }
     } else {
         $return = false;
     }
     return $return;
 }
Exemplo n.º 2
0
 /**
  *
  * @see ApineEntityInterface::load()
  */
 public function load()
 {
     if (!is_null($this->id)) {
         $this->user = Factory\UserFactory::create_by_id($this->_get_field('user_id'));
         $this->token = $this->_get_field('token');
         $this->origin = $this->_get_field('origin');
         $this->creation_date = $this->_get_field('creation_date');
         $this->last_access_date = $this->_get_field('last_access_date');
         $this->disabled = (bool) $this->_get_field('disabled');
         $this->loaded = 1;
     }
 }
Exemplo n.º 3
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;
     }
 }
Exemplo n.º 4
0
 /**
  *
  * @see ApineEntityInterface::load()
  */
 public function load()
 {
     if (!is_null($this->id)) {
         $this->user = Factory\UserFactory::create_by_id($this->_get_field('user_id'));
         $this->token = $this->_get_field('token');
         $this->creation_date = $this->_get_field('creation_date');
         $this->loaded = 1;
     }
 }
Exemplo n.º 5
0
 /**
  * @see Entity\EntityInterface::load()
  */
 public function load()
 {
     if (!is_null($this->id)) {
         $this->user = Factory\UserFactory::create_by_id($this->_get_field('user_id'));
         $this->name = $this->_get_field('name');
         if (@unserialize($this->_get_field('value')) !== false) {
             $this->value = @unserialize($this->_get_field('value'));
         } else {
             $this->value = $this->_get_field('value');
         }
     }
 }
Exemplo n.º 6
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;
     }
 }