/** * @var $service \IAuthService */ public function actionLogin() { try { if ($this->service->authenticate()) { $identity = new UserIdentity($this->service); if ($identity->authenticate() && Yii::app()->getUser()->login($identity)) { Yii::app()->getUser()->setFlash(YFlashMessages::SUCCESS_MESSAGE, Yii::t('SocialModule.social', 'You successfully logged in!')); $module = Yii::app()->getModule('user'); $redirect = Yii::app()->getUser()->isSuperUser() && $module->loginAdminSuccess ? [$module->loginAdminSuccess] : [$module->loginSuccess]; Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->getUser(), 0); $this->redirect(Yii::app()->getUser()->getReturnUrl($redirect)); } if ($this->service->hasAttribute('email') && Yii::app()->userManager->isUserExist($this->service->email)) { Yii::app()->getUser()->setFlash(YFlashMessages::INFO_MESSAGE, Yii::t('SocialModule.social', 'Account with this email address already exists! Please, login if you want to join this social network to your account.')); $this->redirect(['/social/connect', 'service' => $this->service->getServiceName()]); } Yii::app()->getUser()->setFlash(YFlashMessages::SUCCESS_MESSAGE, Yii::t('SocialModule.social', 'You\'ve successfully logged in, please complete the registration!')); $this->redirect(['/social/register', 'service' => $this->service->getServiceName()]); } $this->redirect('/login'); } catch (EAuthException $e) { Yii::app()->getUser()->setFlash('error', 'EAuthException: ' . $e->getMessage()); $this->redirect('/login'); } }
/** * @var $service \IAuthService */ public function actionLogin() { try { if ($this->service->authenticate()) { $identity = new UserIdentity($this->service); if ($identity->authenticate() && Yii::app()->getUser()->login($identity)) { Yii::app()->getUser()->setFlash(YFlashMessages::SUCCESS_MESSAGE, Yii::t('SocialModule.social', 'Вы успешно вошли!')); $module = Yii::app()->getModule('user'); $redirect = Yii::app()->getUser()->isSuperUser() && $module->loginAdminSuccess ? array($module->loginAdminSuccess) : array($module->loginSuccess); Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->getUser(), 0); $this->redirect(Yii::app()->getUser()->getReturnUrl($redirect)); } if ($this->service->hasAttribute('email') && Yii::app()->userManager->isUserExist($this->service->email)) { Yii::app()->getUser()->setFlash(YFlashMessages::INFO_MESSAGE, Yii::t('SocialModule.social', 'Аккаунт с таким адресом уже существует! Войдите если хотите присоединить эту социальную сеть к своему аккаунту.')); $this->redirect(array('/social/connect', 'service' => $this->service->getServiceName())); } Yii::app()->getUser()->setFlash(YFlashMessages::SUCCESS_MESSAGE, Yii::t('SocialModule.social', 'Вы успешно авторизовались, пожалуйста, завершите регистрацию!')); $this->redirect(array('/social/register', 'service' => $this->service->getServiceName())); } $this->redirect('/login'); } catch (EAuthException $e) { Yii::app()->getUser()->setFlash('error', 'EAuthException: ' . $e->getMessage()); $this->redirect('/login'); } }