Example #1
0
 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));
 }