Advertisement
hendrayodhi

reset password

Dec 11th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. <?php
  2.  
  3. class SiteController extends Controller
  4. {
  5. /**
  6. * Declares class-based actions.
  7. */
  8. public function actions()
  9. {
  10. return array(
  11. // captcha action renders the CAPTCHA image displayed on the contact page
  12. 'captcha'=>array(
  13. 'class'=>'CCaptchaAction',
  14. 'backColor'=>0xFFFFFF,
  15. ),
  16. // page action renders "static" pages stored under 'protected/views/site/pages'
  17. // They can be accessed via: index.php?r=site/page&view=FileName
  18. 'page'=>array(
  19. 'class'=>'CViewAction',
  20. ),
  21. );
  22. }
  23.  
  24. /**
  25. * This is the default 'index' action that is invoked
  26. * when an action is not explicitly requested by users.
  27. */
  28. public function actionIndex()
  29. {
  30. // renders the view file 'protected/views/site/index.php'
  31. // using the default layout 'protected/views/layouts/main.php'
  32. $this->render('index');
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39. /**
  40. * This is the action to handle external exceptions.
  41. */
  42. public function actionError()
  43. {
  44. if($error=Yii::app()->errorHandler->error)
  45. {
  46. if(Yii::app()->request->isAjaxRequest)
  47. echo $error['message'];
  48. else
  49. $this->render('error', $error);
  50. }
  51. }
  52.  
  53. /**
  54. * Displays the contact page
  55. */
  56. public function actionContact()
  57. {
  58. $model=new ContactForm;
  59. if(isset($_POST['ContactForm']))
  60. {
  61. $model->attributes=$_POST['ContactForm'];
  62. if($model->validate())
  63. {
  64. $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
  65. $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
  66. $headers="From: $name <{$model->email}>\r\n".
  67. "Reply-To: {$model->email}\r\n".
  68. "MIME-Version: 1.0\r\n".
  69. "Content-type: text/plain; charset=UTF-8";
  70.  
  71. mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
  72. Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  73. $this->refresh();
  74. }
  75. }
  76. $this->render('contact',array('model'=>$model));
  77. }
  78.  
  79. /**
  80. * Displays the login page
  81. */
  82. public function actionLogin()
  83. {
  84. $model=new LoginForm;
  85.  
  86. // if it is ajax validation request
  87. if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  88. {
  89. echo CActiveForm::validate($model);
  90. Yii::app()->end();
  91. }
  92.  
  93. // collect user input data
  94. if(isset($_POST['LoginForm']))
  95. {
  96. $model->attributes=$_POST['LoginForm'];
  97. // validate user input and redirect to the previous page if valid
  98. if($model->validate() && $model->login())
  99. $this->redirect(Yii::app()->user->returnUrl);
  100. }
  101. // display the login form
  102. $this->render('login',array('model'=>$model));
  103. }
  104.  
  105. /**
  106. * Logs out the current user and redirect to homepage.
  107. */
  108. public function actionLogout()
  109. {
  110. Yii::app()->user->logout();
  111. $this->redirect(Yii::app()->homeUrl);
  112. }
  113.  
  114. public function actionResetPassword(){
  115.  
  116. $model = new ResetPassword;
  117. $msg = '';
  118. if(isset($_POST['ResetPassword']))
  119. {
  120. $model->attributes= $_POST['ResetPassword'];
  121. if(!$model->validate())
  122. {
  123. $msg = "<strong class='text-error'>formulir yang diisi salah</strong>";
  124. }else{
  125.  
  126. $connect= Yii::app()->db;
  127.  
  128. $query = "SELECT username, email FROM user where";
  129. $query .= "username='".$model->username."' AND email='".$model->email."'";
  130.  
  131. $tes = $connect->createCommand($query);
  132. $rows = $tes->query();
  133. $hasil= false;
  134.  
  135. foreach($rows as $row)
  136. {
  137. $hasil = true;
  138. }
  139.  
  140. if($hasil === true)
  141. {
  142. $query = "SELECT username, email FROM user where";
  143. // $query .= "username='".$model->username."' AND email='"$model->email;
  144. $query .= "username='".$model->username."' AND email='".$model->email."'";
  145.  
  146. $tes = $connect->createCommand($query)->query();
  147. $tes->bindColumn(1,$password);
  148.  
  149. while($tes->read()!==false)
  150. {
  151. $password = $password;
  152. }
  153.  
  154. $email = new SubmitEmail;
  155. $subject = "permintaan untuk pemulihan password";
  156. $subject .= Yii::app()->name;
  157. $message = "welcome@".$model->username." dengan password";
  158. $message .= $password;
  159. $message .= "<br /><br />";
  160. $message .= "<a href='http://localhost/latihan/forgot/'>kembali</a>";
  161.  
  162. $email->Submit_Email(
  163.  
  164. array(Yii::app()->params['adminEmail'], Yii::app()->name),
  165. array($model->email,$model->username),
  166.  
  167. $subject,
  168. $message
  169. );
  170.  
  171. $model->username = '';
  172. $model->email = '';
  173. $model->captcha = '';
  174. $msg="<strong class='text-info'>congratulation, we have sent your password to your email account</strong>";
  175. }else
  176. {
  177. $msg ="<strong class='text-error'>error data tidak ada</strong>";
  178. }
  179. }
  180. }
  181.  
  182.  
  183. $this->render('resetpassword',array('model'=>$model,'msg'=>$msg));
  184. }
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement