Example of usage use Bluz\Proxy\Auth; $user = Auth::getIdentity();
또한 보기: Instance::setIdentity()
또한 보기: Instance::getIdentity()
또한 보기: Instance::clearIdentity()
저자: Anton Shevchuk
상속: use trait ProxyTrait
예제 #1
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);
 }
예제 #2
0
 /**
  * Test user with correct password
  */
 public function testSigninWithCorrectPassword()
 {
     $this->dispatch('users/signin', ['login' => 'admin', 'password' => 'admin'], 'POST');
     //        $this->assertModule('users');
     //        $this->assertController('signin');
     $this->assertNotNull(Auth::getIdentity());
 }
예제 #3
0
 /**
  * Test sign out user
  */
 public function testSignOut()
 {
     $this->assertNotNull(Auth::getIdentity());
     $this->dispatch('users/signout');
     $this->assertModule('users');
     $this->assertController('signout');
     $this->assertNull(Auth::getIdentity());
 }
예제 #4
0
 /**
  * Test Auth Identity clear
  *
  * @covers \Bluz\Auth\Auth::getIdentity
  * @covers \Bluz\Auth\Auth::clearIdentity
  */
 public function testAuthClearIdentityWithWrongUserAgent()
 {
     $adminIdentity = new UserAdmin();
     Session::set('auth:agent', 'agent:php');
     Session::set('auth:identity', $adminIdentity);
     $_SERVER['HTTP_USER_AGENT'] = 'agent:cli';
     $this->assertNull(Auth::getIdentity());
 }
예제 #5
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());
 }
예제 #6
0
파일: Acl.php 프로젝트: dezvell/mm.local
 /**
  * Check user access by pair module-privilege
  *
  * @param  string $module
  * @param  string $privilege
  *
  * @return bool
  */
 public function isAllowed($module, $privilege)
 {
     if ($privilege) {
         $user = Auth::getIdentity();
         if (!$user || !$user->hasPrivilege($module, $privilege)) {
             return false;
         }
     }
     return true;
 }
예제 #7
0
파일: Row.php 프로젝트: bluzphp/skeleton
 /**
  * {@inheritdoc}
  *
  * @return void
  */
 public function beforeInsert()
 {
     $this->created = gmdate('Y-m-d H:i:s');
     /* @var \Application\Users\Row $user */
     if ($user = Auth::getIdentity()) {
         $this->userId = $user->id;
     } else {
         $this->userId = Users\Table::SYSTEM_USER;
     }
 }
예제 #8
0
 /**
  * Reset layout and Request
  */
 protected static function resetApp()
 {
     if (self::$app) {
         self::$app->useLayout(true);
     }
     Proxy\Auth::clearIdentity();
     Proxy\Messages::popAll();
     Proxy\Request::setInstance(new Http\Request());
     Proxy\Response::setInstance(new Http\Response());
     Proxy\Response::setPresentation(null);
 }
예제 #9
0
 public function testUserStatusActive()
 {
     $provider = new AuthProvider('Facebook');
     $provider->setResponse($this->getApp());
     $authRow = new Row();
     $authRow->userId = 2;
     try {
         $provider->alreadyRegisteredLogic($authRow);
     } catch (RedirectException $e) {
     }
     $this->assertNotNull(Auth::getIdentity());
 }
예제 #10
0
파일: CrudTest.php 프로젝트: Kit-kat1/bluz
 /**
  * setUp
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->getApp()->useLayout(false);
     Auth::setIdentity(new UserHasPermission(UserFixtureContainer::$fixture));
 }
예제 #11
0
 /**
  * Reset layout and Request
  */
 protected static function resetApp()
 {
     if (self::$app) {
         self::$app->useLayout(true);
         self::$app->resetRouter();
     }
     Proxy\Auth::clearIdentity();
     Proxy\Messages::popAll();
     Proxy\Request::setInstance(RequestFactory::fromGlobals());
     Proxy\Response::setInstance(new Bluz\Response\Response());
 }
예제 #12
0
 /**
  * Setup user with all privileges
  *
  * @return void
  */
 protected function setupSuperUserIdentity()
 {
     Auth::setIdentity(new UserHasPermission());
 }
예제 #13
0
 /**
  * Can entity login
  *
  * @return void
  */
 public function login()
 {
     Auth::setIdentity($this);
 }
예제 #14
0
파일: Table.php 프로젝트: bluzphp/skeleton
 /**
  * Call Verify Function
  *
  * @param string $password
  * @param string $hash
  * @throws \Application\Exception
  * @return string
  */
 protected function callVerifyFunction($password, $hash)
 {
     /** @var \Bluz\Auth\Auth $auth */
     $auth = Auth::getInstance();
     $options = $auth->getOption(self::PROVIDER_EQUALS);
     if (!isset($options['verify']) or !is_callable($options['verify'])) {
         throw new Exception("Verify function for 'equals' adapter is not callable");
     }
     // verify password with hash
     return call_user_func($options['verify'], $password, $hash);
 }
예제 #15
0
파일: index.php 프로젝트: bluzphp/skeleton
 *
 * @route /api/{$resource}/{$id}
 * @param string $resource
 * @param string $id
 *
 * @route /api/{$resource}
 * @param string $resource
 *
 * @return mixed
 */
return function ($resource, $id, $relation, $relationId) {
    /**
     * @var Controller $this
     */
    $this->useJson();
    Auth::clearIdentity();
    try {
        // authentication by api token
        if ($token = Request::getParam('token')) {
            Table::getInstance()->authenticateToken($token);
        }
        $params = [];
        foreach ([$id, $relation, $relationId] as $param) {
            if (!is_null($param)) {
                $params[] = $param;
            }
        }
        return $this->dispatch('api', 'resources/' . $resource, $params);
    } catch (\Exception $e) {
        // process exceptions here
        Response::setStatusCode($e->getCode());
예제 #16
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");
     }
 }
예제 #17
0
 /**
  * Try with permissions
  */
 public function testAllow()
 {
     Auth::setIdentity(new UserHasPermission());
     $this->getApp()->widget('test', 'acl-denied');
 }
예제 #18
0
<?php

/**
 * @copyright Bluz PHP Team
 * @link https://github.com/bluzphp/skeleton
 */
/**
 * @namespace
 */
namespace Application\Layout\Helper;

use Bluz\Proxy\Auth;
return function () {
    /**
     * @var \Application\Users\Row $user
     */
    if ($user = Auth::getIdentity()) {
        return $user->login;
    } else {
        return __('Guest');
    }
};
예제 #19
0
 /**
  * Denied access
  * @param ForbiddenException $exception
  * @return \Bluz\Controller\Controller|null
  */
 public function forbidden(ForbiddenException $exception)
 {
     if (AuthProxy::getIdentity()) {
         $message = Translator::translate("You don't have permissions to access this page");
     } else {
         $message = Translator::translate("You don't have permissions, please sign in");
     }
     // for AJAX and API calls (over JSON)
     $jsonOrApi = Request::isXmlHttpRequest() || Request::getAccept([Request::TYPE_HTML, Request::TYPE_JSON]) == Request::TYPE_JSON;
     // for guest, for requests
     if (!AuthProxy::getIdentity() && !$jsonOrApi) {
         // save URL to session and redirect make sense if presentation is null
         Session::set('rollback', Request::getUri()->__toString());
         // add error notice
         Messages::addError($message);
         // redirect to Sign In page
         $url = Router::getUrl('users', 'signin');
         return $this->redirect($url);
     } else {
         return $this->error(new ForbiddenException($message, 403, $exception));
     }
 }
예제 #20
0
파일: User.php 프로젝트: dezvell/mm.local
<?php

/**
 * Bluz Framework Component
 *
 * @copyright Bluz PHP Team
 * @link https://github.com/bluzphp/framework
 */
/**
 * @namespace
 */
namespace Bluz\View\Helper;

use Bluz\View\View;
use Bluz\Proxy\Auth;
return function () {
    return Auth::getIdentity();
};
예제 #21
0
 /**
  * Test deny access
  */
 public function testDeny()
 {
     Proxy\Auth::setIdentity(new UserGuest());
     $this->assertFalse(Proxy\Acl::isAllowed('any', 'any'));
 }