/** * Finds user by [[email]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findByLogin($this->email); } return $this->_user; }
public function login() { $user = User::findByLogin($this->login); if ($this->validate() && $user) { return Yii::$app->user->login($user, 3600 * 24 * 30); } else { return false; } }
public function getUser() { if ($this->_user === false) { if ($this->scenario === 'loginWithEmail') { $this->_user = User::findByEmail($this->email); } else { $this->_user = User::findByLogin($this->login); } } return $this->_user; }
/** * @return array */ public function behaviors() { $behaviors = parent::behaviors(); $behaviors['authenticator'] = ['class' => CompositeAuth::className(), 'authMethods' => [['class' => HttpBasicAuth::className(), 'auth' => function ($username, $password) { $user = User::findByLogin($username); var_dump($user); die; return $user->validatePassword($password) ? $user : null; }]]]; $behaviors['authenticator'] = ['class' => HttpBasicAuth::className()]; return $behaviors; }
public function actionRestorepass() { if (!($post = \Yii::$app->getRequest()->getBodyParams())) { throw new \yii\web\HttpException(400, 'Дані не отримані'); } $model = User::findByLogin($post['login']); if (!$model->login) { throw new \yii\web\HttpException(400, 'Даного користувача не існує'); } $model->generatePasswordResetToken(); $url = 'http://localhost/home/web-client/#/restorepassword?u=' . $model->login . '&p=' . $model->password_reset_token; \Yii::$app->mailer->compose()->setFrom('*****@*****.**')->setTo($model->email)->setSubject('Відновлення паролю')->setTextBody('')->setHtmlBody("<b><a href=\"{$url}\">{$url}</a></b>")->send(); $model->save(); return true; }
/** * Checks whether email or login is unique */ public function actionCheckUnique() { $post = Yii::$app->request->post(); switch ($post['field']) { case 'email': $isUnique = User::findByEmail($post['value']) === null; break; case 'login': $isUnique = User::findByLogin($post['value']) === null; break; default: break; } Yii::$app->response->format = 'json'; return ["result" => $isUnique]; }