示例#1
0
 /**
  * Test Auth Identity clear
  *
  * @covers \Bluz\Auth\Auth::clearIdentity
  */
 public function testAuthClearIdentity()
 {
     $adminIdentity = new UserAdmin();
     Auth::setIdentity($adminIdentity);
     Auth::clearIdentity();
     $this->assertNull(Auth::getIdentity());
 }
示例#2
0
 protected function setUp()
 {
     parent::setUp();
     Db::insert('users')->setArray(['id' => 1, 'login' => 'Donatello', 'email' => '*****@*****.**', 'status' => 'pending'])->execute();
     Db::insert('users')->setArray(['id' => 2, 'login' => 'Bill', 'email' => '*****@*****.**', 'status' => 'active'])->execute();
     Auth::setIdentity(new \Application\Users\Row());
 }
示例#3
0
 /**
  * {@inheritdoc}
  *
  * @param string $module
  * @param string $controller
  * @param array $params
  * @return void
  */
 protected function preDispatch($module, $controller, $params = array())
 {
     // auth as CLI user
     $cliUser = Table::findRowWhere(['login' => 'system']);
     Auth::setIdentity($cliUser);
     parent::preDispatch($module, $controller, $params);
 }
示例#4
0
 protected function setUp()
 {
     parent::setUp();
     $this->hybridAuthMock = $this->getMockBuilder('\\Hybrid_Auth')->setMethods(['authenticate'])->disableOriginalConstructor()->getMock();
     $this->authAdapterMock = $this->getMockBuilder('\\Hybrid_Provider_Adapter')->setMethods(['getUserProfile'])->disableOriginalConstructor()->getMock();
     Db::insert('users')->setArray(['id' => 2, 'login' => 'Bill', 'email' => '*****@*****.**', 'status' => 'active'])->execute();
     Db::insert('auth')->setArray(['provider' => 'facebook', 'userId' => 2, 'foreignKey' => 112233])->execute();
     Auth::setIdentity(new \Application\Users\Row());
 }
示例#5
0
 /**
  * setUp
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->getApp()->useLayout(false);
     Auth::setIdentity(new UserHasPermission(UserFixtureContainer::$fixture));
 }
示例#6
0
 /**
  * Setup user with all privileges
  *
  * @return void
  */
 protected function setupSuperUserIdentity()
 {
     Auth::setIdentity(new UserHasPermission());
 }
示例#7
0
 /**
  * Can entity login
  *
  * @return void
  */
 public function login()
 {
     Auth::setIdentity($this);
 }
示例#8
0
 /**
  * setUp
  *
  * @return void
  */
 protected function setUp()
 {
     parent::setUp();
     Auth::setIdentity(new Row());
 }
示例#9
0
文件: Row.php 项目: bluzphp/skeleton
 /**
  * Can entity login
  *
  * @throws Exception
  * @throws AuthException
  * @return void
  */
 public function tryLogin()
 {
     switch ($this->status) {
         case Table::STATUS_PENDING:
             throw new AuthException("Your account is pending activation", 403);
         case Table::STATUS_DISABLED:
             throw new AuthException("Your account is disabled by administrator", 403);
         case Table::STATUS_ACTIVE:
             // all ok
             // regenerate session
             if (PHP_SAPI !== 'cli') {
                 Session::regenerateId();
             }
             // save user to new session
             Auth::setIdentity($this);
             break;
         default:
             throw new Exception("User status is undefined in system");
     }
 }
示例#10
0
 /**
  * Try with permissions
  */
 public function testAllow()
 {
     Auth::setIdentity(new UserHasPermission());
     $this->getApp()->widget('test', 'acl-denied');
 }
示例#11
0
 /**
  * Test deny access
  */
 public function testDeny()
 {
     Proxy\Auth::setIdentity(new UserGuest());
     $this->assertFalse(Proxy\Acl::isAllowed('any', 'any'));
 }