示例#1
0
 /**
  * Authorize a user's login token
  *
  * @return object | bool
  */
 public function authorizeToken()
 {
     $cookies = $this->getService('cookies');
     // read the cookie, check if the token belongs to a user
     if (!$cookies->has('token')) {
         return FALSE;
     }
     $token = $cookies->get('token');
     if (!valid($token->getValue(), STRING)) {
         return FALSE;
     }
     // try to get the user by token
     $user = \Db\Sql\Users::getByToken($token);
     if (!$user || !valid($user->id)) {
         return FALSE;
     }
     // save the session data
     $session = $this->getService('session');
     $session->set('user_id', $user->id);
     return $user;
 }