public function actionLogin() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { return $this->render('login', ['model' => $model]); } }
/** * Logs in a user. * * @return mixed */ public function actionAcceso() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } $this->layout = 'invitados'; return $this->render('acceso', ['model' => $model]); }
/** * Logs in the user if his profile is activated, * if not, displays standard error message. * * @return string|\yii\web\Response */ public function actionLogin() { if (!Yii::$app->user->isGuest) { return $this->goHome(); } // get setting value for 'Login With Email' $lwe = Yii::$app->params['LoginWithEmail']; // if "login with email" is true we instantiate LoginForm in "lwe" scenario $lwe ? $model = new LoginForm(['scenario' => 'LoginWithEmail']) : ($model = new LoginForm()); // everything went fine, log in the user if ($model->load(Yii::$app->request->post()) && $model->login()) { AccessControl::checkRoleAssignment(); return $this->goBack(); } else { return $this->render('login', ['model' => $model]); } }
/** * Logs in a user. * * @return mixed */ public function actionLogin() { if (!\Yii::$app->user->isGuest) { return $this->redirect(['user-panel/settings']); } $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(); $this->redirect($eauth->getCancelUrl()); } } else { $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { return $this->render('login', ['model' => $model]); } } }