1 <?php
2
3 class RecoveryController extends Controller
4 {
5 public $defaultAction = 'recovery';
6
7 8 9
10 public function actionRecovery () {
11 $form = new UserRecoveryForm;
12 if (Yii::app()->user->id) {
13 $this->redirect(Yii::app()->controller->module->returnUrl);
14 } else {
15 $email = ((isset($_GET['email']))?$_GET['email']:'');
16 $activkey = ((isset($_GET['activkey']))?$_GET['activkey']:'');
17 if ($email&&$activkey) {
18 $form2 = new UserChangePassword;
19 $find = User::model()->notsafe()->findByAttributes(array('email'=>$email));
20 if(isset($find)&&$find->activkey==$activkey) {
21 if(isset($_POST['UserChangePassword'])) {
22 $form2->attributes=$_POST['UserChangePassword'];
23 if($form2->validate()) {
24 $find->password = Yii::app()->controller->module->encrypting($form2->password);
25 $find->activkey=Yii::app()->controller->module->encrypting(microtime().$form2->password);
26 if ($find->status==0) {
27 $find->status = 1;
28 }
29 $find->save();
30 Yii::app()->user->setFlash('recoveryMessage',UserModule::t("New password is saved."));
31 $this->redirect(Yii::app()->controller->module->recoveryUrl);
32 }
33 }
34 $this->render('changepassword',array('form'=>$form2));
35 } else {
36 Yii::app()->user->setFlash('recoveryMessage',UserModule::t("Incorrect recovery link."));
37 $this->redirect(Yii::app()->controller->module->recoveryUrl);
38 }
39 } else {
40 if(isset($_POST['UserRecoveryForm'])) {
41 $form->attributes=$_POST['UserRecoveryForm'];
42 if($form->validate()) {
43 $user = User::model()->notsafe()->findbyPk($form->user_id);
44 $activation_url = 'http://' . $_SERVER['HTTP_HOST'].$this->createUrl(implode(Yii::app()->controller->module->recoveryUrl),array("activkey" => $user->activkey, "email" => $user->email));
45
46 $subject = UserModule::t("You have requested the password recovery site {site_name}",
47 array(
48 '{site_name}'=>Yii::app()->name,
49 ));
50 $message = UserModule::t("You have requested the password recovery site {site_name}. To receive a new password, go to {activation_url}.",
51 array(
52 '{site_name}'=>Yii::app()->name,
53 '{activation_url}'=>$activation_url,
54 ));
55
56 UserModule::sendMail($user->email,$subject,$message);
57
58 Yii::app()->user->setFlash('recoveryMessage',UserModule::t("Please check your email. An instructions was sent to your email address."));
59 $this->refresh();
60 }
61 }
62 $this->render('recovery',array('form'=>$form));
63 }
64 }
65 }
66
67 }