public function login() { //前端传来的参数用quickInput()获取,不管是GET还是POST的,框架会自动过滤数据 //$param = quickInput('userName'); //因为暂时没有前台和数据库,这里模拟一下就好了 $param = 'hello world'; $server = new UserModule(); echo $server->login($param); }
public function actionSave() { $id = $_POST['id']; $ha = UserModule::model()->deleteAllByAttributes(array("user_level_id" => $id)); $q = $_POST['q']; $arr = explode(";;", $q); $num = 1; foreach ($arr as $elem) { $ha = new UserModule(); $ha->user_level_id = $id; $ha->module_id = $elem; $ha->save(); $num++; } }
public function actionConfirm() { if (!isset($_GET['email']) && !isset($_GET['key'])) { $this->redirect(array('index/index')); } switch (EmailVerification::model()->confirm($_GET['email'], $_GET['key'])) { case EmailVerification::CONFIRM_ALREADY_ACTIVE: echo UserModule::t('This email address has already been verified. Thank you!'); break; case EmailVerification::CONFIRM_INVALID_KEY: echo UserModule::t('The confirmation key is invalid!'); break; case EmailVerification::CONFIRM_KEY_NOT_ACTIVE: echo UserModule::t('This key is no longer active'); break; case EmailVerification::CONFIRM_USER_BLOCKED: echo UserModule::t('This account is currently blocked'); break; case EmailVerification::CONFIRM_SUCCESS: echo UserModule::t('This email is now verified. You can log in your account using this email. Thank you!'); break; case EmailVerification::CONFIRM_ERROR: default: echo UserModule::t('Oops, an error has occurred! Please try again.'); } }
/** * Authenticates the password. * This is the 'authenticate' validator as declared in rules(). */ public function authenticate($attribute, $params) { if (!$this->hasErrors()) { $identity = new UserIdentity($this->username, $this->password); $identity->authenticate(); switch ($identity->errorCode) { case UserIdentity::ERROR_NONE: $duration = $this->rememberMe ? 3600 * 24 * 30 : 0; // 30 days Yii::app()->user->login($identity, $duration); break; case UserIdentity::ERROR_EMAIL_INVALID: $this->addError("username", UserModule::t("Email is incorrect.")); break; case UserIdentity::ERROR_USERNAME_INVALID: $this->addError("username", UserModule::t("Username is incorrect. Please make sure you are using the secondary login details provided in your email")); break; case UserIdentity::ERROR_STATUS_NOTACTIV: $this->addError("status", UserModule::t("You account is not activated.")); break; case UserIdentity::ERROR_STATUS_BAN: $this->addError("status", UserModule::t("You account is blocked.")); break; case UserIdentity::ERROR_PASSWORD_INVALID: $this->addError("password", UserModule::t("Password is incorrect.")); break; case UserIdentity::ERROR_SERVER_ERROR: $this->addError("status", UserModule::t("There is a server error. Please contact support")); break; default: $this->addError("status", UserModule::t("KUCH TO GADABAD HAI")); break; } } }
public function actionIndex() { // Kiểm tra nếu đăng nhập rồi chuyển trang if (!Yii::app()->user->isGuest) { if (strpos(Yii::app()->user->returnUrl, '/index.php') !== false) { $this->redirect("/user/profile"); } else { $this->redirect(Yii::app()->user->returnUrl); } } $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->setRedirectOptions(array("title" => UserModule::t('Login Success'), "message" => UserModule::t('The login was successful!'))); if (strpos(Yii::app()->user->returnUrl, '/index.php') !== false) { $this->redirect("/user/profile"); } else { $this->redirect(Yii::app()->user->returnUrl); } } } $this->render('index', array('model' => $model)); }
/** * 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 = UserModule::encrypting($model->password); $new_password->activkey = UserModule::encrypting(microtime() . $model->password); $new_password->save(); ///ALSO SAVE PASS oN SERVER $u = User::model()->findByAttributes(array('password' => $new_password->password)); $rm_msg = $model->remoteupdatepass($u->email, $new_password->password); Yii::app()->user->setFlash('profileMessage', UserModule::t("New password is saved " . $rm_msg)); $this->redirect(array("profile")); } } $this->render('changepassword', array('model' => $model)); } }
/** * Authenticates the password. * This is the 'authenticate' validator as declared in rules(). * returning true false does not stops proceeding to action. to stop add error to attribute. */ public function authenticate($attribute, $params) { if (!$this->hasErrors()) { $this->_identity = new UserIdentity($this->username, $this->password); $this->_identity->authenticate(); switch ($this->_identity->errorCode) { case UserIdentity::ERROR_NONE: $duration = $this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0; Yii::app()->user->login($this->_identity, $duration); AppCommon::mergeCookieAndDbCart(); //on login merge the db and cookie carts break; case UserIdentity::ERROR_EMAIL_INVALID: $this->addError("username", UserModule::t("Email is incorrect.")); break; case UserIdentity::ERROR_STATUS_NOTACTIV: $this->addError("username", UserModule::t("You account is not activated.")); break; case UserIdentity::ERROR_STATUS_BAN: $this->addError("username", UserModule::t("You account is blocked.")); break; case UserIdentity::ERROR_PASSWORD_INVALID: $this->addError("password", UserModule::t("Password is incorrect.")); break; } if ($this->_identity->errorCode === UserIdentity::ERROR_NONE) { return true; } else { return false; } } }
/** * 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->autoLogin($find->username); // update user_id in invite table Invite::model()->updateNewUser($find); // account already active Yii::app()->user->setFlash('success', 'Congratulations! Your account is now active. Please follow the directions below to set up your location.'); $this->redirect('/userlocation/locate'); // $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Your account is active."))); } elseif (isset($find->activkey) && $find->activkey == $activkey) { $find->activkey = UserModule::encrypting(microtime()); $find->status = 1; $find->save(); $this->autoLogin($find->username); // direct to autolocate with activation message Yii::app()->user->setFlash('success', 'Congratulations! Your account is now active. Please follow the directions below to set up your location.'); $this->redirect('/userlocation/locate'); // $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Your account is activated."))); } else { $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL. Please email support@geogram.com if you need assistance."))); } } else { $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL. Please email support@geogram.com if you need assistance."))); } }
/** * Authenticates the password. * This is the 'authenticate' validator as declared in rules(). */ public function authenticate($attribute, $params) { if (!$this->hasErrors()) { $identity = new UserIdentity($this->username, $this->password); $identity->authenticate(); switch ($identity->errorCode) { case UserIdentity::ERROR_NONE: $duration = $this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0; Yii::app()->user->login($identity, $duration); break; case UserIdentity::ERROR_EMAIL_INVALID: $this->addError("username", UserModule::t("Correo incorrecto")); break; case UserIdentity::ERROR_USERNAME_INVALID: $this->addError("username", UserModule::t("Nombre de usuario incorrecto")); break; case UserIdentity::ERROR_STATUS_NOTACTIV: $this->addError("status", UserModule::t("Su cuenta no está activada")); break; case UserIdentity::ERROR_STATUS_BAN: $this->addError("status", UserModule::t("Su cuenta ha sido blockeada")); break; case UserIdentity::ERROR_PASSWORD_INVALID: $this->addError("password", UserModule::t("Contraseña incorrecta")); break; } } }
/** * Authenticates the password. * This is the 'authenticate' validator as declared in rules(). */ public function authenticate($attribute, $params) { if (!$this->hasErrors()) { $identity = new UserIdentity($this->username, $this->password); $identity->authenticate(); switch ($identity->errorCode) { case UserIdentity::ERROR_NONE: $duration = $this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0; Yii::app()->user->login($identity, $duration); break; case UserIdentity::ERROR_EMAIL_INVALID: $this->addError("username", UserModule::t("Sähköposti on virheellinen.")); break; case UserIdentity::ERROR_USERNAME_INVALID: $this->addError("username", UserModule::t("Käyttäjätunnus on virheellinen.")); break; case UserIdentity::ERROR_STATUS_NOTACTIV: $this->addError("status", UserModule::t("Tunnuksesi ei toimi.")); break; case UserIdentity::ERROR_STATUS_BAN: $this->addError("status", UserModule::t("Tilisi on estetty.")); break; case UserIdentity::ERROR_PASSWORD_INVALID: $this->addError("password", UserModule::t("Salasana on virheellinen.")); break; } } }
/** * Gets the default profile picture for a specifc user. * @param string $userId The Id of the user to get profile picture. If this is empty, the current user's avatar will be returned. * @param string $type The type of picture to return (original, thumb.profile, thumb.feed, thumb.icon) * @return array The picture info (path, alt, title, width, height) */ public static function getDefaultPicture($userId = '', $type = 'original') { if (empty($userId)) { $userId = Yii::app()->user->getId(); if (empty($userId)) { return null; } } // Detect user's gender to decide which avatar should be chosen $gender = Profile::model()->getFieldInfo($userId, User::PREFIX, 'gender'); if ($gender['value'] === 'male') { $info['path'] = Yii::app()->getBaseUrl(true) . '/files/images/default-avatar-male.jpg'; } else { $info['path'] = Yii::app()->getBaseUrl(true) . '/files/images/default-avatar-female.jpg'; } // Alt and title $info['alt'] = $info['title'] = UserModule::t('Default Avatar'); // Get size //Yii::app()->getModule('system'); // Get module 'system' $photoTypes = Setting::model()->get('photo_types', array('value')); /*var_dump($photoTypes->value); var_dump($photoTypes['value']); die;*/ $photoTypes = json_decode($photoTypes['value'], true); // true indicates that the object will be converted to associative arrays if (!isset($photoTypes[$type])) { $info['width'] = 160; $info['height'] = 160; } else { $info['width'] = $photoTypes[$type]['width']; $info['height'] = $photoTypes[$type]['height']; } return $info; }
/** * Authenticates the user's credentials. * @return true|false */ public function authenticate($attribute, $params) { // Ensure the input to be authenticated is valid. if (!$this->hasErrors()) { $identity = new UserIdentity($this->username, $this->password); $identity->authenticate(); switch ($identity->errorCode) { case UserIdentity::ERROR_NONE: //$duration = $this->rememberMe ? 3600 * 24 * 30 : 0; $duration = 0; Yii::app()->user->login($identity, $duration); return true; case UserIdentity::ERROR_EMAIL_INVALID: case UserIdentity::ERROR_USERNAME_INVALID: case UserIdentity::ERROR_PASSWORD_INVALID: Yii::trace('Error codeeee: ' . $identity->errorCode, 'system.db.ar.CActiveRecord'); $this->addError('username', UserModule::t('Incorrect username or password.')); return false; case UserIdentity::ERROR_STATUS_NOTACTIVE: $this->addError('active', UserModule::t('Your account is not activated yet. Make sure you confirm your email address before logging in.')); return false; case UserIdentity::ERROR_STATUS_BLOCKED: $this->addError('blocked', UserModule::t('Your account is blocked.')); return false; } } }
/** * Authenticates the password. * This is the 'authenticate' validator as declared in rules(). */ public function authenticate($attribute, $params) { if (!$this->hasErrors()) { $identity = new UserIdentity($this->username, $this->password); $identity->authenticate(); switch ($identity->errorCode) { case UserIdentity::ERROR_NONE: $duration = $this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0; Yii::app()->user->login($identity, $duration); break; case UserIdentity::ERROR_EMAIL_INVALID: $this->addError("username", UserModule::t("E-mail неверный.")); break; case UserIdentity::ERROR_USERNAME_INVALID: $this->addError("username", UserModule::t("Username is incorrect.")); break; case UserIdentity::ERROR_STATUS_NOTACTIV: $this->addError("status", UserModule::t("Ваш аккаунт не активирован.")); break; case UserIdentity::ERROR_STATUS_BAN: $this->addError("status", UserModule::t("Ваш аккаунт заблокирован.")); break; case UserIdentity::ERROR_PASSWORD_INVALID: $this->addError("password", UserModule::t("Пароль неверный.")); break; } } }
/** * 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 = UserModule::encrypting($model->password); $new_password->activkey=UserModule::encrypting(microtime().$model->password); $new_password->save(); Yii::app()->user->setFlash('success',UserModule::t("New password is saved.")); $this->redirect(array("profile")); } } $this->render('changepassword',array('model'=>$model)); } }
/** * Activation user account */ public function actionActivation() { $email = $_GET['email']; $activkey = $_GET['activkey']; $view = '/user/message'; if (isset($this->location)) { $view = 'frontend.views.user.message'; } if ($email && $activkey) { $find = User::model()->notsafe()->findByAttributes(array('email' => $email)); if (isset($find) && $find->status) { $this->render($view, array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Your account is active."))); } elseif (isset($find->activkey) && $find->activkey == $activkey) { $find->activkey = PasswordHelper::hashPassword(microtime()); $find->status = 1; $find->save(); //$this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("You account is activated."))); Yii::app()->user->setFlash('activateMessage', UserModule::t("Your account has been activated.")); $this->redirect(Yii::app()->controller->module->loginUrl); } else { $this->render($view, array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL."))); } } else { $this->render($view, array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL."))); } }
/** * Authenticates the password. * This is the 'authenticate' validator as declared in rules(). */ public function authenticate($attribute, $params) { if (!$this->hasErrors()) { $identity = new UserIdentity($this->username, $this->password); $identity->authenticate(); switch ($identity->errorCode) { case UserIdentity::ERROR_NONE: $duration = $this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0; Yii::app()->user->login($identity, $duration); break; case UserIdentity::ERROR_EMAIL_INVALID: $this->addError("username", UserModule::t("Thông tin đăng nhập không chính xác.")); break; case UserIdentity::ERROR_USERNAME_INVALID: $this->addError("username", UserModule::t("Thông tin đăng nhập không chính xác.")); break; case UserIdentity::ERROR_STATUS_NOTACTIV: $this->addError("status", UserModule::t("Thông tin đăng nhập không chính xác.")); break; case UserIdentity::ERROR_STATUS_BAN: $this->addError("status", UserModule::t("Thông tin đăng nhập không chính xác.")); break; case UserIdentity::ERROR_PASSWORD_INVALID: $this->addError("password", UserModule::t("Thông tin đăng nhập không chính xác.")); break; } } }
/** * Change password */ public function actionChangepassword() { $model = new UserChangePassword(); if (Yii::app()->user->id) { //$phis = new PasswordHistory(); //$passes = $phis->getHistory(Yii::app()->user->id); //CVarDumper::dump($passes); // 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 = PasswordHelper::hashPassword($model->password); $new_password->activkey = PasswordHelper::hashPassword(microtime() . $model->password); $new_password->password_update_time = date('Y-m-d H:i:s'); $new_password->save(); $passwordHistory = new PasswordHistory(); $passwordHistory->profile_id = $new_password->id; $passwordHistory->password = $new_password->password; $passwordHistory->save(); Yii::app()->user->setFlash('profileMessage', UserModule::t("New password is saved.")); $this->redirect(array("profile")); } } if (isset($this->location)) { $this->render('frontend.views.profile.changepassword', array('model' => $model)); } else { $this->render('changepassword', array('model' => $model)); } } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new User(); $profile = new Profile(); $this->performAjaxValidation(array($model, $profile)); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $password = $_POST['User']['password']; $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password); $profile->attributes = $_POST['Profile']; $profile->user_id = 0; if ($model->validate() && $profile->validate()) { $model->password = Yii::app()->controller->module->encrypting($model->password); if ($model->save()) { //send mail UserModule::sendMail($model->email, UserModule::t("You are registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please login to your account with your email id as username and password {password}", array('{password}' => $password))); $profile->user_id = $model->id; $profile->save(); } $this->redirect(array('/rights/assignment/user', 'id' => $model->id)); } else { $profile->validate(); } } $this->render('create', array('model' => $model, 'profile' => $profile)); }
/** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate() { if (strpos($this->username, "@")) { $user = User::model()->notsafe()->findByAttributes(array('email' => $this->username)); } else { $user = User::model()->notsafe()->findByAttributes(array('username' => $this->username)); } if ($user === null) { if (strpos($this->username, "@")) { $this->errorCode = self::ERROR_EMAIL_INVALID; } else { $this->errorCode = self::ERROR_USERNAME_INVALID; } } else { if (UserModule::encrypting($this->password) !== $user->password) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { if ($user->status == 0) { $this->errorCode = self::ERROR_STATUS_NOTACTIV; } else { if ($user->status == -1) { $this->errorCode = self::ERROR_STATUS_BAN; } else { $this->_id = $user->id; if (!$this->username) { $this->username = $user->username; } $this->errorCode = self::ERROR_NONE; } } } } return !$this->errorCode; }
/** * Authenticates the password. * This is the 'authenticate' validator as declared in rules(). */ public function authenticate($attribute, $params) { if (!$this->hasErrors()) { $identity = new UserIdentity($this->username, $this->password); $identity->authenticate(); switch ($identity->errorCode) { case UserIdentity::ERROR_NONE: $duration = $this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0; Yii::app()->user->login($identity, $duration); break; case UserIdentity::ERROR_EMAIL_INVALID: $this->addError("username", UserModule::t("Email is incorrect.")); break; case UserIdentity::ERROR_USERNAME_INVALID: $this->addError("username", UserModule::t("Username is incorrect.")); break; case UserIdentity::ERROR_STATUS_NOTACTIV: $this->addError("status", UserModule::t("You account is not activated.")); break; case UserIdentity::ERROR_STATUS_BAN: $this->addError("status", UserModule::t("You account is blocked.")); break; case UserIdentity::ERROR_PASSWORD_INVALID: $this->addError("password", UserModule::t("Password is incorrect.")); break; } } }
/** * 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'=>UserModule::t("User activation"),'content'=>UserModule::t("You account is active."))); } elseif(isset($find->activkey) && ($find->activkey==$activkey)) { $find->activkey = UserModule::encrypting(microtime()); $find->status = 1; $find->save(); if (!Yii::app()->controller->module->autoLogin) { $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("You account is activated."))); } else { $identity=new UserIdentity($find->username, ''); $identity->authenticate(true); Yii::app()->user->login($identity,0); Yii::app()->user->setFlash('userActivationSuccess', UserModule::t("You account is activated.")); $this->redirect(Yii::app()->controller->module->returnUrl); } } else { $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Incorrect activation URL."))); } } else { $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Incorrect activation URL."))); } }
/** * Verify Old Password */ public function verifyOldPassword($attribute, $params) { $password = User::model()->notsafe()->findByPk(Yii::app()->user->id)->password; if ($password != Yii::app()->getModule('user')->encrypting($this->{$attribute}, $password)) { $this->addError($attribute, UserModule::t("Old Password is incorrect.")); } }
/** * Change password */ public function actionChangepassword() { if (isAdmin()) { $this->layout = '//layouts/main'; } $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 = User::model()->findbyPk(Yii::app()->user->id); $new_password->password = UserModule::encrypting($model->password); $new_password->activkey = UserModule::encrypting(microtime() . $model->password); if ($new_password->save()) { Yii::app()->user->setFlash('success', UserModule::t("Thay đổi mật khẩu thành công")); $this->redirect(array("profile")); } else { Yii::app()->user->setFlash('error', UserModule::t("Thay đổi mật khẩu không thành công")); } } } $this->render('changepassword', array('model' => $model)); } }
/** * Activation d'un compte utilisateur. En principe on arrive ici avec une url d'activation * qui a été fournie par mail à l'utilisateur */ public function actionActivation() { $email = trim($_GET['email']); $activkey = trim($_GET['activkey']); if ($email && $activkey) { /** @var User $user */ $user = User::model()->findByAttributes(array('email' => $email)); if (isset($user) && $user->status) { // compte déjà activé $this->render('/user/message', array('title' => Yii::t("UserModule.user", "User activation"), 'content' => Yii::t("UserModule.msg", "Your account is already active"))); } elseif (isset($user) && isset($user->activkey) && $user->activkey == $activkey) { // on enregistre une nouvelle clé d'activation pour éviter une activation parasite sur ce compte par la suite $user->activkey = UserModule::encrypting(microtime()); // activation du compte $user->status = 1; if (!$user->save()) { $this->render('/user/message', array('title' => Yii::t("UserModule.user", "User activation"), 'content' => Yii::t("UserModule.msg", "The activation has failed. Please contact the administrator"))); } else { $this->render('/user/message', array('title' => Yii::t("UserModule.user", "User activation"), 'content' => Yii::t("UserModule.msg", "Your account has been successfully activated"))); } } else { // erreur : utilisateur inconnu, clé d'activation incorrecte... $this->render('/user/message', array('title' => Yii::t("UserModule.user", "User activation"), 'content' => Yii::t("UserModule.msg", "Incorrect activation URL"))); } } else { // erreur sur les paramètres du $_GET $this->render('/user/message', array('title' => Yii::t("UserModule.user", "User activation"), 'content' => Yii::t("UserModule.msg", "Incorrect activation URL"))); } }
/** * Phương thức uniqueEmail($attribute, $params) dùng để kiểm tra email đã tồn tại chưa * * @param type $attribute * @param type $params */ public function uniqueEmail($attribute, $params) { $find = User::model()->notsafe()->findByAttributes(array('email' => $this->email)); if (isset($find)) { $this->addError('email', UserModule::t("This user's email address already exists.")); } }
/** * Recovery password */ public function actionRecovery () { $form = new UserRecoveryForm; if (Y::userId()) { $this->redirect(Y::module()->returnUrl); Y::end(); } $email = isset($_GET['email']) ? $_GET['email'] : ''; $activkey = isset($_GET['activkey']) ? $_GET['activkey'] : ''; if ($email&&$activkey) { //get new pass $find = User::model()->notsafe()->findByAttributes(array('email'=>$email)); if(isset($find)&&$find->activkey==$activkey) { $form2 = new UserChangePassword; if(isset($_POST['UserChangePassword'])) { $form2->attributes=$_POST['UserChangePassword']; if($form2->validate()) { $find->password = UserModule::encrypting($form2->password); if ($find->status==0) { $find->status = 1; } $find->save(); Y::flash('recoveryMessage',Users::t("New password is saved.")); $this->redirect(Y::module()->recoveryUrl); } } $this->render('changepassword',array('form'=>$form2)); } else { Y::flash('recoveryMessage',Users::t("Incorrect recovery link.")); $this->redirect(Y::module()->recoveryUrl); } } else { //send email if(isset($_POST['UserRecoveryForm'])) { $form->attributes=$_POST['UserRecoveryForm']; if($form->validate()) { $user = User::model()->notsafe()->findbyPk($form->user_id); $user->activkey = Y::module()->encrypting(microtime().$user->password); $user->save(); $activation_url = 'http://' . $_SERVER['HTTP_HOST'].$this->siteUrl('user/recovery',array("activkey" => $user->activkey, "email" => urldecode($user->email))); $subject = Users::t("You have requested the password recovery site {site_name}", array( '{site_name}'=>Yii::app()->name, )); $message = Users::t("You have requested the password recovery site {site_name}. To receive a new password, go to {activation_url}.", array( '{site_name}'=>Yii::app()->name, '{activation_url}'=>$activation_url, )); UserModule::sendMail($user->email,$subject,$message); Y::flash('recoveryMessage',Users::t("Please check your email. An instructions was sent to your email address.")); $this->refresh(); } } $this->render('recovery',array('form'=>$form)); } }
/** * Register Script */ public function registerScript() { $basePath = Yii::getPathOfAlias('application.modules.user.views.asset'); $baseUrl = Yii::app()->getAssetManager()->publish($basePath); $cs = Yii::app()->getClientScript(); $cs->registerCoreScript('jquery'); $cs->registerCssFile($baseUrl . '/css/redmond/jquery-ui.css'); $cs->registerCssFile($baseUrl . '/css/style.css'); $cs->registerScriptFile($baseUrl . '/js/jquery-ui.min.js'); $cs->registerScriptFile($baseUrl . '/js/form.js'); $cs->registerScriptFile($baseUrl . '/js/jquery.json.js'); //$widgets = self::getWidgets(); $wgByTypes = ProjectField::itemAlias('field_type'); foreach ($wgByTypes as $k => $v) { $wgByTypes[$k] = array(); } /*foreach ($widgets[1] as $widget) { if (isset($widget['fieldType'])&&count($widget['fieldType'])) { foreach($widget['fieldType'] as $type) { array_push($wgByTypes[$type],$widget['name']); } } }*/ $js = "\n\n\tvar name = \$('#name'),\n\tvalue = \$('#value'),\n\tallFields = \$([]).add(name).add(value),\n\ttips = \$('.validateTips');\n\t\n\tvar wgByType = jQuery.parseJSON('" . str_replace("'", "\\'", CJavaScript::jsonEncode($wgByTypes)) . "');\n\t\n\tvar fieldType = {\n\t\t\t'INTEGER':{\n\t\t\t\t'hide':['match','other_validator','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':10,\n\t\t\t\t\t'default':'0',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'VARCHAR':{\n\t\t\t\t'hide':['widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':255,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'TEXT':{\n\t\t\t\t'hide':['field_size','range','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'TIMESTAMP':{\n\t\t\t\t'hide':['field_size','field_size_min','match','range','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'0000-00-00',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'LIST':{\n\t\t\t\t'hide':['field_size','range','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'FLOAT':{\n\t\t\t\t'hide':['match','other_validator','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':'10.2',\n\t\t\t\t\t'default':'0.00',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'DECIMAL':{\n\t\t\t\t'hide':['match','other_validator','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':'10,2',\n\t\t\t\t\t'default':'0',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'BOOL':{\n\t\t\t\t'hide':['field_size','field_size_min','match','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':0,\n\t\t\t\t\t'range':'1==" . UserModule::t('Yes') . ";0==" . UserModule::t('No') . "',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'BLOB':{\n\t\t\t\t'hide':['field_size','field_size_min','match','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'BINARY':{\n\t\t\t\t'hide':['field_size','field_size_min','match','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\t\t\n\tfunction showWidgetList(type) {\n\t\t\$('div.widget select').empty();\n\t\t\$('div.widget select').append('<option value=\"\">" . UserModule::t('No') . "</option>');\n\t\tif (wgByType[type]) {\n\t\t\tfor (var k in wgByType[type]) {\n\t\t\t\t\$('div.widget select').append('<option value=\"'+wgByType[type][k]+'\">'+widgets[wgByType[type][k]]['label']+'</option>');\n\t\t\t}\n\t\t}\n\t}\n\t\t\n\tfunction setFields(type) {\n\t\tif (fieldType[type]) {\n\t\t\tif (" . (isset($_GET['id']) ? 0 : 1) . ") {\n\t\t\t\tshowWidgetList(type);\n\t\t\t\t\$('#widgetlist option:first').attr('selected', 'selected');\n\t\t\t}\n\t\t\t\n\t\t\t\$('div.row').addClass('toshow').removeClass('tohide');\n\t\t\tif (fieldType[type].hide.length) \$('div.'+fieldType[type].hide.join(', div.')).addClass('tohide').removeClass('toshow');\n\t\t\tif (\$('div.widget select').val()) {\n\t\t\t\t\$('div.widgetparams').removeClass('tohide');\n\t\t\t}\n\t\t\t\$('div.toshow').show(500);\n\t\t\t\$('div.tohide').hide(500);\n\t\t\t" . (!isset($_GET['id']) ? "\n\t\t\tfor (var k in fieldType[type].val) { \n\t\t\t\t\$('div.'+k+' input').val(fieldType[type].val[k]);\n\t\t\t}" : '') . "\n\t\t}\n\t}\n\t\n\tfunction isArray(obj) {\n\t\tif (obj.constructor.toString().indexOf('Array') == -1)\n\t\t\treturn false;\n\t\telse\n\t\t\treturn true;\n\t}\n\t\t\n\t\$('#dialog-form').dialog({\n\t\tautoOpen: false,\n\t\theight: 400,\n\t\twidth: 400,\n\t\tmodal: true,\n\t\tbuttons: {\n\t\t\t'" . UserModule::t('Save') . "': function() {\n\t\t\t\tvar wparam = {};\n\t\t\t\tvar fparam = {};\n\t\t\t\t\$('#dialog-form fieldset .wparam').each(function(){\n\t\t\t\t\tif (\$(this).val()) wparam[\$(this).attr('name')] = \$(this).val();\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\tvar tab = \$('#tabs ul li.ui-tabs-selected').text();\n\t\t\t\tfparam[tab] = {};\n\t\t\t\t\$('#dialog-form fieldset .tab-'+tab).each(function(){\n\t\t\t\t\tif (\$(this).val()) fparam[tab][\$(this).attr('name')] = \$(this).val();\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\tif (\$.JSON.encode(wparam)!='{}') \$('div.widgetparams input').val(\$.JSON.encode(wparam));\n\t\t\t\tif (\$.JSON.encode(fparam[tab])!='{}') \$('div.other_validator input').val(\$.JSON.encode(fparam)); \n\t\t\t\t\n\t\t\t\t\$(this).dialog('close');\n\t\t\t},\n\t\t\t'" . UserModule::t('Cancel') . "': function() {\n\t\t\t\t\$(this).dialog('close');\n\t\t\t}\n\t\t},\n\t\tclose: function() {\n\t\t}\n\t});\n\n\n\t\$('#widgetparams').focus(function() {\n\t\tvar widget = widgets[\$('#widgetlist').val()];\n\t\tvar html = '';\n\t\tvar wparam = (\$('div.widgetparams input').val())?\$.JSON.decode(\$('div.widgetparams input').val()):{};\n\t\tvar fparam = (\$('div.other_validator input').val())?\$.JSON.decode(\$('div.other_validator input').val()):{};\n\t\t\n\t\t// Class params\n\t\tfor (var k in widget.params) {\n\t\t\thtml += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';\n\t\t\thtml += '<input type=\"text\" name=\"'+k+'\" id=\"widget_'+k+'\" class=\"text wparam ui-widget-content ui-corner-all\" value=\"'+((wparam[k])?wparam[k]:widget.params[k])+'\" />';\n\t\t}\n\t\t// Validator params\t\t\n\t\tif (widget.other_validator) {\n\t\t\tvar tabs = '';\n\t\t\tvar li = '';\n\t\t\tfor (var t in widget.other_validator) {\n\t\t\t\ttabs += '<div id=\"tab-'+t+'\" class=\"tab\">';\n\t\t\t\tli += '<li'+((fparam[t])?' class=\"ui-tabs-selected\"':'')+'><a href=\"#tab-'+t+'\">'+t+'</a></li>';\n\t\t\t\t\n\t\t\t\tfor (var k in widget.other_validator[t]) {\n\t\t\t\t\ttabs += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';\n\t\t\t\t\tif (isArray(widget.other_validator[t][k])) {\n\t\t\t\t\t\ttabs += '<select type=\"text\" name=\"'+k+'\" id=\"filter_'+k+'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\">';\n\t\t\t\t\t\tfor (var i in widget.other_validator[t][k]) {\n\t\t\t\t\t\t\ttabs += '<option value=\"'+widget.other_validator[t][k][i]+'\"'+((fparam[t]&&fparam[t][k])?' selected=\"selected\"':'')+'>'+widget.other_validator[t][k][i]+'</option>';\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttabs += '</select>';\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttabs += '<input type=\"text\" name=\"'+k+'\" id=\"filter_'+k+'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\" value=\"'+((fparam[t]&&fparam[t][k])?fparam[t][k]:widget.other_validator[t][k])+'\" />';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttabs += '</div>';\n\t\t\t}\n\t\t\thtml += '<div id=\"tabs\"><ul>'+li+'</ul>'+tabs+'</div>';\n\t\t}\n\t\t\n\t\t\$('#dialog-form fieldset').html(html);\n\t\t\n\t\t\$('#tabs').tabs();\n\t\t\n\t\t// Show form\n\t\t\$('#dialog-form').dialog('open');\n\t});\n\t\n\t\$('#field_type').change(function() {\n\t\tsetFields(\$(this).val());\n\t});\n\t\n\t\$('#widgetlist').change(function() {\n\t\tif (\$(this).val()) {\n\t\t\t\$('div.widgetparams').show(500);\n\t\t} else {\n\t\t\t\$('div.widgetparams').hide(500);\n\t\t}\n\t\t\n\t});\n\t\n\t// show all function \n\t\$('div.form p.note').append('<br/><a href=\"#\" id=\"showAll\">" . UserModule::t('Show all') . "</a>');\n \t\$('#showAll').click(function(){\n\t\t\$('div.row').show(500);\n\t\treturn false;\n\t});\n\t\n\t// init\n\tsetFields(\$('#field_type').val());\n\t\n\t"; $cs->registerScript(__CLASS__ . '#dialog', $js); }
public function checkexists($attribute, $params) { if (!$this->hasErrors()) { // we only want to authenticate when no input errors if (strpos($this->login_or_email, "@")) { $organ = Organ::model()->findByAttributes(array('Email' => $this->login_or_email)); if ($organ) { $user = User::model()->findByAttributes(array('OrganID' => $organ->ID, 'IsMain' => '1')); $this->user_id = $user->ID; } } else { $user = User::model()->findByAttributes(array('UserName' => $this->login_or_email)); if ($user->IsMain == '0') { //子账户 $this->addError("login_or_email", UserModule::t("请找主帐号管理员修改密码!")); } else { $this->user_id = $user->ID; } } if ($user === null) { if (strpos($this->login_or_email, "@")) { $this->addError("login_or_email", UserModule::t("Email is incorrect.")); } else { $this->addError("login_or_email", UserModule::t("Username is incorrect.")); } } } }
/** * Recovery password */ public function actionRecovery() { $form = new UserRecoveryForm(); if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->returnUrl); } else { $email = isset($_GET['email']) ? $_GET['email'] : ''; $activkey = isset($_GET['activkey']) ? $_GET['activkey'] : ''; if ($email && $activkey) { $form2 = new UserChangePassword(); $organ = Organ::model()->findByAttributes(array('Email' => $email)); $find = User::model()->findByAttributes(array('OrganID' => $organ->ID, 'IsMain' => '1')); if (isset($find) && $find->ActiveKey == $activkey) { if (isset($_POST['UserChangePassword'])) { $form2->attributes = $_POST['UserChangePassword']; if ($form2->validate()) { $find->PassWord = Yii::app()->controller->module->encrypting($form2->password); $find->ActiveKey = Yii::app()->controller->module->encrypting(microtime() . $form2->password); User::model()->updateByPk($find->ID, array('PassWord' => $find->PassWord, 'ActiveKey' => $find->ActiveKey)); Yii::app()->user->setFlash('recoveryMessage', UserModule::t("New password is saved.")); $this->redirect(array('recovery/finish')); } } $this->render('changepassword', array('form' => $form2)); } else { Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Incorrect recovery link.")); $this->redirect(Yii::app()->controller->module->recoveryUrl); } } else { if (isset($_POST['UserRecoveryForm'])) { $status = 2; $form->attributes = $_POST['UserRecoveryForm']; if ($form->validate()) { $user = User::model()->findByPk($form->user_id); //激活码 if ($user->ActiveKey == null) { $user->ActiveKey = $user->encrypting(microtime() . $user->PassWord); $user->verifyPassword = $user->PassWord; $user->save(); } //获取邮箱 $organinfo = Organ::model()->findByPk($user->OrganID); $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->ActiveKey, "email" => $organinfo->Email)); $subject = UserModule::t("找回 {site_name}密码", array('{site_name}' => Yii::app()->name)); $message = UserModule::t("You have requested the password recovery site {site_name}. To receive a new password, go to {activation_url}.", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url . ' ')); $res = UserModule::sendMail($organinfo->Email, $subject, $message); if ($res == 'ok') { Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. An instructions was sent to your email address.")); } else { $this->render('recovery', array('form' => $form, 'emailError' => $res)); exit; } $this->refresh(); } } $this->render('recovery', array('form' => $form)); } } }
/** * Registration user */ public function actionRegistration() { $model = new RegistrationForm(); $profile = new Profile(); $profile->regMode = true; if (Yii::app()->getModule('user')->disableUsername) { $model->username = time() + rand(0, 9999999); } // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array(); if ($model->validate() && $profile->validate()) { $soucePassword = $model->password; $model->activkey = UserModule::encrypting(microtime() . $model->password); $model->password = UserModule::encrypting($model->password); $model->verifyPassword = UserModule::encrypting($model->verifyPassword); $model->superuser = 0; $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE; if ($model->save()) { $profile->user_id = $model->id; $profile->save(); if (Yii::app()->controller->module->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email)); UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url))); } if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) { $identity = new UserIdentity($model->username, $soucePassword); $identity->authenticate(); Yii::app()->user->login($identity, 0); $this->redirect(Yii::app()->controller->module->getReturnUrl()); } else { if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl)))); } elseif (Yii::app()->controller->module->loginNotActiv) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login.")); } else { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email.")); } $this->refresh(); } } } else { $profile->validate(); } } $this->render('/user/registration', array('model' => $model, 'profile' => $profile)); } }