コード例 #1
0
ファイル: AuthService.php プロジェクト: cubex/framework
 /**
  * Retrieve the user from the cookie
  *
  * @param bool $checkQueue
  *
  * @return IAuthedUser|null
  */
 public function getCookieUser($checkQueue = true)
 {
     $cookied = Cookie::get($this->getCookieName(), null, $checkQueue);
     if ($cookied !== null) {
         $authedUser = $this->getCubex()->make('\\Cubex\\Auth\\AuthedUser');
         if ($authedUser instanceof IAuthedUser) {
             try {
                 $authedUser->unserialize($cookied);
                 return $authedUser;
             } catch (\Exception $e) {
             }
         }
     }
     return null;
 }
コード例 #2
0
ファイル: CookieTest.php プロジェクト: cubex/framework
 public function testForget()
 {
     $cookie = Cookie::forget('testforget');
     $this->assertTrue($cookie->getExpiresTime() < time());
     $this->assertEquals('testforget', $cookie->getName());
 }
コード例 #3
0
ファイル: AuthServiceTest.php プロジェクト: cubex/framework
 public function testGetAuthedUser()
 {
     $auth = $this->getAuthService();
     $provider = $auth->getAuthProvider();
     $usr = new AuthedUser('brooke', 56, ['surname' => 'Bryan']);
     if ($provider instanceof TestAuthProvider) {
         $provider->setRetrieve($usr);
         $this->assertSame($usr, $auth->getAuthedUser());
         $auth->logout();
     }
     $request = Cookie::getFacadeApplication()->make('request');
     if ($request instanceof Request) {
         $request->cookies->set('cubex_login', 'InvalidCookie');
         $this->assertFalse($auth->isLoggedIn());
         $auth->logout();
         $request->cookies->set('cubex_login', $usr->serialize());
         $this->assertEquals('brooke', $auth->getAuthedUser()->getUsername());
         $auth->logout();
         $request->cookies->remove('cubex_login');
     }
 }