本文整理汇总了PHP中app\models\LoginForm::getUser方法的典型用法代码示例。如果您正苦于以下问题:PHP LoginForm::getUser方法的具体用法?PHP LoginForm::getUser怎么用?PHP LoginForm::getUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\LoginForm
的用法示例。
在下文中一共展示了LoginForm::getUser方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetUser
public function testGetUser()
{
// failure
$model = new LoginForm();
$model->username = 'wrong_username';
$this->assertNull($model->getUser());
// success
$model = new LoginForm();
$model->username = $this->users['user1']['username'];
$this->assertInstanceOf('app\\models\\User', $model->getUser());
}
示例2: actionLogin
public function actionLogin()
{
$model = new LoginForm();
$data = Yii::$app->request->post();
$model->load($data, '');
if ($model->login()) {
$user = $model->getUser();
return ['token' => $user->token];
} else {
Yii::$app->response->statusCode = 401;
return ['errors' => $this->filterErrors($model->getErrors())];
}
}
示例3: actionLogin
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
$user = User::findOne(Yii::$app->user->id);
return json_encode(['success' => true, 'data' => $user->attributes]);
}
$login = new LoginForm();
$login->email = Yii::$app->request->post('email');
$login->password = Yii::$app->request->post('password');
if ($login->login()) {
$user = $login->getUser();
return json_encode(['success' => true, 'data' => $user->attributes]);
} else {
if ($login->hasErrors()) {
return json_encode(['success' => false, 'data' => $login->getErrors()]);
}
}
}
示例4: actionLogin
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->afterLogin();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
$user = $model->getUser();
if ($user->status != User::STATUS_ACTIVE) {
Yii::$app->user->logout();
Yii::$app->session->setFlash('error', 'Your account is not active.');
return $this->refresh();
}
if ($user->role >= User::ROLE_STAFF) {
return $this->redirect(['/admin']);
} else {
Yii::$app->user->logout();
Yii::$app->session->setFlash('error', 'You do not have permission.');
return $this->refresh();
}
} else {
return $this->render('login', ['model' => $model]);
}
}
示例5: actionReset
/**
* Send email link to access reset password
* @return type mixed
*/
public function actionReset()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
//if request is post
if ($model->load(Yii::$app->request->post())) {
if ($user = $model->getUser()) {
//Found user
\Yii::$app->notification->sendMail($user->identity, 4, ['{{name}}' => $user->profile->first_name, '{{link}}' => Html::a('This URL', Yii::$app->urlManager->createAbsoluteUrl(['admin/changesecurity/', 'token' => base64_encode($user->access_token)]))]);
Yii::$app->session->setFlash('success', 'We have sent an email with the reset link! Please check it out.');
$model = new LoginForm();
} else {
//No user exists
Yii::$app->session->setFlash('error', 'You are not a member!');
}
}
return $this->render('reset', ['model' => $model]);
}
示例6: actionReset
/**
* Send email link to access reset password
* @return void mixed
*/
public function actionReset()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
//if request is post
if ($model->load(Yii::$app->request->post())) {
if ($user = $model->getUser()) {
//Found user
if ($user->level == 3) {
$params = ['{{name}}' => $user->parent->profile->first_name, '{{child}}' => $user->profile->label . ' "' . $user->fullname . '"', '{{link}}' => Html::a('Click', Yii::$app->urlManager->createAbsoluteUrl(['user/family/', 'id' => $user->id]))];
\Yii::$app->notification->sendMail($user->parent->identity, 5, $params);
Yii::$app->session->setFlash('success', 'We have sent an email to your parent! Please ask to reset your password.');
} else {
$params = ['{{name}}' => $user->profile->first_name, '{{link}}' => Html::a('This URL', Yii::$app->urlManager->createAbsoluteUrl(['user/changesecurity/', 'token' => base64_encode($user->access_token)]))];
\Yii::$app->notification->sendMail($user->identity, 4, $params);
Yii::$app->session->setFlash('success', 'We have sent an email with the reset link! Please check it out.');
}
$model = new LoginForm();
} else {
//No user exists
Yii::$app->session->setFlash('error', 'You are not a member!');
}
}
return $this->render('reset', ['model' => $model]);
}