UserRecoveryForm is the data structure for keeping user recovery form data. It is used by the 'recovery' action of 'UserController'.
Inheritance: extends CFormModel
	/**
	 * 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));
    	}
	}
Beispiel #2
0
 /**
  * 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));
         }
     }
 }
	/**
	 * 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;
		    		$find = User::model()->notsafe()->findByAttributes(array('email'=>$email));
		    		if(isset($find)&&$find->activkey==$activkey) {
			    		if(isset($_POST['UserChangePassword'])) {
							$form2->attributes=$_POST['UserChangePassword'];
							if($form2->validate()) {
								$find->password = Yii::app()->controller->module->encrypting($form2->password);
								$find->activkey=Yii::app()->controller->module->encrypting(microtime().$form2->password);
								if ($find->status==0) {
									$find->status = 1;
								}
								$find->save();
								Yii::app()->user->setFlash('success',UserModule::t("New password is saved."));
								$this->redirect(Yii::app()->controller->module->recoveryUrl);
							}
						} 
						$this->render('changepassword',array('model'=>$form2));
		    		} else {
		    			Yii::app()->user->setFlash('error',UserModule::t("Incorrect recovery link."));
						$this->redirect(Yii::app()->controller->module->recoveryUrl);
		    		}
		    	} else {
			    	if(isset($_POST['UserRecoveryForm'])) {
			    		$form->attributes=$_POST['UserRecoveryForm'];
			    		if($form->validate()) {
			    			$user = User::model()->notsafe()->findbyPk($form->user_id);
							$activation_url = 'http://' . $_SERVER['HTTP_HOST'].$this->createUrl(implode(Yii::app()->controller->module->recoveryUrl),array("activkey" => $user->activkey, "email" => $user->email));
							
							$subject = UserModule::t("You have requested a password recovery of {site_name}",
			    					array(
			    						'{site_name}'=>Yii::app()->name,
			    					));
			    			$message = UserModule::t("You have requested our password recovery services. To receive a new password, go to {activation_url}. Sincerely, Team of {site_name}",
			    					array(
			    						'{site_name}'=>Yii::app()->name,
			    						'{activation_url}'=>$activation_url,
			    					));
							
			    			UserModule::sendMail($user->email,$subject,$message);
			    			
							Yii::app()->user->setFlash('info',UserModule::t("Please check your email. Further instructions are sent to your email address."));
			    			$this->refresh();
			    		}
			    	}
		    		$this->render('recovery',array('model'=>$form));
		    	}
		    }
	}
 /**
  * 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();
             $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
             if (isset($find) && $find->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->password = Yii::app()->controller->module->encrypting($form2->password);
                         $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->status == 0) {
                             $find->status = 1;
                         }
                         $find->save();
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("New password is saved."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $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'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->notsafe()->findbyPk($form->user_id);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     $subject = UserModule::t("Bạn đã có yêu cầu phục hồi mật khẩu từ {site_name}", array('{site_name}' => Yii::app()->name));
                     $message = UserModule::t("Bạn đã có yêu cầu phục hồi mật khẩu từ {site_name}. Để nhận được mật khẩu mới bạn hãy vào link sau: {activation_url}.", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                     if (Yii::app()->request->isAjaxRequest) {
                         jsonOut(array('error' => false, 'msg' => 'Xin vui lòng kiểm tra email. Một hướng dẫn đã chuyển đến email của bạn.'), false);
                     }
                     UserModule::sendMail($user->email, $subject, $message);
                     Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. An instructions was sent to your email address."));
                     $this->refresh();
                 } else {
                     if (Yii::app()->request->isAjaxRequest) {
                         jsonOut(array('error' => true, 'msg' => CActiveForm::validate($form)));
                     }
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     Yii::app()->theme = 'client';
     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();
             $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
             if (isset($find) && $find->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->password = Yii::app()->controller->module->encrypting($form2->password);
                         $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->status == 0) {
                             $find->status = 1;
                         }
                         $find->save();
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("New password is saved."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $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'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->notsafe()->findbyPk($form->user_id);
                     $user->activkey = UserModule::encrypting(microtime() . $user->password);
                     $user->save();
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     echo '<br>' . $activation_url;
                     echo '<br>' . Yii::app()->controller->module->recoveryUrl;
                     $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl));
                     $subject = UserModule::t("You have requested the password recovery site {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 <a href=\"{activation_url}\">{activation_url}</a>.", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                     UserModule::sendMail($user->email, $subject, $message);
                     Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. An instructions was sent to your email address."));
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }
 /**
  * Восстановление пароля
  */
 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();
             $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
             if (isset($find) && $find->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->password = Yii::app()->controller->module->encrypting($form2->password);
                         $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->status == 0) {
                             $find->status = 1;
                         }
                         $find->save();
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("New password is saved."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $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'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->notsafe()->findbyPk($form->user_id);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     $subject = Yii::t('admin', 'Request for password recovery');
                     $message = Yii::t('admin', 'To reset the password, use the link:') . ' ' . $activation_url;
                     $send = Email::sendUserNoReply($user->username, $user->email, $subject, $message);
                     if ($send) {
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. An instructions was sent to your email address."));
                     } else {
                         Yii::app()->user->setFlash('recoveryMessage', Yii::t('admin', 'Error sending email messages. Please try again or contact us'));
                     }
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('model' => $form));
         }
     }
 }
    /**
     * 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();
                $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
                if (isset($find) && $find->activkey == $activkey) {
                    if (isset($_POST['UserChangePassword'])) {
                        $form2->attributes = $_POST['UserChangePassword'];
                        if ($form2->validate()) {
                            $find->password = Yii::app()->controller->module->encrypting($form2->password);
                            $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                            if ($find->status == 0) {
                                $find->status = 1;
                            }
                            $find->save();
                            Yii::app()->user->setFlash('recoveryMessage', UserModule::t("New password is saved."));
                            $this->redirect(Yii::app()->controller->module->recoveryUrl);
                        }
                    }
                    $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'])) {
                    $form->attributes = $_POST['UserRecoveryForm'];
                    if ($form->validate()) {
                        $user = User::model()->notsafe()->findbyPk($form->user_id);
                        $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                        $subject = UserModule::t("You have requested the password recovery site {site_name}", array('{site_name}' => Yii::app()->name));
                        $message = UserModule::t('<p> You have requested to reset your {site_name}. password, No problem! Click the link below to create a new password </p> <a href="' . $activation_url . '">{activation_url}</a>.<br>							If you did not request to change your password, let us know and we’ll make sure everything is okay with your account. You can email us at support@instanttop.com <p>Kind regards,<br>
							Your' . Yii::app()->name . ' team </p>', array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                        UserModule::sendMail($user->email, $subject, $message);
                        Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. An instructions was sent to your email address."));
                        $this->refresh();
                    }
                }
                $this->render('recovery', array('form' => $form));
            }
        }
    }
 /**
  * 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();
             $find = AUserLogin::model()->scope_select_all()->findByAttributes(array('login_name' => $email));
             if (isset($find) && $find->userLogin2userDetails->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->pwd = Yii::app()->controller->module->encrypting($form2->password);
                         $find->userLogin2userDetails->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->userLogin2userDetails->is_active == 0) {
                             $find->userLogin2userDetails->is_active = 1;
                         }
                         $find->save();
                         $find->userLogin2userDetails->save();
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("New password is saved."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $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'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = AUserLogin::model()->scope_select_all()->findByAttributes(array('login_name' => $form->login_or_email));
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->userLogin2userDetails->activkey, "email" => $user->login_name));
                     $subject = UserModule::t("You have requested the password recovery for {site_name}", array('{site_name}' => Yii::app()->name));
                     $message = UserModule::t("Hi, \n You have requested the password recovery for {site_name}. To receive a new password, go to {activation_url}. \n Regards, \n tw.in team", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                     UserModule::sendMail($user->login_name, $subject, $message);
                     Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. Instructions has been sent to your email address."));
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }
Beispiel #9
0
 /**
  * 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();
             $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
             if (isset($find) && $find->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->password = Yii::app()->controller->module->encrypting($form2->password);
                         $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->status == 0) {
                             $find->status = 1;
                         }
                         $find->save();
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Новый пароль сохранен."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $this->render('changepassword', array('model' => $form2));
             } else {
                 Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Неверная ссылка."));
                 $this->redirect(Yii::app()->controller->module->recoveryUrl);
             }
         } else {
             if (isset($_POST['UserRecoveryForm'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->notsafe()->findbyPk($form->user_id);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     $subject = UserModule::t("Запрос на восстанвление пароля на сайте {site_name}", array('{site_name}' => Yii::app()->name));
                     $message = UserModule::t("Вы запросили восстановление пароля на сайте {site_name}. Для получения нового пароля, перейдите по ссылке <br> {activation_url}.", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                     UserModule::sendMail($user->email, $subject, $message);
                     Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Ссылка на восстановление пароля отправлена на вашу почту."));
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('model' => $form));
         }
     }
 }
Beispiel #10
0
 /**
  * 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();
             $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
             if (isset($find) && $find->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->password = Yii::app()->controller->module->encrypting($form2->password);
                         $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->status == 0) {
                             $find->status = 1;
                         }
                         $find->save();
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Salasana vaihdettu onnistuneesti."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $this->render('changepassword', array('form' => $form2));
             } else {
                 Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Linkki on vanhentunut."));
                 $this->redirect(Yii::app()->controller->module->recoveryUrl);
             }
         } else {
             if (isset($_POST['UserRecoveryForm'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->notsafe()->findbyPk($form->user_id);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     $subject = UserModule::t("Olet pyytänyt salasanan vaihtoa ohjelmasta {site_name} \r\n", array('{site_name}' => Yii::app()->name));
                     $message = UserModule::t("Olet pyytänyt salasanan vaihtoa ohjelmasta {site_name}. \r\nVaihda uusi salasana menemällä osoitteeseen \r\n{activation_url}", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                     UserModule::sendMail($user->email, $subject, $message);
                     Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Tarkista sähköpostisi. Sähköpostiisi on lähetetty linkki jonka avulla voit vaihtaa salasanasi."));
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }
 /**
  * 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();
             $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
             if (isset($find) && $find->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->password = Yii::app()->controller->module->encrypting($form2->password);
                         $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->status == 0) {
                             $find->status = 1;
                         }
                         $find->save();
                         Yii::app()->user->setFlash('success', "New password is saved.");
                         $this->redirect(Yii::app()->controller->module->loginUrl);
                     }
                 }
                 $this->render('/recovery/changepassword', array('form' => $form2));
             } else {
                 Yii::app()->user->setFlash('error', "Incorrect recovery link.");
                 $this->redirect(Yii::app()->controller->module->recoveryUrl);
             }
         } else {
             if (isset($_POST['UserRecoveryForm'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->notsafe()->findbyPk($form->user_id);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     $subject = UserModule::t("[{site_name}] Password Recovery", array('{site_name}' => Yii::app()->params['system_name']));
                     $message = UserModule::t("recovery password can be done by following the link: <br>\n\t\t\t\t\t\t\t\t\t\t  {activation_url}. <br><br><br>\n\t\t\t\t\t\t\t\t\t\t  Best regard {site_name} :)<br>" . date("M d-m-Y | H:i") . " WIB", array('{site_name}' => Yii::app()->params['system_name'], '{activation_url}' => $activation_url));
                     UserModule::sendMail($user->email, $subject, $message);
                     Yii::app()->user->setFlash('info', "Please check your email. An instructions was sent to your email address.");
                     $this->refresh();
                 }
             }
             $this->render('/recovery/recovery', array('form' => $form));
         }
     }
 }
Beispiel #12
0
 /**
  * Страница авторизации/регистрации
  */
 public function actionLogin()
 {
     $model = new UserLogin();
     $registration_form = new RegistrationForm();
     $user_recovery_form = new UserRecoveryForm();
     // if it is ajax validation request
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if (isset($_POST['UserLogin'])) {
         $model->attributes = $_POST['UserLogin'];
         if ($model->validate()) {
             //print_r($model->attributes);die;
             $this->lastViset();
             $this->redirect(array('my/index'));
         }
     }
     if (isset($_POST['RegistrationForm'])) {
         $registration_form->attributes = $_POST['RegistrationForm'];
         $registration_form->username = $registration_form->email;
         if ($registration_form->validate()) {
             $soucePassword = $registration_form->password;
             $registration_form->activkey = UserModule::encrypting(microtime() . $registration_form->password);
             $registration_form->password = UserModule::encrypting($registration_form->password);
             $registration_form->verifyPassword = UserModule::encrypting($registration_form->verifyPassword);
             $registration_form->superuser = 0;
             $registration_form->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
             if ($registration_form->save()) {
                 $activation_url = $this->createAbsoluteUrl('site/activation', array("activkey" => $registration_form->activkey, "email" => $registration_form->email));
                 //UserModule::sendMail($registration_form->email,UserModule::t("Вы зарегистрировались на сайте {site_name}",array('{site_name}'=>Yii::app()->name)),UserModule::t("Для активации вашего аккаунта, перейдите пожалуста по ссылке {activation_url}",array('{activation_url}'=>$activation_url)));
                 UserModule::sendMail($registration_form->email, UserModule::t("Вы зарегистрировались на сайте {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Здравствуйте. Благодарим Вас за регистрацию на сервисе сохранения закладок " . Yii::app()->name . ". Для активации аккаунта перейдите по ссылке.<br> {activation_url}", array('{activation_url}' => $activation_url)));
                 return $this->redirect(array('site/regsuccess'));
             }
         }
     }
     if (isset($_POST['UserRecoveryForm'])) {
         $user_recovery_form->attributes = $_POST['UserRecoveryForm'];
         if ($user_recovery_form->validate()) {
             $user = User::model()->notsafe()->findbyPk($user_recovery_form->user_id);
             //$activation_url = 'http://' . $_SERVER['HTTP_HOST'].$this->createUrl(implode(array("/user/recovery")),array("activkey" => $user->activkey, "email" => $user->email));
             $activation_url = $this->createAbsoluteUrl('site/recovery', array("activkey" => $user->activkey, "email" => $user->email));
             $subject = UserModule::t("Запрос на восстановление пароля на сайте {site_name}", array('{site_name}' => Yii::app()->name));
             $message = UserModule::t("Вы запросили восстановление пароля на сайте {site_name}. Для получения нового пароля, перейдите по ссылке <br> {activation_url}.", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
             UserModule::sendMail($user->email, $subject, $message);
             Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Ссылка на восстановление пароля<br>отправлена на вашу почту."));
             $this->refresh();
         }
     }
     $this->render('login', array('model' => $model, 'registration_form' => $registration_form, 'user_recovery_form' => $user_recovery_form));
 }
 /**
  * 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();
             $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
             if (isset($find) && $find->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->password = PasswordHelper::hashPassword($form2->password);
                         $find->activkey = PasswordHelper::hashPassword(microtime() . $form2->password);
                         $find->password_update_time = date('Y-m-d H:i:s');
                         if ($find->status == 0) {
                             $find->status = 1;
                         }
                         $find->save();
                         $passwordHistory = new PasswordHistory();
                         $passwordHistory->profile_id = $find->id;
                         $passwordHistory->password = $find->password;
                         $passwordHistory->save();
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Your password has been changed. Please login with your new password."));
                         $this->redirect(Yii::app()->controller->module->loginUrl);
                     }
                 }
                 if (isset($this->location)) {
                     $this->render('frontend.views.recovery.changepassword', array('form' => $form2));
                 } else {
                     $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'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->notsafe()->findbyPk($form->user_id);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     $subject = UserModule::t("You have requested password recovery for {site_name}", array('{site_name}' => Yii::app()->name));
                     $message = UserModule::t("You have requested password recovery for {site_name}. To change your password, click <a href='{$activation_url}'>here</a> or copy and paste this link into your browser: {$activation_url}", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                     UserModule::sendMail($user->email, $subject, $message);
                     //echo $message.'here';
                     Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email, the reset link was sent to your email address."));
                     $this->refresh();
                 }
             }
             if (isset($this->location)) {
                 $this->render('frontend.views.recovery.recovery', array('form' => $form));
             } else {
                 $this->render('recovery', array('form' => $form));
             }
         }
     }
 }
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->user->returnUrl);
     } else {
         if (isset($_POST['UserRecoveryForm'])) {
             $form->attributes = $_POST['UserRecoveryForm'];
             if ($form->validate()) {
                 $user = User::model()->findbyPk($form->user_id);
                 // generate new password and send email
                 $user->generatePassword();
                 //$subject = 'You have requested the password recovery site '.Yii::app()->name;
                 //$message = 'You have requested the password recovery site '.Yii::app()->name.
                 //    '. Your new password is: '.$user->password;
                 //UserModule::sendMail($user->email,$subject,$message);
                 Yii::app()->user->setFlash('recoveryMessage', 'Please check your email. Your new password was sent to your email address.');
                 $this->refresh();
             }
         }
         $this->render('recovery', array('form' => $form));
     }
 }
Beispiel #15
0
 /**
  * Recover password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     if (($uid = Yii::app()->user->id) === true) {
         $this->redirect(Yii::app()->user->returnUrl);
     } else {
         if (isset($_GET['email']) && isset($_GET['activkey'])) {
             $email = $_GET['email'];
             $activkey = $_GET['activkey'];
             $form2 = new UserChangePassword();
             $find = User::model()->findByAttributes(array('email' => $email));
             if ($find->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->password = Yii::app()->user->encrypt($form2->password);
                         $find->activkey = Yii::app()->user->encrypt(microtime() . $form2->password);
                         $find->save();
                         Yii::app()->user->setFlash('loginMessage', Yii::t("user", "Your new password has been saved."));
                         $this->redirect(array("user/login"));
                     }
                 }
                 $this->render('/user/changepassword', array('form' => $form2));
             } else {
                 Yii::app()->user->setFlash('recoveryMessage', Yii::t("user", "Incorrect recovery link."));
                 $this->redirect('http://' . $_SERVER['HTTP_HOST'] . $this->createUrl('user/recovery'));
             }
         } else {
             if (isset($_POST['UserRecoveryForm'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->findbyPk($form->user_id);
                     $headers = "From: " . Yii::app()->params['adminEmail'] . "\r\nReply-To: " . Yii::app()->params['adminEmail'];
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl('user/recovery', array("activkey" => $user->activkey, "email" => $user->email));
                     mail($user->email, "You have requested to be reset. To receive a new password, go to {$activation_url}.", $headers);
                     Yii::app()->user->setFlash('resetPwMessage', Yii::t("user", "Instructions have been sent to you. Please check your eMail."));
                     $this->refresh();
                 }
             }
             $this->render('/user/recovery', array('form' => $form));
         }
     }
 }
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     Yii::app()->theme = 'client';
     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();
             $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
             if (isset($find) && $find->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->password = Yii::app()->controller->module->encrypting($form2->password);
                         $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->status == 0) {
                             $find->status = 1;
                         }
                         $find->save();
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("New password is saved."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $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'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->notsafe()->findbyPk($form->user_id);
                     $user->activkey = UserModule::encrypting(microtime() . $user->password);
                     $user->save();
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     /*
                     						$this->createUrl(implode(Yii::app()->controller->module->recoveryUrl));
                     						$subject = UserModule::t("You have requested the password recovery site {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 <a href=\"{activation_url}\">{activation_url}</a>.",
                     		    					array(
                     		    						'{site_name}'=>Yii::app()->name,
                     		    						'{activation_url}'=>$activation_url,
                     		    					));
                     							
                     		    			UserModule::sendMail($user->email,$subject,$message);
                     */
                     // новая служба системных сообщений
                     $type_id = Emails::TYPE_10;
                     $email = new Emails();
                     /*$criteria = new CDbCriteria();
                     		$criteria->order = 'id DESC';
                     		$criteria->limit = 1;
                     		$user = User::model()->findAll($criteria);
                     		$user = $user[0];*/
                     $email->from_id = 1;
                     $email->to_id = $form->user_id;
                     //  = $user->id;
                     $rec = Templates::model()->findAll("`type_id`='{$type_id}'");
                     $id = Campaign::getId();
                     $email->campaign = Campaign::getName();
                     $email->name = $user->full_name;
                     $email->login = $user->username;
                     $email->password = $soucePassword;
                     $email->page_psw = $activation_url;
                     $email->page_cabinet = 'http://' . $_SERVER['SERVER_NAME'] . '/user/profile/edit';
                     $email->sendTo($user->email, $rec[0]->title, $rec[0]->text, $type_id);
                     Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. An instructions was sent to your email address."));
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }