Advertisement
Guest User

Untitled

a guest
Oct 5th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. <?php
  2.  
  3. class RecoveryController extends Controller
  4. {
  5.  
  6. public $defaultAction = 'recovery';
  7. public $layout = '//layouts/column4';
  8.  
  9. /**
  10. * Declares class-based actions.
  11. */
  12. public function actions()
  13. {
  14. // TODO
  15. return array(
  16. 'captcha' => array(
  17. 'class' => 'CCaptchaAction',
  18. 'backColor' => 0xFFFFFF,
  19. ),
  20. );
  21. }
  22.  
  23. /**
  24. * Recovery password
  25. */
  26. public function actionRecovery()
  27. {
  28. if (Yii::app()->user->id) {
  29. $this->redirect(Yii::app()->controller->module->returnUrl);
  30. } else {
  31. $email = isset($_GET['email']) ? $_GET['email'] : '';
  32. $activkey = isset($_GET['activkey']) ? $_GET['activkey'] : '';
  33. if ($email && $activkey) {
  34. $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
  35. if (isset($find) && $find->activkey == $activkey) {
  36. $model = new UserChangePassword();
  37. if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] === 'password-change-form') {
  38. echo CActiveForm::validate($model);
  39. Yii::app()->end();
  40. }
  41. if (isset($_POST['UserChangePassword'])) {
  42. $model->attributes = $_POST['UserChangePassword'];
  43. if ($model->validate()) {
  44. $find->password = Yii::app()->controller->module->encrypting($model->password);
  45. $find->activkey = Yii::app()->controller->module->encrypting(microtime().$model->password);
  46. if ($find->status == 0) {
  47. $find->status = 1;
  48. }
  49. $find->save();
  50. Yii::app()->user->setFlash(
  51. 'recoveryMessage',
  52. UserModule::t('<span class="label label-success">UPDATED</span> The new password is saved successfully.'));
  53. $this->redirect(Yii::app()->controller->module->recoveryUrl);
  54. }
  55. }
  56. $this->render('changepassword', array(
  57. 'model' => $model
  58. ));
  59. } else {
  60. Yii::app()->user->setFlash(
  61. 'recoveryErrorMessage',
  62. UserModule::t('<span class="label label-important">ERROR</span> Incorrect recovery link.'));
  63. $this->redirect(Yii::app()->controller->module->recoveryUrl);
  64. }
  65. } else {
  66. $model = new UserRecoveryForm();
  67. if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] === 'password-restore-form') {
  68. echo CActiveForm::validate($model);
  69. Yii::app()->end();
  70. }
  71. if (isset($_POST['UserRecoveryForm'])) {
  72. $model->attributes = $_POST['UserRecoveryForm'];
  73. if ($_POST['UserRecoveryForm']['login_or_email']) {
  74. // FIXME - Captcha Bug
  75. $session = Yii::app()->session;
  76. $prefixLen = strlen(CCaptchaAction::SESSION_VAR_PREFIX);
  77. foreach($session->keys as $key) {
  78. if(strncmp(CCaptchaAction::SESSION_VAR_PREFIX, $key, $prefixLen) == 0)
  79. $session->remove($key);
  80. }
  81. // Sends a password restore email.
  82. $user = User::model()->findByAttributes(array('username'=>$_POST['UserRecoveryForm']['login_or_email']));
  83.  
  84. $recovery_url = $this->createAbsoluteUrl(implode(Yii::app()->controller->module->recoveryUrl), array(
  85. "activkey" => $user->activkey,
  86. "email" => $user->email
  87. ));
  88. $subject = UserModule::t(
  89. "Password Recovery for :site_name",
  90. array(':site_name' => Yii::app()->name,)
  91. );
  92. $message = UserModule::t(
  93. "You have requested a password recovery for :site_name. Please change your password using the following link.<br>:recovery_url",
  94. array(
  95. ':site_name' => Yii::app()->name,
  96. ':recovery_url' => $recovery_url,
  97. )
  98. );
  99. UserModule::sendMail($user->email, $subject, $message);
  100. Yii::app()->user->setFlash(
  101. 'recoveryMessage',
  102. UserModule::t('<span class="label label-success">EMAIL SENT</span> A password recovery instruction is sent to your email address. Please follow the instruction to restore your password .'));
  103. $this->refresh();
  104. }
  105. }
  106. $this->render('recovery', array(
  107. 'model' => $model
  108. ));
  109. }
  110. }
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement