/** * Registration user */ public function actionRegistration() { $this->layout = '//layouts/login'; $model = new RegistrationForm(); // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'signup-form_id') { /* echo UActiveForm::validate($model); Yii::app()->end(); */ $errors = CActiveForm::validate($model); echo $errors; Yii::app()->end(); } if (Yii::app()->user->id) { $this->redirect('/'); } else { $this->redirect('/login'); if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; $model->verifyPassword = $model->password; if ($model->validate()) { $soucePassword = $model->password; $model->activkey = UsersModule::encrypting(microtime() . $model->password); $model->password = UsersModule::encrypting($model->password); $model->verifyPassword = UsersModule::encrypting($model->verifyPassword); $model->status = Yii::app()->getModule('users')->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE; if ($model->save()) { Yii::app()->queue->subscribe($model->id, null, "User.{$model->id}"); if (Yii::app()->getModule('users')->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email)); UsersModule::sendMail($model->email, UsersModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UsersModule::t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url))); } // wellcome email $subject = Yii::t('email', 'Welcome'); $message = Yii::t('email', 'Welcome to <a href="{url}">{catalog}</a>.', array('{url}' => $this->createAbsoluteUrl('/'), '{catalog}' => Yii::app()->name)); SendMail::send($model->email, $subject, $message, true); if ((Yii::app()->getModule('users')->loginNotActiv || Yii::app()->getModule('users')->activeAfterRegister && Yii::app()->getModule('users')->sendActivationMail == false) && Yii::app()->getModule('users')->autoLogin) { $identity = new UserIdentity($model->username, $soucePassword); $identity->authenticate(); Yii::app()->user->login($identity, 0); $this->redirect(Yii::app()->getModule('users')->returnUrl); } else { if (!Yii::app()->getModule('users')->activeAfterRegister && !Yii::app()->getModule('users')->sendActivationMail) { Yii::app()->user->setFlash('registration', UsersModule::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif (Yii::app()->getModule('users')->activeAfterRegister && Yii::app()->getModule('users')->sendActivationMail == false) { Yii::app()->user->setFlash('registration', UsersModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UsersModule::t('Login'), Yii::app()->getModule('users')->loginUrl)))); } elseif (Yii::app()->getModule('users')->loginNotActiv) { Yii::app()->user->setFlash('registration', UsersModule::t("Thank you for your registration. Please check your email or login.")); } else { Yii::app()->user->setFlash('registration', UsersModule::t("Thank you for your registration. Please check your email.")); } $this->refresh(); } } } else { // var_dump($model->errors);die(); } } $this->render('/user/registration', array('model' => $model)); } }
/** * Activation user account */ public function actionActivation() { $email = $_GET['email']; $activkey = $_GET['activkey']; if ($email && $activkey) { $find = User::model()->notsafe()->findByAttributes(array('email' => $email)); if (isset($find) && $find->status) { $this->render('/user/message', array('title' => UsersModule::t("User activation"), 'content' => UsersModule::t("Your account is active."))); } elseif (isset($find->activkey) && $find->activkey == $activkey) { $find->activkey = UsersModule::encrypting(microtime()); $find->status = 1; $find->save(); $this->render('/user/message', array('title' => UsersModule::t("User activation"), 'content' => UsersModule::t("Your account is activated."))); } else { $this->render('/user/message', array('title' => UsersModule::t("User activation"), 'content' => UsersModule::t("Incorrect activation URL."))); } } else { $this->render('/user/message', array('title' => UsersModule::t("User activation"), 'content' => UsersModule::t("Incorrect activation URL."))); } }
/** * Change password */ public function actionChangepassword() { $model = new UserChangePassword(); if (Yii::app()->user->id) { // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') { echo UActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['UserChangePassword'])) { $model->attributes = $_POST['UserChangePassword']; if ($model->validate()) { $new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id); $new_password->password = UsersModule::encrypting($model->password); $new_password->activkey = UsersModule::encrypting(microtime() . $model->password); $new_password->save(); Yii::app()->user->setFlash('profileMessage', UsersModule::t("New password is saved.")); $this->redirect(array("profile")); } } $this->render('changepassword', array('model' => $model)); } }
public function actionUpdate($id) { $user = $this->_loadUser($id); // if($user->id == Yii::app()->user->id) // $this->redirect('/settings'); // форма изменения пароля $changePassword = new UserChangePassword(); if (isset($_POST['User'])) { $this->performAjaxValidation($user, 'form-fullname'); $this->performAjaxValidation($user, 'form-about'); $this->performAjaxValidation($user, 'form-social'); if (isset($_POST['ajax']) && $_POST['ajax'] === 'form-account-username') { $errors = CActiveForm::validate($user); if ($errors !== '[]') { // echo CJSON::encode($errors); //echo CJSON::encode(false); echo 'false'; Yii::app()->end(); } } if (isset($_POST['ajax']) && $_POST['ajax'] === 'form-account-email') { $errors = CActiveForm::validate($user); if ($errors !== '[]') { //echo CJSON::encode($errors); //echo CJSON::encode(false); echo 'false'; Yii::app()->end(); } } $data = Yii::app()->request->getPost('User'); if ($data) { $user->attributes = $data; } if (!$user->save()) { VarDumper::dump($user->errors); } } if (isset($_POST['UserChangePassword'])) { $this->performAjaxValidation($changePassword, 'form-changepassword'); $data = Yii::app()->request->getPost('UserChangePassword'); $changePassword->attributes = $data; if ($changePassword->validate()) { $new_password = User::model()->notsafe()->findbyPk($user->id); $new_password->password = UsersModule::encrypting($changePassword->password); $new_password->activkey = UsersModule::encrypting(microtime() . $changePassword->password); if ($new_password->save(false)) { echo 'done'; } else { // VarDumper::dump($new_password->errors); } } } if (Yii::app()->request->isAjaxRequest) { Yii::app()->end(); } else { $this->render('view', array('user' => $user, 'changePassword' => $changePassword)); } }
/** * Displays the login page */ public function actionLogin() { if (Yii::app()->user->isGuest) { $modelLogin = new UserLogin(); $modelRegister = new RegistrationForm(); $modelRecovery = new UserRecoveryForm(); // collect user input data if (isset($_POST['ajax']) && $_POST['ajax'] === 'form-login') { $errors = CActiveForm::validate($modelLogin); echo $errors; /* if(Yii::app()->request->urlReferrer && Yii::app()->request->urlReferrer == 'http://'.Yii::app()->request->serverName.'/mkreview'){ // Сохраняем в сессию единицу, чтобы сохранить данные в localStorage при создании отзыва Yii::app()->session['redirectReview'] = 1; }*/ Yii::app()->end(); } if (isset($_POST['ajax']) && $_POST['ajax'] === 'form-register') { if (isset($_POST['RegistrationForm']['username'])) { $modelRegister->fullname = $_POST['RegistrationForm']['username']; } $errors = CActiveForm::validate($modelRegister); if ($errors != '[]') { echo $errors; Yii::app()->end(); } } if (isset($_POST['UsersLogin'])) { $modelLogin->attributes = $_POST['UsersLogin']; // validate user input and redirect to previous page if valid if ($modelLogin->validate()) { $this->lastViset(); /* if(Yii::app()->request->urlReferrer && Yii::app()->request->urlReferrer == 'http://'.Yii::app()->request->serverName.'/mkreview'){ // Сохраняем в сессию единицу, чтобы сохранить данные в localStorage при создании отзыва Yii::app()->session['redirectReview'] = 1; }*/ if (Yii::app()->user->returnUrl == '/index.php' || Yii::app()->user->returnUrl == '/') { $this->redirect(Yii::app()->getModule('users')->returnUrl); } else { $this->redirect(Yii::app()->user->returnUrl); } } else { VarDumper::dump($modelLogin->errors); die; // Ctrl + X Delete line } } if (isset($_POST['RegistrationForm'])) { $modelRegister->attributes = $_POST['RegistrationForm']; $modelRegister->fullname = $modelRegister->username; $modelRegister->verifyPassword = $modelRegister->password; if ($modelRegister->validate()) { $soucePassword = $modelRegister->password; $modelRegister->activkey = UsersModule::encrypting(microtime() . $modelRegister->password); $modelRegister->password = UsersModule::encrypting($modelRegister->password); $modelRegister->verifyPassword = UsersModule::encrypting($modelRegister->verifyPassword); $modelRegister->superuser = 0; $modelRegister->status = Yii::app()->getModule('users')->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE; if ($modelRegister->save()) { if (Yii::app()->getModule('users')->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/users/activation/activation', array("activkey" => $modelRegister->activkey, "email" => $modelRegister->email)); UsersModule::sendMail($modelRegister->email, UsersModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UsersModule::t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url))); } // wellcome email // $subject = Yii::t('email','Welcome'); // $message = Yii::t('email', 'Welcome to <a href="{url}">{catalog}</a>.', array('{url}'=>$this->createAbsoluteUrl('/'), '{catalog}'=>Yii::app()->name)); // SendMail::send($modelRegister->email,$subject,$message,true); if ((Yii::app()->getModule('users')->loginNotActiv || Yii::app()->getModule('users')->activeAfterRegister && Yii::app()->getModule('users')->sendActivationMail == false) && Yii::app()->getModule('users')->autoLogin) { $identity = new UserIdentity($modelRegister->username, $soucePassword); $identity->authenticate(); Yii::app()->user->login($identity, 0); $this->lastViset(); if (Yii::app()->request->isAjaxRequest) { echo '[]'; Yii::app()->end(); } else { /*if(Yii::app()->request->urlReferrer && Yii::app()->request->urlReferrer == 'http://'.Yii::app()->request->serverName.'/mkreview'){ // Сохраняем в сессию единицу, чтобы сохранить данные в localStorage при создании отзыва Yii::app()->session['redirectReview'] = 1; }*/ if (Yii::app()->request->urlReferrer && Yii::app()->request->urlReferrer != 'http://' . Yii::app()->request->serverName . '/login') { $url = Yii::app()->request->urlReferrer; $this->redirect($url); } else { $this->redirect('/'); } } } else { if (!Yii::app()->getModule('users')->activeAfterRegister && !Yii::app()->getModule('users')->sendActivationMail) { Yii::app()->user->setFlash('registration', UsersModule::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif (Yii::app()->getModule('users')->activeAfterRegister && Yii::app()->getModule('users')->sendActivationMail == false) { Yii::app()->user->setFlash('registration', UsersModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->getModule('users')->loginUrl)))); } elseif (Yii::app()->getModule('users')->loginNotActiv) { Yii::app()->user->setFlash('registration', UsersModule::t("Thank you for your registration. Please check your email or login.")); } else { Yii::app()->user->setFlash('registration', UsersModule::t("Thank you for your registration. Please check your email.")); } if (Yii::app()->request->isAjaxRequest) { echo '[]'; Yii::app()->end(); } else { /*if(Yii::app()->request->urlReferrer && Yii::app()->request->urlReferrer == 'http://'.Yii::app()->request->serverName.'/mkreview'){ // Сохраняем в сессию единицу, чтобы сохранить данные в localStorage при создании отзыва Yii::app()->session['redirectReview'] = 1; }*/ if (Yii::app()->request->urlReferrer && Yii::app()->request->urlReferrer != 'http://' . Yii::app()->request->serverName . '/login') { $url = Yii::app()->request->urlReferrer; $this->redirect($url); } else { $this->redirect('/'); } } } } } else { var_dump($modelRegister->errors); die; } } // display the login form $this->render('application.modules.users.views.user.login', array('modelLogin' => $modelLogin, 'modelRecovery' => $modelRecovery, 'modelRegister' => $modelRegister)); } else { if (Yii::app()->request->urlReferrer && Yii::app()->request->urlReferrer != 'http://' . Yii::app()->request->serverName . '/login') { $url = Yii::app()->request->urlReferrer; $this->redirect($url); } else { $this->redirect('/'); } } }
public function actionTwlogin() { $redirectUrl = '/'; if (isset(Yii::app()->session['twredirect']) && !empty(Yii::app()->session['twredirect'])) { $redirectUrl = Yii::app()->session['twredirect']; unset(Yii::app()->session['twredirect']); } if (isset($_REQUEST['oauth_token']) && Yii::app()->session['oauth_token'] !== $_REQUEST['oauth_token']) { Yii::app()->session['oauth_status'] = 'oldtoken'; } /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */ $twitter = Yii::app()->twitter->getTwitterTokened(Yii::app()->session['oauth_token'], Yii::app()->session['oauth_token_secret']); /* Request access tokens from twitter */ if (!isset($_REQUEST['oauth_verifier'])) { $this->redirect($redirectUrl); die; } // $access_token = $twitter->getAccessToken($_REQUEST['oauth_verifier']); $access_token = $twitter->getAccessToken($_REQUEST['oauth_verifier'], $_REQUEST['oauth_token']); /* Save the access tokens. Normally these would be saved in a database for future use. */ Yii::app()->session['access_token'] = $access_token; /* Remove no longer needed request tokens */ unset(Yii::app()->session['oauth_token']); unset(Yii::app()->session['oauth_token_secret']); if (200 == $twitter->http_code) { /* The user has been verified and the access tokens can be saved for future use */ Yii::app()->session['status'] = 'verified'; //get an access twitter object $twitter = Yii::app()->twitter->getTwitterTokened($access_token['oauth_token'], $access_token['oauth_token_secret']); //get user details $accountInfo = $twitter->get("account/verify_credentials"); //get friends ids // $friends= $twitter->get("friends/ids"); //get followers ids // $followers= $twitter->get("followers/ids"); //tweet // $result=$twitter->post('statuses/update', array('status' => "Tweet message")); // если пользователь не найден if (empty($accountInfo)) { $this->redirect($redirectUrl); die; } $login = '******' . $accountInfo->id; $password = crc32($accountInfo->id); // пробуем авторизоваться и войти $authenticate = $this->enterSite($login, $password); if (!Yii::app()->user->isGuest) { // вошли $model = Yii::app()->user->getModel(); $this->redirect($redirectUrl); die; } if (!$authenticate) { Yii::app()->session['registerAccountInfo'] = array('username' => $login, 'password' => $password, 'interests' => '', 'avatarUrl' => $accountInfo->profile_image_url, 'token' => $access_token['oauth_token'], 'social' => 'twitter'); if (!empty($accountInfo->profile_image_url)) { $img = str_replace('_normal', '_bigger', $accountInfo->profile_image_url); } else { $img = null; } $model = new FormRegisterSocial(); $model->username = $login; $model->password = $password; $model->photo = $img; $model->fullname = !empty($accountInfo->name) ? $accountInfo->name : $login; $model->email = null; $model->avatar_enc = !empty($model->photo) ? base64_encode(Controller::getRemoteContents($model->photo)) : ''; $model->from_soc_network = true; $model->soc_network_name = 'twitter'; // если подхваченные данные валидны - регистрируем if ($model->validate()) { $soucePassword = $model->password; $model->activkey = UsersModule::encrypting(microtime() . $model->password); $model->password = UsersModule::encrypting($model->password); $model->superuser = 0; $model->status = User::STATUS_ACTIVE; if ($model->save()) { // удаляем регистрационные данные из сессии Yii::app()->session['registerAccountInfo'] = null; $model->chickPhoto(); $this->enterSite($login, $soucePassword); } $this->redirect($redirectUrl); Yii::app()->end(); } else { $this->addFlashMessage($model->errors, 'error'); $model->clearErrors(); } $this->redirect($redirectUrl); Yii::app()->end(); /* $this->render('registersocial', array( 'model' => $model, 'login' => $login, 'filetoken' => sha1(time() . rand()), ));*/ } } else { /* Save HTTP status for error dialog on connnect page.*/ //header('Location: /clearsessions.php'); // $this->redirect(Yii::app()->homeUrl); $this->redirect($redirectUrl); Yii::app()->end(); } }