public function actionForgotpassword() { $this->layout = '/layouts/login'; $model = new ForgotPassword(); if (isset($_POST['ForgotPassword'])) { $model->attributes = $_POST['ForgotPassword']; if ($model->validate()) { $user = User::model()->find('LOWER(u_email)=:email', array(':email' => strtolower($model->username))); $salt = md5(uniqid(rand(), true)); $username = $user->u_username; $request = array('{reset_link}' => $salt, '{username}' => $username); if ($this->sendEmail(2, $user->u_email, $request)) { if ($user->updateByPk($user->u_id, array('u_scrkey' => $salt))) { Yii::app()->user->setFlash('success', 'A link has been sent to your email address to reset the password.'); $this->redirect(array('site/login')); } else { Yii::app()->user->setFlash('success', 'Error in setting the reset key.'); } } } } $this->render('forgotpassword', array('model' => $model)); }
public function actionForgotPassword() { $model = new ForgotPassword(); $getEmail = $_POST['ForgotPassword']['email']; $getModel = ServiceUser::model()->findByAttributes(array('email' => $getEmail)); $gtModel = CustomerUser::model()->findByAttributes(array('email' => $getEmail)); if (isset($_POST['ForgotPassword'])) { $model->attributes = $_POST['ForgotPassword']; if ($model->validate()) { if (!empty($getModel)) { $p = rand(); $pwd = md5($p); $subject = 'Welcome to Wow Cleans'; $body = $this->renderPartial('registrationEmail', array('model' => $model, 'password' => $p), true); $getModel->password = $pwd; if ($getModel->save()) { $msg = Yii::app()->user->setFlash('serviceforgot', "Please check you email !"); Yii::app()->mailer->send($model->email, $subject, $body); $this->redirect(array('registration/registration/index')); } } if (!empty($gtModel)) { $p = rand(); $pwd = md5($p); $subject = 'Welcome to Wow Cleans'; $body = $this->renderPartial('registrationEmail', array('model' => $model, 'password' => $p), true); $gtModel->password = $pwd; if ($gtModel->save()) { Yii::app()->mailer->send($model->email, $subject, $body); Yii::app()->user->setFlash('forgotc', "Please check you email"); $this->redirect(array('registration/registration/index')); } } } else { $errors = $model->getErrors(); } } $links = CmsPages::model()->findAll(); Yii::app()->params['MyArray'] = $links; $this->render('forgotpassword', array('model' => $model)); }