public function actionForget() { $this->layout = '/layouts/index'; $model = new ForgetForm(); if (($post = $this->request->getPost('ForgetForm', false)) != false) { $post['password'] = $this->grantePassword(); $model->attributes = $post; if ($model->save()) { $this->render('forget', ['model' => $model, 'success' => true]); } else { $this->render('forget', ['model' => $model, 'success' => false]); } return; } $this->render('forget', ['model' => $model]); }
public function actionForget() { $model = new ForgetForm(); if (isset($_POST['ForgetForm'])) { $model->attributes = $_POST['ForgetForm']; if ($model->validate()) { $acc = Account::model()->findByAttributes(array('username' => $model->username)); if (empty($acc)) { $confirm = "The Username is not exist!"; Yii::app()->user->setFlash('forget', $confirm); $this->refresh(); return; } else { if ($acc->email != $model->email) { $confirm = "Email is not right!"; Yii::app()->user->setFlash('forget', $confirm); $this->refresh(); return; } } $newPass = $this->_getRandId(Yii::app()->params['passwordLength']); $acc->password = $acc->hashPassword($newPass); if (!$acc->save()) { Yii::app()->user->setFlash('forget', "Error!"); } Yii::import('application.extensions.yii-mail.YiiMailMessage'); $message = new YiiMailMessage(); $message->setTo($model->email); $message->setFrom(array(Yii::app()->params['siteEmail'] => Yii::app()->params['siteName'])); $subject = "Password Reset"; $message->setSubject($subject); /*$body = "Username: "******" \r\nNew password: "******"Your new password has been sent to your email."; Yii::app()->user->setFlash('forget', $confirm); $this->refresh(); } } $this->render('forget', array('model' => $model)); }