public function actionLogin() { $service = Yii::app()->request->getQuery('service'); if (isset($service)) { $authIdentity = Yii::app()->eauth->getIdentity($service); $authIdentity->redirectUrl = Yii::app()->user->returnUrl; $authIdentity->cancelUrl = $this->createAbsoluteUrl('/social/social/login/'); if ($authIdentity->authenticate()) { $identity = new ServiceUserIdentity($authIdentity); // successful authentication if ($identity->authenticate()) { //проверить нет ли этого пользователя $socialLogin = new SocialLoginIdentity(Yii::app()->user->getState('service'), Yii::app()->user->getState('id')); if ($socialLogin->authenticate()) { Yii::app()->user->login($identity); Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'Вы успешно авторизовались!')); $this->redirect(array(Yii::app()->getModule('user')->loginSuccess)); } else { // пользователь новый, необходимо сделать редирект на форму окончания регистрации Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'Пожалуйста, завершите регистрацию!')); $this->redirect(array('/social/social/registration/')); } // special redirect with closing popup window $authIdentity->redirect(); } else { // close popup window and redirect to cancelUrl $authIdentity->cancel(); } } // Something went wrong, redirect to login page $this->redirect(array('/social/social/login/')); } }
public function actionLogin() { $this->pageName = Yii::t('app', 'AUTH'); $this->pageTitle = $this->pageName; $service = Yii::app()->request->getQuery('service'); if (isset($service)) { $authIdentity = Yii::app()->eauth->getIdentity($service); $authIdentity->redirectUrl = '/users/login'; $authIdentity->cancelUrl = $this->createAbsoluteUrl('login'); if ($authIdentity->authenticate()) { $identity = new ServiceUserIdentity($authIdentity); // $identity = new EAuthUserIdentity($authIdentity); // Успешный вход if ($identity->authenticate()) { Yii::app()->user->login($identity, Yii::app()->user->rememberTime); // die(print_r($identity->authenticate())); // Специальный редирект с закрытием popup окна $authIdentity->redirect(); } else { die('error: cancel();'); // Закрываем popup окно и перенаправляем на cancelUrl $authIdentity->cancel(); } } die('err'); // Что-то пошло не так, перенаправляем на страницу входа $this->redirect(array('login')); } if (!Yii::app()->user->isGuest) { Yii::app()->request->redirect('/'); } Yii::import('mod.users.forms.UserLoginForm'); $model = new UserLoginForm(); $view = Yii::app()->request->isAjaxRequest ? '_form' : 'login'; if (Yii::app()->request->getIsPostRequest()) { $model->attributes = $_POST['UserLoginForm']; // integration forum // CIntegrationForums::instance()->check_user($model->login, $model->password); if ($model->validate()) { $duration = $model->rememberMe ? (int) Yii::app()->settings->get('core', 'cookie_time') : 0; if (Yii::app()->user->login($model->getIdentity(), $duration)) { if (Yii::app()->request->isAjaxRequest) { $view = 'ajax_success_login'; } else { $this->refresh(); } } else { // if (count(User::model()->findByAttributes(array('password' => User::encodePassword($model->password)))) < 1) // $model->addError('login', Yii::t('default', 'INCORRECT_LOGIN_OR_PASS')); if (count(User::model()->findByAttributes(array('login' => $model->login))) < 1 || count(User::model()->findByAttributes(array('password' => User::encodePassword($model->password)))) < 1) { $model->addError('login', Yii::t('app', 'INCORRECT_LOGIN_OR_PASS')); } } } } if (Yii::app()->request->isAjaxRequest) { Yii::app()->clientScript->scriptMap['jquery.js'] = false; } $this->render($view, array('model' => $model), false, true); }
public function run() { $model = new LoginForm(); //аутентифікація через соціальні мережі $service = Yii::app()->request->getQuery('service'); if (isset($service)) { $authIdentity = Yii::app()->eauth->getIdentity($service); $authIdentity->redirectUrl = Yii::app()->user->returnUrl; $authIdentity->cancelUrl = Yii::app()->createAbsoluteUrl('site/login'); if ($authIdentity->authenticate()) { $identity = new ServiceUserIdentity($authIdentity); //$identity = new SocialUserIdentity($authIdentity); // Успешный вход if ($identity->authenticate()) { Yii::app()->user->login($identity); Yii::app()->session['userdata'] = array('user_name' => Yii::app()->user->name); // Специальный редирект с закрытием popup окна $authIdentity->redirect(); } else { // Закрываем popup окно и перенаправляем на cancelUrl $authIdentity->cancel(); } } // Что-то пошло не так, перенаправляем на страницу входа $this->redirect(array('site/login')); } //стандартна аутентифікація // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'LoginForm') { //echo CActiveForm::validate($model); $error = CActiveForm::validate($model); if ($error != '[]') { echo $error; } Yii::app()->end(); } // collect user input data if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; if ($model->validate() && $model->login()) { Yii::app()->session['userdata'] = array('user_name' => Yii::app()->user->name); //$this->controller->redirect(Yii::app()->user->returnUrl); echo CJSON::encode(array('status' => 'success', 'user_reg_buttons' => $data['user_reg_buttons'] = $this->controller->renderPartial('user_reg_buttons', array(), true))); Yii::app()->end(); } else { $error = CActiveForm::validate($model); if ($error != '[]') { echo $error; } Yii::app()->end(); } } // display the login form //$this->controller->render('login',array('model'=>$model)); }
protected function beforeAction() { $serviceName = Yii::app()->request->getQuery('service'); if (isset($serviceName)) { /** @var $eauth EAuthServiceBase */ $eauth = Yii::app()->eauth->getIdentity($serviceName); $eauth->redirectUrl = Yii::app()->user->returnUrl; $eauth->cancelUrl = $this->createAbsoluteUrl('site/login'); //try { if ($eauth->authenticate()) { //$identity = new EAuthUserIdentity($eauth); //var_dump($eauth->getAttributes()); exit; // successful authentication $attributes = $eauth->getAttributes(); //var_dump($identity->id, $identity->name, Yii::app()->user->id);exit; // Save the attributes to display it in layouts/main.php $user = User::model()->find(array( 'condition'=>'service = :service AND service_user_id = :service_user_id', 'params'=>array(':service'=>$serviceName, ':service_user_id'=>$attributes['id'])) ); if(!$user) { $user = new User(); $user->name = $attributes['name']; $user->service = $serviceName; $user->service_user_id = $attributes['id']; $user->verification = uniqid(); $user->active = 0; $user->reg_date = date('Y-m-d H:i:s', time()); $user->avatar = 'default-user-icon-profile.png'; $user->save(); } $auth = new ServiceUserIdentity($eauth, $user->id); if($auth->authenticate()) { Yii::app()->user->login($auth); } // redirect and close the popup window if needed $eauth->redirect(); } // Something went wrong, redirect back to login page $this->redirect(array('site/login')); //} /*catch (EAuthException $e) { // save authentication error to session Yii::app()->user->setFlash('error', 'EAuthException: '.$e->getMessage()); // close popup window and redirect to cancelUrl $eauth->redirect($eauth->getCancelUrl()); }*/ } return true; }
public function actionSocial() { $service = Yii::app()->request->getQuery('service'); if (isset($service)) { $authIdentity = Yii::app()->eauth->getIdentity($service); $authIdentity->redirectUrl = Yii::app()->user->returnUrl; $authIdentity->cancelUrl = $this->createAbsoluteUrl('site/login'); if ($authIdentity->authenticate()) { $identity = new ServiceUserIdentity($authIdentity); // Успешный вход if ($identity->authenticate()) { Yii::app()->user->login($identity); // var_dump($identity); $data = ["id" => $identity->getId(), "token" => $identity->getEncriptedIdentity()]; // $return = [ // 'type' => 'raw', // 'data' => $data, // ]; // Yii::app()->request->redirect( 'http://dialog.k.mgbeta.ru'); // exit; // var_dump($data); // var_dump($_GET['redirect'] . json_encode($data)); // exit; Yii::app()->request->redirect($_GET['redirect'] . json_encode($data)); // Yii::app()->request->redirect('http://'.$host['host'].'/auth/social?redirect='.$_GET['redirectUrl'].'&identity={'.$data.'} ' ); // Yii::app()->request->redirect( $_GET['redirectUrl'] ); } else { // $data = [ // "id" => $identity->getId(), // "token" => $identity->getEncriptedIdentity() // ]; //// var_dump($identity); throw new CHttpException('500', 'Ошибка аутентификации через социальную сеть'); // throw new CHttpException('500', CJSON::encode('Ошибка аутентификации через социальную сеть')); // Yii::app()->request->redirect('http://'.$host['host'].'/auth/social?redirect='.$_GET['redirectUrl'].'&identity={'.$data.'} ' ); // Yii::app()->request->redirect($_GET['redirectUrl'].json_encode($data)); } } // Что-то пошло не так, перенаправляем на страницу входа Yii::app()->end(); } else { echo "service empty"; } }
/** * Displays the login page */ public function actionLogin() { $service = Yii::app()->request->getQuery('service'); if (isset($service)) { $authIdentity = Yii::app()->eauth->getIdentity($service); $authIdentity->redirectUrl = Yii::app()->user->returnUrl; $authIdentity->cancelUrl = $this->createAbsoluteUrl('site/login'); if ($authIdentity->authenticate()) { $identity = new ServiceUserIdentity($authIdentity); // Успешный вход if ($identity->authenticate()) { Yii::app()->user->login($identity); // Специальный редирект с закрытием popup окна $authIdentity->redirect(); } else { // Закрываем popup окно и перенаправляем на cancelUrl $authIdentity->cancel(); } } // Что-то пошло не так, перенаправляем на страницу входа $this->redirect(array('site/login')); } $model = new LoginForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid if ($model->validate() && $model->login()) { $this->redirect(Yii::app()->user->returnUrl); } } // display the login form $this->render('login', array('model' => $model)); }
/** * Displays the login page */ public function actionLogin() { /** * Авторизация по токену для восстановления пароля */ if ($recoveryPasswordToken = Yii::app()->request->getParam('token')) { if ($user = CmsUser::getByRecoveryPasswordToken($recoveryPasswordToken)) { $log = new LoginForm(); $log->username = $user->username; $log->password = $user->password; $log->login(); $this->redirect($this->createAbsoluteUrl('UserPersonal/index', array('id' => $user->id))); } } $service = Yii::app()->request->getQuery('service'); if (isset($service)) { $authIdentity = Yii::app()->eauth->getIdentity($service); $authIdentity->redirectUrl = Yii::app()->user->returnUrl; $authIdentity->cancelUrl = $this->createAbsoluteUrl('site/login'); if ($authIdentity->authenticate()) { $identity = new ServiceUserIdentity($authIdentity); // Успешный вход if ($identity->authenticate()) { Yii::app()->user->login($identity); // Специальный редирект с закрытием popup окна $authIdentity->redirect(); } else { // Закрываем popup окно и перенаправляем на cancelUrl $authIdentity->cancel(); } } $this->redirect(array('site/login')); } //авторизация с помошью соц сетей $model = new LoginForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid // $model1=CmsUser::model()->findByAttributes(array('username'=>$model->username)); $model_set = CmsSetting::model()->findByPk(1); if ($model_set->podtv_email == 1) { $user = CmsUser::model()->findByAttributes(array('username' => $model->username)); $user->sendRecoveryPasswordMessage(); $this->render('login', array('model' => $model, 'flag' => true)); Yii::app()->end(); } else { if ($model->validate() && $model->login()) { $this->redirect(array('UserPersonal/index', 'id' => Yii::app()->user->id)); } } } // display the login form $this->render('login', array('model' => $model)); }
public function actionLogin() { $service = Yii::app()->request->getQuery('service'); if ($service !== null) { $authIdentity = Yii::app()->eauth->getIdentity($service); $authIdentity->redirectUrl = Yii::app()->user->returnUrl; $authIdentity->cancelUrl = $this->createAbsoluteUrl('/social/social/login'); // если авторизовались через сервис if ($authIdentity->authenticate()) { $identity = new ServiceUserIdentity($authIdentity); // successful authentication if ($identity->authenticate()) { //проверить нет ли уже этого пользователя $socialLogin = new SocialLoginIdentity(Yii::app()->user->getState('service'), Yii::app()->user->getState('sid')); if ($socialLogin->authenticate()) { $this->cleanState(); Yii::app()->user->login($socialLogin); Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('social', 'Вы успешно авторизовались!')); //редирект с закрытием окна $authIdentity->redirect(array(Yii::app()->getModule('user')->loginSuccess)); } else { // попробуем создать учетную запись, если такой ник уже есть - редирект на форму регистрации $nick_name = preg_replace('/[^A-Za-z0-9]/', '', YText::translit($authIdentity->getAttribute('nick'))); $user = User::model()->find('LOWER(nick_name) = :nick_name', array(':nick_name' => strtolower($nick_name))); if ($user) { Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('social', 'Пожалуйста, завершите регистрацию, имя пользователя "{nick_name}" к сожалению, уже занято...', array('{nick_name}' => $nick_name))); $this->redirect(array('/social/social/registration')); } //если пользователь уже авторизован - привязка к текущему аккаунту if (Yii::app()->user->isAuthenticated()) { //создадим запись в Login $login = new Login(); $login->setAttributes(array('user_id' => Yii::app()->user->getId(), 'identity_id' => Yii::app()->user->getState('sid'), 'type' => Yii::app()->user->getState('service'))); //@TODO как-то иначе обработать неудачу if (!$login->save()) { throw new CDbException(Yii::t('social', 'При создании учетной записи произошла ошибка!')); } Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('social', 'Аккаунт привязан!')); $authIdentity->redirect(array(Yii::app()->getModule('user')->loginSuccess)); } $transaction = Yii::app()->db->beginTransaction(); try { $email = $authIdentity->getAttribute('email'); $account = new User(); $account->createAccount($nick_name, $email, null, null, User::STATUS_ACTIVE, empty($email) ? User::EMAIL_CONFIRM_NO : User::EMAIL_CONFIRM_YES, $authIdentity->getAttribute('first_name'), $authIdentity->getAttribute('last_name')); if ($account && !$account->hasErrors()) { //создадим запись в Login $login = new Login(); $login->setAttributes(array('user_id' => $account->id, 'identity_id' => Yii::app()->user->getState('sid'), 'type' => Yii::app()->user->getState('service'))); if (!$login->save()) { throw new CDbException(Yii::t('social', 'При создании учетной записи произошла ошибка!')); } } $transaction->commit(); // авторизуем нового пользователя $socialLogin = new SocialLoginIdentity(Yii::app()->user->getState('service'), Yii::app()->user->getState('sid')); if ($socialLogin->authenticate()) { $this->cleanState(); Yii::app()->user->login($socialLogin); Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('social', 'Вы успешно авторизовались!')); $this->redirect(array(Yii::app()->getModule('user')->loginSuccess)); } else { Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('social', 'Учетная запись создана, но не удалось авторизоваться!')); $this->cleanState(); $this->redirect(array('/user/account/login')); } } catch (Exception $e) { $transaction->rollback(); Yii::log(Yii::t('social', "При авторизации через {servive} произошла ошибка!", array('{servive}' => Yii::app()->user->getState('service'))), CLogger::LEVEL_ERROR); Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('social', 'При создании учетной записи произошла ошибка {error}!', array('{error}' => $e->getMessage()))); $this->cleanState(); $this->redirect(array('/social/social/registration')); } } // special redirect with closing popup window $authIdentity->redirect(); } else { $authIdentity->cancel(); } // close popup window and redirect to cancelUrl } // Something went wrong, redirect to login page $this->redirect(array('/social/social/login')); } }
public function actionLogin2() { $serviceName = Yii::app()->request->getQuery('service'); if (isset($serviceName)) { $eauth = Yii::app()->eauth->getIdentity($serviceName); $eauth->redirectUrl = Yii::app()->user->returnUrl; $eauth->cancelUrl = $this->createAbsoluteUrl('player/login2'); try { if ($eauth->authenticate()) { $identity = new ServiceUserIdentity($eauth); // Успешный вход if ($identity->authenticate()) { Yii::app()->user->login($identity, 0); $player = Player::model()->findByAttributes(array('email' => Yii::app()->user->id, 'role' => $serviceName)); if ($player == null) { $player = new Player(); $player->createSocialPlayer(Yii::app()->user->name, $serviceName); } // Специальный редирект с закрытием popup окна $eauth->redirect(); } else { // Закрываем popup окно и перенаправляем на cancelUrl $eauth->cancel(); } } // Something went wrong, redirect to login page $this->redirect(array('player/login2/')); } catch (EAuthException $e) { // save authentication error to session Yii::app()->user->setFlash('error', 'EAuthException: ' . $e->getMessage()); // close popup window and redirect to cancelUrl $eauth->redirect($eauth->getCancelUrl()); } } $model = new LoginForm(); // collect user input data if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid if ($model->validate()) { $this->redirect("/player/Myship"); } } // display the login form $this->render('login2', array('model' => $model)); }