/**
  * @group actions
  * @group users
  * @group auth
  */
 public function testLoginWithToken()
 {
     $action = new \Actions\Users\Auth();
     $token = $action->createToken(1, TRUE);
     $this->assertTrue(strlen($token) > 0);
     $user = $action->authorizeToken();
     $this->assertTrue($user != FALSE);
     $this->assertObjectHasAttribute('id', $user);
     $this->assertTrue(valid($user->id));
     $this->assertTrue($action->destroyToken(1));
 }
Example #2
0
 /**
  * Sets up the session data, builds the user info
  */
 public function init()
 {
     // save the userId from the session
     $this->userId = $this->getDI()->getShared('session')->get('user_id');
     // read in the session. if it's not set, try to re-authorize them
     // with a login token. authorizeToken will set the session info
     // if a valid token exists.
     if (!$this->isLoggedIn()) {
         $action = new \Actions\Users\Auth();
         if (!$action->authorizeToken()) {
             return FALSE;
         }
         // update the auth from the session
         $this->userId = $this->getDI()->getShared('session')->get('user_id');
     }
     // load user, roles, and settings. if the requested userId is the
     // same as the session, then just use the session user.
     $this->load($this->userId);
 }