Пример #1
0
 public function actionRemember()
 {
     if (!Yii::app()->user->isGuest) {
         throw new CHttpException('500', 'Восстановление пароля недоступно');
     }
     $model = new Anketa('remember');
     if (isset($_POST['Anketa'])) {
         $model->attributes = $_POST['Anketa'];
         if ($model->validate()) {
             $model = Anketa::model()->findByAttributes(array('email' => $model->email));
             if ($model === null) {
                 throw new CHttpException('500', 'Пользователь не найден');
             }
             $model->password = Anketa::randomSalt(7);
             // 'xNhd9po';
             //echo $model->password; //die();
             if ($model->saveAttributes(array('password'))) {
                 // email sender
                 $email = Yii::app()->email;
                 $email->view = 'remember';
                 $email->viewVars = array('model' => $model);
                 $email->subject = 'Восстановление пароля на ' . Yii::app()->name;
                 $email->from = Yii::app()->params['noreplyEmail'];
                 $email->to = $model->email;
                 $email->send();
                 Yii::app()->user->setFlash('remember', 'Информация о восстановлении пароля отправлена на указанный ящик');
                 $this->refresh();
             } else {
                 throw new CHttpException('500', 'Ошибка сохранения');
             }
         }
     }
     $this->render('remember', array('model' => $model));
 }
Пример #2
0
 /**
  * не используется?
  * @return mixed
  */
 public function _actionForm()
 {
     $model = new Anketa('search');
     // uncomment the following code to enable ajax-based validation
     /*
     if(isset($_POST['ajax']) && $_POST['ajax']==='anketa-anketaform-form')
     {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     */
     if (isset($_POST['Anketa'])) {
         $model->attributes = $_POST['Anketa'];
         if ($model->validate()) {
             // form inputs are valid, do something here
             return;
         }
     }
     $this->render('anketaform', array('model' => $model));
 }