yii2-user

How to login using two different model or switch identity class in yii2?

蹲街弑〆低调 提交于 2019-12-04 07:34:59
I want to allow user login from two different model. Config.php 'user' => [ 'identityClass' => 'app\models\User', //one more class here 'enableAutoLogin' => false, 'authTimeout' => 3600*2, ], LoginForm.php public function rules() { return [ // username and password are both required [['username', 'password'], 'required'], // rememberMe must be a boolean value ['rememberMe', 'boolean'], // password is validated by validatePassword() ['password', 'validatePassword'], ]; } public function validatePassword($attribute, $params) { if (!$this->hasErrors()) { $user = $this->getUser(); if (!$user || !

authTimeout in Yii2

隐身守侯 提交于 2019-12-01 05:42:40
I am trying to log out user automatically in yii2 after he is idle for a fixed seconds . In web.php I added 'user' => [ 'identityClass' => 'app\models\User', 'enableAutoLogin' => true, 'authTimeout'=>100 ], inside components . I am using basic template. But it is not logging out automatically. Does this work in Yii2? I was following documentation from http://www.yiiframework.com/doc-2.0/yii-web-user.html Andrei Putivet $authTimeout - public property. The number of seconds in which the user will be logged out automatically if he remains inactive. If this property is not set, the user will be

authTimeout in Yii2

放肆的年华 提交于 2019-12-01 02:22:01
问题 I am trying to log out user automatically in yii2 after he is idle for a fixed seconds . In web.php I added 'user' => [ 'identityClass' => 'app\models\User', 'enableAutoLogin' => true, 'authTimeout'=>100 ], inside components . I am using basic template. But it is not logging out automatically. Does this work in Yii2? I was following documentation from http://www.yiiframework.com/doc-2.0/yii-web-user.html 回答1: $authTimeout - public property. The number of seconds in which the user will be

yii2, google outh2 and scope

心不动则不痛 提交于 2019-11-30 20:20:39
I am using Yii2, GoogleOAuth and yii2-user extension. I want to receive user google circles and set scope to my config: 'authClientCollection' => [ 'class' => 'yii\authclient\Collection', 'clients' => [ 'google' => [ 'class' => 'yii\authclient\clients\GoogleOAuth', 'clientId' => '758709912345-p4qp4lqihit5un1u6qb75msqp5m5j6d8.apps.googleusercontent.com', 'clientSecret' => 'ZygOIi1-0asfktUQ1pKOFOo', 'scope' => 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/drive', ], ], ] When I login with Google OAuth2 I had error:

Yii2 - How to get the current username or name from Yii::$app->user?

雨燕双飞 提交于 2019-11-30 09:05:54
问题 How do you add, or get, variables using Yii::$app->user->something ? I don't want to get them through identity . I want to make specific ones accessible through user . For example, I want to get the current logged in user's username and name: \Yii::$app->user->username or \Yii::$app->user->name 回答1: While other topics here on SO offer a chincy hack solution, or to simply fetch it through Yii::$app->user->identity , I am going to show you how to do it properly. You can bend Yii2 to your will,