Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. di sitecontroler.php
  2.  
  3. public function actionForgotPassword()
  4. {
  5. $model = new Useraccess;
  6. $hash = '';
  7. if (isset($_POST['Useraccess'])) {
  8. $model->attributes = $_POST['Useraccess'];
  9. if ($model->validate()) {
  10. $model = Useraccess::model()->findByEmail($_POST['Useraccess']['email']);
  11. $timestamp = time();
  12. $hash = crypt($model->email . $model->password . $timestamp);
  13. Shared::debug($hash);
  14. $model->password_reset = $timestamp;
  15.  
  16. // save the timestamp (password reset is good for 24 hours only)
  17. $model->save();
  18.  
  19. $message = new YiiMailMessage('forgotPass', array('hash' => $hash));
  20. $message->view = "forgotpassword";
  21. $params = array('myMail'=>$model);
  22. $message->subject = 'Harry Diecast - Forgot Password System';
  23. $message->setBody($params, 'text/html');
  24. $message->addTo($model->email);
  25. $message->from = Yii::app()->params['adminEmail'];
  26. Yii::app()->mail->send($message);
  27.  
  28. if ($model->Send()) {
  29. $message->ClearAddresses();
  30. app()->user->setFlash('success', 'Please check your email for further instructions.');
  31. $this->redirect(array('/site/index'));
  32. } else {
  33. app()->user->setFlash('error', 'Error while sending email: ' . $message->ErrorInfo);
  34. }
  35. }
  36. }
  37. $this->render('forgotpassword', array('model' => $model, 'hash'=>$hash));
  38. }
  39.  
  40.  
  41. sedangkan di sote/forgotpassword.php
  42.  
  43. <?php
  44. $this->pageTitle=Yii::app()->name . ' - Forgot Password';
  45. $this->breadcrumbs=array(
  46. 'Forgot Password',
  47. );
  48. ?>
  49.  
  50. <?php $form=$this->beginWidget('CActiveForm', array(
  51. 'id'=>'forgot-form',
  52. 'enableClientValidation'=>true,
  53. 'clientOptions'=>array(
  54. 'validateOnSubmit'=>true,
  55. ),
  56. )); ?>
  57.  
  58. <div class="form-group">
  59. </br>
  60. </br>
  61. <div class="form-group">
  62. <div class="col-md-4">
  63. <?php echo $form->labelEx($model,'email'); ?>
  64. </div>
  65. <div class="col-md-8">
  66. <?php echo $form->textField($model,'email',array('size'=>50,'maxlength'=>50,'class'=>'form-control', 'placeholder'=>'Enter Email')); ?>
  67. <?php echo $form->error($model,'email',array('class'=>'text-danger')); ?>
  68. </div>
  69. </div>
  70. </br>
  71.  
  72. <div class="form-group">
  73. <div class="col-md-4">
  74. </div>
  75. <div class="col-md-8">
  76. <?php echo CHtml::submitButton('Forgot password'); ?>
  77. </div>
  78. </div>
  79. <?php $this->endWidget(); ?>
  80.  
  81. </div><!-- form -->
  82.  
  83. klo /text.htmlnya sprti ini di view
  84.  
  85. <html>
  86. <head>
  87. </head>
  88. <body>
  89. Dear <?php
  90. echo $myMail['fullname'];
  91. ?><br>Harry Diecast - Forgot Password Form
  92. <br>Password anda adalah...
  93. <br>Silahkan Mencoba login kembali
  94. </body>
  95. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement