本文整理汇总了PHP中yii\web\User::className方法的典型用法代码示例。如果您正苦于以下问题:PHP User::className方法的具体用法?PHP User::className怎么用?PHP User::className使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\web\User
的用法示例。
在下文中一共展示了User::className方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUser
/**
* Get user
* @return User
*/
public function getUser()
{
if (!$this->_user instanceof User) {
$this->_user = Instance::ensure($this->_user, User::className());
}
return $this->_user;
}
示例2: interception
public function interception($event)
{
if (!isset(Yii::$app->i18n->translations['db_rbac'])) {
Yii::$app->i18n->translations['db_rbac'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'sourceLanguage' => 'ru-Ru', 'basePath' => '@developeruz/db_rbac/messages'];
}
$route = Yii::$app->getRequest()->resolve();
//Проверяем права по конфигу
$this->createRule();
$user = Instance::ensure(Yii::$app->user, User::className());
$request = Yii::$app->getRequest();
$action = $event->action;
if (!$this->cheсkByRule($action, $user, $request)) {
//И по AuthManager
if (!$this->checkPermission($route)) {
//Если задан $login_url и пользователь не авторизован
if (Yii::$app->user->isGuest && $this->login_url) {
Yii::$app->response->redirect($this->login_url)->send();
exit;
}
//Если задан $redirect_url
if ($this->redirect_url) {
Yii::$app->response->redirect($this->redirect_url)->send();
exit;
} else {
throw new ForbiddenHttpException(Yii::t('db_rbac', 'Недостаточно прав'));
}
}
}
}
示例3: init
/**
* 初始化方法
*/
public function init()
{
parent::init();
//获取user实例
$this->user = Instance::ensure($this->user, User::className());
$this->user_info = $this->user->identity;
}
示例4: init
/**
* Initializes the [[rules]] array by instantiating rule objects from configurations.
*/
public function init()
{
parent::init();
$this->user = Instance::ensure($this->user, User::className());
if ($this->user->identity !== null) {
$this->user->identity->getRules();
}
}
示例5: beforeLogin
/**
* when user login in backend , it should be 'Administrator' or ,'Merchant'
*/
public static function beforeLogin()
{
Event::on(\yii\web\User::className(), \yii\web\User::EVENT_BEFORE_LOGIN, function ($event) {
$user = $event->identity;
$auth = new DbManager();
$auth->init();
$role = $auth->getRolesByUser($user->id);
$event->isValid = in_array(current($role)->name, ['Administrator', 'Merchant']);
});
}
示例6: bootstrap
/**
* @param \yii\base\Application $app
*/
public function bootstrap($app)
{
Event::on(User::className(), User::EVENT_AFTER_LOGIN, function () {
$storage = Instance::ensure(\Yii::$app->cart->storage, MultipleStorage::className());
if (get_class($storage) == 'hscstudio\\cart\\MultipleStorage') {
$cart = Instance::ensure(\Yii::$app->cart, Cart::className());
$storage->sync($cart);
}
});
}
示例7: init
/**
* Initialize
* @throws \yii\base\InvalidConfigException
*/
public function init()
{
parent::init();
$this->db = Instance::ensure($this->db, Connection::className());
$this->authManager = Instance::ensure($this->authManager, BaseManager::className());
$this->user = Instance::ensure($this->user, User::className());
if (empty($this->cache)) {
$this->cache = $this->createCacheComponent();
} else {
$this->cache = Instance::ensure($this->cache, Cache::className());
}
}
示例8: init
/**
* Initializes the [[rules]] array by instantiating rule objects from configurations.
*/
public function init()
{
if ($this->user === null) {
$this->user = Adm::getInstance()->user;
}
$this->user = Instance::ensure($this->user, User::className());
foreach ($this->rules as $i => $rule) {
if (is_array($rule)) {
$this->rules[$i] = Yii::createObject(array_merge($this->ruleConfig, $rule));
}
}
}
示例9: userLoginAfter
/**
* 注册登录事件
* @throws \Exception
* @return boolean
*/
public static function userLoginAfter()
{
Event::on(User::className(), User::EVENT_AFTER_LOGIN, function ($event) {
// user identity
if (isset($event->identity) && $event->identity instanceof \common\models\User) {
$user = $event->identity;
$attrs = [];
foreach ($attrs as $_attr) {
\Yii::$app->session->set($_attr, isset($user->{$_attr}) ? $user->{$_attr} : false);
}
}
return true;
});
}
示例10: init
public function init()
{
$this->user = Instance::ensure($this->user, User::className());
$rolesObject = Yii::$app->authManager->getRolesByUser($this->user->id);
if (!empty($rolesObject)) {
foreach ($rolesObject as $roles => $object) {
foreach ($object->data as $route) {
$this->_actions[] = $route;
}
}
}
$this->rules = [['actions' => $this->_actions, 'allow' => true]];
parent::init();
}
示例11: interception
public function interception($event)
{
$route = Yii::$app->getRequest()->resolve();
//Проверяем права по конфигу
$this->createRule();
$user = Instance::ensure(Yii::$app->user, User::className());
$request = Yii::$app->getRequest();
$action = $event->sender->requestedAction;
if (!$this->cheсkByRule($action, $user, $request)) {
//И по AuthManager
if (!$this->checkPermission($route)) {
throw new BadRequestHttpException('Не достаточно прав');
}
}
}
示例12: init
public function init()
{
/** @var $module Module */
if (empty($this->user) && ($module = Yii::$app->getModule('admin')) != null) {
$this->user = $module->adminComponent;
}
ActionFilter::init();
if (empty($this->rules)) {
$this->rules = [['actions' => [], 'allow' => true, 'roles' => ['@']]];
}
$this->user = Instance::ensure($this->user, User::className());
foreach ($this->rules as $i => $rule) {
if (is_array($rule)) {
$this->rules[$i] = Yii::createObject(array_merge($this->ruleConfig, $rule));
}
}
}
示例13: interception
public function interception($event)
{
if (!isset(Yii::$app->i18n->translations['db_rbac'])) {
Yii::$app->i18n->translations['db_rbac'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'sourceLanguage' => 'ru-Ru', 'basePath' => '@developeruz/db_rbac/messages'];
}
$route = Yii::$app->getRequest()->resolve();
//Проверяем права по конфигу
$this->createRule();
$user = Instance::ensure(Yii::$app->user, User::className());
$request = Yii::$app->getRequest();
$action = $event->action;
if (!$this->cheсkByRule($action, $user, $request)) {
//И по AuthManager
if (!$this->checkPermission($route)) {
throw new ForbiddenHttpException(Yii::t('db_rbac', 'Недостаточно прав'));
}
}
}
示例14: actionJson
/**
* Run a generation of swagger json-document
* @throws \yii\base\InvalidConfigException
*/
public function actionJson()
{
// workaround for identity absence in console application
Yii::$container->set('user', ['class' => User::className(), 'identityClass' => 'common\\models\\User']);
// Document generation
$doc = new Document();
Yii::$app->set('doc', $doc);
$controllers = $this->getControllers();
/** @var \yii\base\Controller $controller */
foreach ($controllers as $key => $controller) {
$tag = new Tag();
$tag->name = $key;
$doc->addTag($tag);
$actions = $this->getActions($controller);
foreach ($actions as $actionName => $action) {
$doc->handleAction($action);
}
}
$doc->generateFile(Yii::getAlias($this->module->jsonPath));
$this->stdout('Done' . PHP_EOL);
}
示例15: bootstrap
/** @inheritdoc */
public function bootstrap($app)
{
/** @var $module Module */
if ($app->hasModule('users') && ($module = $app->getModule('users')) instanceof Module) {
$this->_modelMap = array_merge($this->_modelMap, $module->modelMap);
foreach ($this->_modelMap as $name => $definition) {
$class = "mii\\modules\\users\\models\\" . $name;
\Yii::$container->set($class, $definition);
$modelName = is_array($definition) ? $definition['class'] : $definition;
$module->modelMap[$name] = $modelName;
if (in_array($name, ['User', 'Profile', 'Token', 'Account'])) {
\Yii::$container->set($name . 'Query', function () use($modelName) {
return $modelName::find();
});
}
}
\Yii::$container->setSingleton(Finder::className(), ['userQuery' => \Yii::$container->get('UserQuery'), 'profileQuery' => \Yii::$container->get('ProfileQuery'), 'tokenQuery' => \Yii::$container->get('TokenQuery'), 'accountQuery' => \Yii::$container->get('AccountQuery')]);
if ($app instanceof ConsoleApplication) {
$module->controllerNamespace = 'mii\\modules\\users\\commands';
$app->get('i18n')->translations['users*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages'];
} else {
try {
$app->user->enableAutoLogin = true;
$app->user->loginUrl = ['/users/security/login'];
$app->user->identityClass = $module->modelMap['User'];
} catch (InvalidConfigException $e) {
$app->set('user', ['class' => User::className(), 'enableAutoLogin' => true, 'loginUrl' => ['/users/security/login'], 'identityClass' => $module->modelMap['User']]);
}
$configUrlRule = ['prefix' => $module->urlPrefix, 'rules' => $module->urlRules];
if ($module->urlPrefix != 'users') {
$configUrlRule['routePrefix'] = 'users';
}
$app->get('urlManager')->rules[] = new GroupUrlRule($configUrlRule);
$app->get('urlManager')->addRules(['PUT,PATCH /' . $this->id . '/apis/<id>' => $this->id . '/api/update', 'DELETE /' . $this->id . '/apis/<id>' => $this->id . '/api/delete', 'GET,HEAD /' . $this->id . '/apis/<id>' => $this->id . '/api/view', 'POST /' . $this->id . '/apis' => $this->id . '/api/create', 'GET,HEAD /' . $this->id . '/apis' => $this->id . '/api/index', 'OPTIONS /' . $this->id . '/apis/<id>' => $this->id . '/api/options', 'OPTIONS /' . $this->id . '/apis' => $this->id . '/api/options'], false);
if (!$app->has('authClientCollection')) {
$app->set('authClientCollection', ['class' => Collection::className()]);
}
}
$app->get('i18n')->translations['users*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages'];
$defaults = ['welcomeSubject' => \Yii::t('users', 'Welcome to {0}', \Yii::$app->name), 'confirmationSubject' => \Yii::t('users', 'Confirm account on {0}', \Yii::$app->name), 'reconfirmationSubject' => \Yii::t('users', 'Confirm email change on {0}', \Yii::$app->name), 'recoverySubject' => \Yii::t('users', 'Complete password reset on {0}', \Yii::$app->name)];
\Yii::$container->set('mii\\modules\\users\\Mailer', array_merge($defaults, $module->mailer));
}
}