public function updateRequestAction()
 {
     MailerTemplate::checkRequired(UsersModule::MAILER_TEMPLATE_CHANGE_PASSWORD);
     $model = new User(User::SCENARIO_CHANGE_PASSWORD_REQUEST);
     $form = new Form('users.ChangePasswordRequestForm', $model);
     $this->performAjaxValidation($model);
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         if ($model->validate()) {
             $user = User::model()->find("email = '{$model->email}'");
             if ($user) {
                 if ($user->status == User::STATUS_ACTIVE) {
                     $user->password_recover_code = md5($user->password . $user->email . $user->id . time());
                     $user->password_recover_date = new CDbExpression('NOW()');
                     $user->save();
                     $outbox = new MailerOutbox();
                     $outbox->template_id = MailerTemplate::model()->getIdByCode(UsersModule::MAILER_TEMPLATE_CHANGE_PASSWORD);
                     $outbox->user_id = $user->id;
                     $outbox->save();
                     Yii::app()->user->setFlash('success', 'На ваш Email отправлено письмо с дальнейшими инструкциями.');
                 } else {
                     if ($user->status == User::STATUS_NEW) {
                         Yii::app()->user->setFlash('error', UserIdentity::ERROR_NOT_ACTIVE);
                     } else {
                         Yii::app()->user->setFlash('error', UserIdentity::ERROR_BLOCKED);
                     }
                 }
             } else {
                 Yii::app()->user->setFlash('error', UserIdentity::ERROR_UNKNOWN_EMAIL);
             }
             $this->redirect($_SERVER['REQUEST_URI']);
         }
     }
     $this->render("changePasswordRequest", array('form' => $form));
 }
 public function actionCreate()
 {
     $model = new MailerOutbox();
     $form = new Form('mailer.MailerOutboxForm', $model);
     $this->performAjaxValidation($model);
     if (isset($_POST['MailerOutbox'])) {
         $model->attributes = $_POST['MailerOutbox'];
         $template = MailerTemplate::model()->findByPk($model->template_id);
         $user = User::model()->findByPk($model->user_id);
         $model->subject = $template->constructSubject($user);
         $model->body = $template->constructBody($user);
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('form' => $form));
 }
Esempio n. 3
0
 public function actionActivateAccountRequest()
 {
     MailerTemplate::checkRequired(UsersModule::MAILER_TEMPLATE_ACTIVATION);
     $model = new User(User::SCENARIO_ACTIVATE_REQUEST);
     $form = new Form('users.ActivateRequestForm', $model);
     $this->performAjaxValidation($model);
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         if ($model->validate()) {
             $user = User::model()->findByAttributes(array('email' => $_POST['User']['email']));
             if (!$user) {
                 Yii::app()->user->setFlash('error', 'Введенный вами Email не найден');
             } else {
                 switch ($user->status) {
                     case User::STATUS_NEW:
                         $user->generateActivateCode();
                         $user->scenario = User::SCENARIO_ACTIVATE_REQUEST;
                         $user->activate_date = new CDbExpression('NOW()');
                         $user->save();
                         $outbox = new MailerOutbox();
                         $outbox->user_id = $user->id;
                         $outbox->template_id = MailerTemplate::model()->getIdByCode(UsersModule::MAILER_TEMPLATE_ACTIVATION);
                         $outbox->save();
                         Yii::app()->user->setFlash('success', 'На ваш Email отправлено письмо с дальнейшими инструкциями.');
                         break;
                     case User::STATUS_ACTIVE:
                         Yii::app()->user->setFlash('error', UserIdentity::ERROR_ALREADY_ACTIVE);
                         break;
                     case User::STATUS_BLOCKED:
                         Yii::app()->user->setFlash('error', UserIdentity::ERROR_BLOCKED);
                         break;
                 }
             }
         }
     }
     $this->render('activateAccountRequest', array('form' => $form));
 }
Esempio n. 4
0
<?php

return array('activeForm' => array('id' => 'mailerOutbox-form', 'enableAjaxValidation' => false, 'clientOptions' => array('validateOnType' => false, 'validateOnSubmit' => false)), 'elements' => array('template_id' => array('type' => 'dropdownlist', 'items' => CHtml::listData(MailerTemplate::model()->findAll('', array('order' => 'id DESC')), 'id', 'name'), 'empty' => 'не выбран'), 'email' => array('type' => 'text'), 'user_id' => array('type' => 'dropdownlist', 'items' => CHtml::listData(User::model()->findAll(), 'id', 'name'), 'empty' => 'не выбран')), 'buttons' => array('submit' => array('type' => 'submit', 'value' => $this->model->isNewRecord ? 'создать' : 'сохранить')));
Esempio n. 5
0
<?php

$this->tabs = array('отправить письмо' => $this->createUrl('create'));
$this->widget('AdminGridView', array('id' => 'outbox-email-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array(array('name' => 'email'), array('name' => 'template_id', 'value' => '$data->template->name', 'filter' => CHtml::listData(MailerTemplate::model()->findAll(), 'id', 'name')), array('name' => 'status', 'value' => '$data->status_caption', 'filter' => MailerOutbox::$status_list), array('name' => 'log'), array('name' => 'date_create', 'filter' => false), array('name' => 'date_send', 'filter' => false), array('class' => 'CButtonColumn', 'template' => '{view}'))));
Esempio n. 6
0
 /**
  * Checks for the required templates, use it before code in which they are used
  * @static
  * @param $code
  * @throws CException
  */
 public static function checkRequired($code)
 {
     $code = trim($code);
     $exist = MailerTemplate::model()->exists("code = '{$code}'");
     if (!$exist) {
         throw new CException("Не найден обязательный шаблон письма с кодом: {$code}");
     }
 }
Esempio n. 7
0
 public function beforeValidate()
 {
     if (parent::beforeValidate() && $this->isNewRecord) {
         $user = User::model()->findByPk($this->user_id);
         $template = MailerTemplate::model()->findByPk($this->template_id);
         if (!$this->subject) {
             $this->subject = $template->constructSubject($user);
         }
         if (!$this->body) {
             $this->body = $template->constructBody($user);
         }
         if (!$this->email) {
             $this->email = $user->email;
         }
     }
     return true;
 }