/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findByUsername($this->username); } return $this->_user; }
public function beforeAction($action) { //预先传递模块ID、控制器ID和动作ID给Smarty $moduleName = $this->module->id; $controllerName = $this->id; $actionName = $action->id; static::smartyAssign("moduleName", strtolower($moduleName)); static::smartyAssign("controllerName", strtolower($controllerName)); static::smartyAssign("actionName", strtolower($actionName)); //csrfToken $csrfToken = array('name' => Yii::$app->request->csrfParam, 'value' => Yii::$app->request->csrfToken); static::smartyAssign('csrfToken', $csrfToken); //User信息 if (!Yii::$app->user->isGuest) { $user = User::findIdentity(Yii::$app->user->id); static::smartyAssign('user', $user); } return parent::beforeAction($action); }
/** * Checks the user credentials * * @param array $credentials * @return App\Common\Models\User */ public function check($credentials) { // Check if the user exist $user = User::findFirst(["conditions" => "username = ?1", "bind" => [1 => $credentials['username']]]); if ($user === false) { //$this->registerUserThrottling(0); $message = 'the user does not exist'; $this->flashSession->message('username', $message); throw new \Exception($message); } // Check the password if (!$this->security->checkHash($credentials['password'], $user->password)) { //$this->registerUserThrottling($user->id); $message = 'wrong email/password combination'; $this->flashSession->message('password', $message); throw new \Exception($message); } return $user; }
public function beforeAction($action) { //预先传递模块ID、控制器ID和动作ID给Smarty $moduleName = $this->module->id; $controllerName = $this->id; $actionName = $this->action->id; $this->smartyAssign("moduleName", strtolower($moduleName)); $this->smartyAssign("controllerName", strtolower($controllerName)); $this->smartyAssign("actionName", strtolower($actionName)); //csrfToken $csrfToken = array('name' => Yii::$app->request->csrfParam, 'value' => Yii::$app->request->csrfToken); $this->smartyAssign('csrfToken', $csrfToken); //User信息 if (!Yii::$app->user->isGuest) { $admin = User::findIdentity(Yii::$app->user->id); $this->smartyAssign('admin', $admin); } //激活的文章数量 $activeArticleCount = Article::getArticleCount(Article::STATUS_DELETED, '>'); $this->smartyAssign('activeArticleCount', $activeArticleCount); return parent::beforeAction($action); }
public function getUser() { return $this->hasOne(User::className(), ['id' => 'uid']); }