/** * Возвращает модель по указанному идентификатору * Если модель не будет найдена - возникнет HTTP-исключение. * * @param integer идентификатор нужной модели * * @return void */ public function loadModel($id) { $model = SocialUser::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('social', 'Запрошенная страница не найдена.')); } return $model; }
/** * Возвращает модель по указанному идентификатору * Если модель не будет найдена - возникнет HTTP-исключение. * * @param integer идентификатор нужной модели * * @return void */ public function loadModel($id) { $model = SocialUser::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('SocialModule.social', 'Page not found!')); } return $model; }
public function authenticate() { $storage = SocialUser::model()->with('user')->find('provider = :provider AND uid = :uid', array(':provider' => $this->service->getServiceName(), ':uid' => $this->service->getId())); if (null === $storage || !$storage->user->isActive()) { return false; } $this->id = $storage->user->id; $this->name = $storage->user->nick_name; Yii::app()->getUser()->setState(YWebUser::STATE_ACCESS_LEVEL, $storage->user->access_level); Yii::app()->getUser()->setState(YWebUser::STATE_NICK_NAME, $storage->user->nick_name); $storage->user->last_visit = new CDbExpression('NOW()'); $storage->user->update(array('last_visit')); $this->errorCode = self::ERROR_NONE; return true; }
public function actionConnect() { if (Yii::app()->getUser()->isAuthenticated()) { $this->redirect(Yii::app()->getUser()->returnUrl); } $authData = $this->service->getAuthData(); $badLoginCount = Yii::app()->authenticationManager->getBadLoginCount(Yii::app()->getUser()); $scenario = $badLoginCount > 3 ? 'loginLimit' : ''; $form = new LoginForm($scenario); if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['LoginForm'])) { $form->setAttributes(Yii::app()->getRequest()->getPost('LoginForm')); if ($form->validate() && Yii::app()->authenticationManager->login($form, Yii::app()->getUser(), Yii::app()->getRequest())) { $social = new SocialUser(); $social->user_id = Yii::app()->getUser()->getId(); $social->provider = $authData['service']; $social->uid = $authData['uid']; if ($social->save()) { Yii::app()->getUser()->setFlash(YFlashMessages::SUCCESS_MESSAGE, Yii::t('SocialModule.social', 'Social network successfully attached to your account, you can use it to log in now.')); $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)); } } else { $form->addError('hash', Yii::t('SocialModule.social', 'Wrong email or password!')); Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->getUser(), $badLoginCount + 1); } } $this->render('connect', ['authData' => $authData, 'model' => $form]); }
public function actionConnect() { if (Yii::app()->getUser()->isAuthenticated()) { $this->redirect(Yii::app()->getUser()->returnUrl); } $authData = $this->service->getAuthData(); $badLoginCount = Yii::app()->authenticationManager->getBadLoginCount(Yii::app()->getUser()); $scenario = $badLoginCount > 3 ? 'loginLimit' : ''; $form = new LoginForm($scenario); if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['LoginForm'])) { $form->setAttributes(Yii::app()->getRequest()->getPost('LoginForm')); if ($form->validate() && Yii::app()->authenticationManager->login($form, Yii::app()->getUser(), Yii::app()->getRequest())) { $social = new SocialUser(); $social->user_id = Yii::app()->getUser()->getId(); $social->provider = $authData['service']; $social->uid = $authData['uid']; if ($social->save()) { 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)); } } else { $form->addError('hash', Yii::t('SocialModule.social', 'Email or password was typed wrong!')); Yii::app()->authenticationManager->setBadLoginCount(Yii::app()->getUser(), $badLoginCount + 1); } } $this->render('connect', array('authData' => $authData, 'model' => $form)); }