Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- di sitecontroler.php
- public function actionForgotPassword()
- {
- $model = new Useraccess;
- $hash = '';
- if (isset($_POST['Useraccess'])) {
- $model->attributes = $_POST['Useraccess'];
- if ($model->validate()) {
- $model = Useraccess::model()->findByEmail($_POST['Useraccess']['email']);
- $timestamp = time();
- $hash = crypt($model->email . $model->password . $timestamp);
- Shared::debug($hash);
- $model->password_reset = $timestamp;
- // save the timestamp (password reset is good for 24 hours only)
- $model->save();
- $message = new YiiMailMessage('forgotPass', array('hash' => $hash));
- $message->view = "forgotpassword";
- $params = array('myMail'=>$model);
- $message->subject = 'Harry Diecast - Forgot Password System';
- $message->setBody($params, 'text/html');
- $message->addTo($model->email);
- $message->from = Yii::app()->params['adminEmail'];
- Yii::app()->mail->send($message);
- if ($model->Send()) {
- $message->ClearAddresses();
- app()->user->setFlash('success', 'Please check your email for further instructions.');
- $this->redirect(array('/site/index'));
- } else {
- app()->user->setFlash('error', 'Error while sending email: ' . $message->ErrorInfo);
- }
- }
- }
- $this->render('forgotpassword', array('model' => $model, 'hash'=>$hash));
- }
- sedangkan di sote/forgotpassword.php
- <?php
- $this->pageTitle=Yii::app()->name . ' - Forgot Password';
- $this->breadcrumbs=array(
- 'Forgot Password',
- );
- ?>
- <?php $form=$this->beginWidget('CActiveForm', array(
- 'id'=>'forgot-form',
- 'enableClientValidation'=>true,
- 'clientOptions'=>array(
- 'validateOnSubmit'=>true,
- ),
- )); ?>
- <div class="form-group">
- </br>
- </br>
- <div class="form-group">
- <div class="col-md-4">
- <?php echo $form->labelEx($model,'email'); ?>
- </div>
- <div class="col-md-8">
- <?php echo $form->textField($model,'email',array('size'=>50,'maxlength'=>50,'class'=>'form-control', 'placeholder'=>'Enter Email')); ?>
- <?php echo $form->error($model,'email',array('class'=>'text-danger')); ?>
- </div>
- </div>
- </br>
- <div class="form-group">
- <div class="col-md-4">
- </div>
- <div class="col-md-8">
- <?php echo CHtml::submitButton('Forgot password'); ?>
- </div>
- </div>
- <?php $this->endWidget(); ?>
- </div><!-- form -->
- klo /text.htmlnya sprti ini di view
- <html>
- <head>
- </head>
- <body>
- Dear <?php
- echo $myMail['fullname'];
- ?><br>Harry Diecast - Forgot Password Form
- <br>Password anda adalah...
- <br>Silahkan Mencoba login kembali
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement