本文整理汇总了PHP中app\models\LoginForm::login方法的典型用法代码示例。如果您正苦于以下问题:PHP LoginForm::login方法的具体用法?PHP LoginForm::login怎么用?PHP LoginForm::login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\LoginForm
的用法示例。
在下文中一共展示了LoginForm::login方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLoginNoUser
public function testLoginNoUser()
{
$model = new LoginForm(['username' => 'not_existing_username', 'password' => 'not_existing_password']);
$this->specify('user should not be able to login, when there is no identity', function () use($model) {
expect('model should not login user', $model->login())->false();
expect('user should not be logged in', Yii::$app->user->isGuest)->true();
});
$model->username = 'demo';
$model->password = 'wrong_password';
$this->specify('user should not be able to login with wrong password', function () use($model) {
expect('model should not login user', $model->login())->false();
expect('error message should be set', $model->errors)->hasKey('password');
expect('user should not be logged in', Yii::$app->user->isGuest)->true();
});
}
示例2: actionLogin
public function actionLogin()
{
$nombre = null;
if (!\Yii::$app->user->isGuest) {
$nombre = $nombre = Yii::$app->user->identity->nombre_usuario;
if (User::isUserAdmin(Yii::$app->user->identity->id)) {
$this->redirect(['usuario/admin']);
}
if (User::isUserProfe(Yii::$app->user->identity->id)) {
$this->redirect(['usuario/profesor']);
}
if (User::isUserSubcomision(Yii::$app->user->identity->id)) {
$this->redirect(['usuario/subcomision']);
}
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
$nombre = Yii::$app->user->identity->nombre_usuario;
if (User::isUserAdmin(Yii::$app->user->identity->id)) {
$this->redirect(['usuario/admin']);
}
if (User::isUserProfe(Yii::$app->user->identity->id)) {
$this->redirect(['usuario/profesor']);
}
if (User::isUserSubcomision(Yii::$app->user->identity->id)) {
$this->redirect(['usuario/subcomision']);
}
}
return $this->render('login', ['model' => $model]);
}
示例3: actionLogin
public function actionLogin()
{
$endDate = \app\models\Weeks::END_DATE;
if (date('Y-m-d') > $endDate) {
return $this->render('unavailable', ['endDate' => $endDate]);
}
if (!\Yii::$app->user->isGuest) {
return $this->AddEssay();
}
if (Yii::$app->request->isAjax && Yii::$app->request->get('sendCodePhone')) {
return $this->sendCodePhone(Yii::$app->request->get('sendCodePhone'));
} elseif (Yii::$app->request->isAjax && Yii::$app->request->get('checkCode') && Yii::$app->request->get('phone')) {
return $this->checkCode(Yii::$app->request->get('phone'), Yii::$app->request->get('checkCode'));
}
$signupForm = new SignupForm();
if ($signupForm->load(Yii::$app->request->post()) && $signupForm->signup()) {
return $this->AddEssay('register');
}
$loginForm = new LoginForm();
if ($loginForm->load(Yii::$app->request->post()) && $loginForm->login()) {
if (Yii::$app->user->identity->isModerator() || Yii::$app->user->identity->isClient()) {
return $this->redirect(["/admin/index"]);
} else {
return $this->AddEssay('login');
}
}
return $this->render('login', ['loginForm' => $loginForm, 'signupForm' => $signupForm]);
}
示例4: actionIndex
/**
* Вывод главной страницы с 3 формами:
* авторизация, регистрация и восстановление
* пароля. Все 3 обработчика форм
* лаконичнее располагать по одному
* запросу
*
* @return string|\yii\web\Response
*/
public function actionIndex()
{
if (Yii::$app->user->isGuest) {
//Авторизация
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
}
//Регистрация
$reg = new RegForm();
if ($reg->load(Yii::$app->request->post()) && $reg->save()) {
Yii::$app->getSession()->setFlash('reg-success');
return $this->goBack();
}
//Восстановление пароля
$forget = new PasswordResetForm();
if ($forget->load(Yii::$app->request->post()) && $forget->validate()) {
if ($forget->sendEmail()) {
Yii::$app->getSession()->setFlash('forget-send');
}
return $this->goBack();
}
return $this->render('index', ['model' => $model, 'reg' => $reg, 'forget' => $forget]);
} else {
return $this->render('panel');
}
}
示例5: actionLogin
public function actionLogin()
{
$this->layout = 'login';
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
$role = Yii::$app->user->identity->getRole(Yii::$app->user->id);
if ($role == "instructor") {
$url = Yii::$app->urlManager->createUrl("instructor/instructor");
$this->redirect($url);
} else {
if ($role == "admin") {
$url = Yii::$app->urlManager->createUrl("site/dashboard");
$this->redirect($url);
} else {
if ($role == "student") {
$url = Yii::$app->urlManager->createUrl("student/student");
$this->redirect($url);
} else {
return $this->goBack();
}
}
}
} else {
return $this->render('login', ['model' => $model]);
}
}
示例6: testLoginCorrect
public function testLoginCorrect()
{
$model = new LoginForm(['username' => 'demo', 'password' => 'demo']);
expect('model should login user', $model->login())->true();
expect('error message should not be set', $model->errors)->hasntKey('password');
expect('user should be logged in', Yii::$app->user->isGuest)->false();
}
示例7: actionRegister
public function actionRegister()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new RegisterForm();
$request = Yii::$app->request;
$post = $request->post();
if (isset($post)) {
$model->attributes = $request->post('RegisterForm');
if ($model->validate()) {
//create user in DB
$user = new User();
$user->username = $model->username;
$user->password = $model->password;
$user->no_login = 0;
$user->save();
//perform login
$login = new LoginForm();
$login->username = $user->username;
$login->password = $user->password;
$login->login();
return $this->goHome();
}
}
return $this->render('register', ['model' => $model]);
}
示例8: actionLogin
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$this->layout = 'login';
$model = new LoginForm();
$passResetModel = new PasswordResetRequestForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
if ($passResetModel->load(Yii::$app->request->post()) && $passResetModel->validate()) {
/*Yii::$app->mailer->compose()
->setFrom('test@gmail.com')
->setTo('trantor.php@gmail.com')
->setSubject('Email sent from Yii2-Swiftmailer')
->setTextBody('asdfasdasd')
->send();*/
if ($passResetModel->sendEmail()) {
Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');
return $this->goHome();
} else {
Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
return $this->goBack();
}
} else {
return $this->render('login', ['model' => $model, 'passResetModel' => $passResetModel]);
}
}
}
示例9: actionIndex
public function actionIndex()
{
$session = Yii::$app->session;
// count login failed
$countLogin = 0;
$session->remove('countLogin');
if ($session->has('countLogin')) {
$countLogin = $session->get('countLogin');
}
$this->layout = 'loginLayout';
if (!\Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post())) {
if ($model->login()) {
$session->remove('countLogin');
return $this->redirect('/admin/top');
} else {
$countLogin++;
$session->set('countLogin', $countLogin);
}
}
// var_dump($countLogin);
return $this->render('index', ['model' => $model]);
}
示例10: actionLogin
public function actionLogin()
{
$serviceName = Yii::$app->getRequest()->getQueryParam('service');
if (isset($serviceName)) {
/** @var $eauth \nodge\eauth\ServiceBase */
$eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
$eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl());
$eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));
try {
if ($eauth->authenticate()) {
// var_dump($eauth->getIsAuthenticated(), $eauth->getAttributes()); exit;
$identity = User::findByEAuth($eauth);
Yii::$app->getUser()->login($identity);
// special redirect with closing popup window
$eauth->redirect();
} else {
// close popup window and redirect to cancelUrl
$eauth->cancel();
}
} catch (\nodge\eauth\ErrorException $e) {
// save error to show it later
Yii::$app->getSession()->setFlash('error', 'EAuthException: ' . $e->getMessage());
// close popup window and redirect to cancelUrl
// $eauth->cancel();
$eauth->redirect($eauth->getCancelUrl());
}
}
$model = new LoginForm();
if ($model->load($_POST) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', array('model' => $model));
}
}
示例11: actionLogin
public function actionLogin()
{
$model = new LoginForm();
if (!Yii::$app->user->isGuest or $model->load(Yii::$app->request->post()) && $model->login()) {
$usuarioActual = UsuariosRoles::find()->where('usuarioId = :id', ['id' => Yii::$app->user->id])->all();
foreach ($usuarioActual as $ua) {
if ($ua->roles->nombre == "educacion") {
return $this->redirect(["site/escuelas"]);
} else {
if ($ua->roles->nombre == "Proyectos") {
return $this->redirect(['proyectos/index']);
} else {
if ($ua->roles->nombre == "eduardo") {
return $this->redirect(['dictamenes/index']);
} else {
if ($ua->roles->nombre == "Zonificacion") {
return $this->redirect(['tramite-zonificacion/index']);
} else {
if ($ua->roles->nombre == "Uso de Suelo") {
return $this->redirect(['tramite-zonificacion/index']);
//$rol = UsuariosRoles::find()->where('usuarioId = '. Yii::$app->user->id)->one();
//$tramites = TipoTramitesRoles::find()->where('roleId = '. $rol->roleId . ' and leer = 1' )->all();
//return $this->redirect(['tipos-tramite/index']);
//'index',['tipos-tramites'=>$tramites]);
} else {
if ($ua->roles->nombre == 'Dev') {
return $this->redirect(['tramite-zonificacion/index']);
} else {
if ($ua->roles->nombre == 'pedro') {
return $this->redirect(['tramites-espectaculares/index']);
} else {
if ($ua->roles->nombre == 'Fraccionamiento') {
return $this->redirect(['tramites-autorizacion/index']);
} else {
if ($ua->roles->nombre == 'Construccion') {
return $this->redirect(['tramites-alineamiento/index']);
} else {
if ($ua->roles->nombre == 'Sistemas') {
return $this->redirect(['tipos-tramite/index']);
} else {
if ($ua->roles->nombre == "Direccion") {
return $this->redirect(['tramite-zonificacion/index']);
}
}
}
}
}
}
}
}
}
}
}
}
} else {
$requisitos = Requisitos::find()->all();
return $this->render('login', ['model' => $model, 'requisitos' => $requisitos]);
}
}
示例12: actionLogin
public function actionLogin()
{
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
$this->goHome();
}
return $this->render('login', ['model' => $model]);
}
示例13: actionLogin
public function actionLogin()
{
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
}
return $this->render('login', compact('model'));
}
示例14: actionLogin
public function actionLogin()
{
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->redirect(\Yii::$app->urlManager->createUrl('admin/index'));
}
return $this->render('login', ['model' => $model]);
}
示例15: actionIndex
/**
* Display login form to authorize user
*/
public function actionIndex()
{
$model = new LoginForm();
if ($model->load(\Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('index', ['model' => $model]);
}
}