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