public function actionRestorepassword() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new RestorepasswordForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { Yii::$app->session->setFlash('success', 'На Ваш email отправлено письмо с сылкой для установки нового пароля.'); $oUser = $model->getUser(); $oUser->us_key = Yii::$app->security->generateRandomString() . time(); $oUser->save(false, ['us_key']); $oNotify = new Notificator([$oUser], $oUser, 'restorepassword_mail'); $oNotify->notifyMail('Запрос на изменение пароля на сайте "' . Yii::$app->name . '"'); return $this->refresh(); // return $this->redirect('/'); } return $this->render('restorepassword', ['model' => $model]); }
public function behaviors() { return [['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['us_created']], 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'password', ActiveRecord::EVENT_BEFORE_UPDATE => 'password'], 'value' => function ($event) { /** @var \yii\base\Event $event */ $model = $event->sender; if (!empty($model->password)) { $model->setPassword($model->password); } return $model->password; }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'us_confirmkey'], 'value' => function ($event) { /** @var \yii\base\Event $event */ return Yii::$app->security->generateRandomString() . time(); }], ['class' => ActionBehavior::className(), 'allevents' => [ActiveRecord::EVENT_AFTER_INSERT], 'action' => function ($event) { /** @var \yii\base\Event $event */ $model = $event->sender; if ($model->scenario == 'register') { $oNotify = new Notificator([$model], $model, 'confirm_mail'); $oNotify->notifyMail('Подтвердите регистрацию на портале "' . Yii::$app->name . '"'); } }]]; }
public function behaviors() { return [['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['prs_created']], 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'prs_confirmkey'], 'value' => function ($event) { /** @var \yii\base\Event $event */ /** @var Person $model */ $model = $event->sender; if ($model->prs_type == Person::PERSON_TYPE_GUEST) { return Yii::$app->security->generateRandomString() . time(); } return $model->prs_confirmkey; }], ['class' => ActionBehavior::className(), 'allevents' => [ActiveRecord::EVENT_AFTER_INSERT], 'action' => function ($event) { /** @var \yii\base\Event $event */ /** @var Person $model */ /** @var \\app\\components\Notificator $oNotify */ $model = $event->sender; if ($model->prs_type == Person::PERSON_TYPE_GUEST) { $oNotify = new Notificator([$model], $model, 'confirm_guest_mail'); $oNotify->sEmailField = 'prs_email'; $oNotify->notifyMail('Подтвердите регистрацию в качестве гостя на портале "' . Yii::$app->name . '"'); } }]]; }
/** * @param Doclad $model * @return array|string|Response */ public function changeDoclad($model) { $model->_oldAttributesValues = $model->attributes; $model->on(ActiveRecord::EVENT_AFTER_UPDATE, function ($event) { /** @var Doclad $model */ $model = $event->sender; if ($model->_oldAttributesValues['doc_state'] != $model->doc_state) { $oNotify = new Notificator([User::findOne($model->doc_us_id)], $model, 'change_doclad_state'); $oNotify->notifyMail('Модератор изменил статус Вашего доклада на сайте "' . Yii::$app->name . '"'); } if ($model->_oldAttributesValues['doc_format'] != $model->doc_format) { $oNotify = new Notificator([User::findOne($model->doc_us_id)], $model, 'change_doclad_format'); $oNotify->notifyMail('Модератор изменил формат представления Вашего доклада на сайте "' . Yii::$app->name . '"'); } }); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; $aValidate = ActiveForm::validate($model); // Yii::info('addDoclad(): return json ' . print_r($aRes, true)); return $aValidate; } if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->doc_state == Doclad::DOC_STATUS_APPROVE) { $model->doc_comment = ''; } if ($model->save()) { Yii::$app->session->setFlash('success', 'Данные успешно сохранены'); return $this->redirect(['index']); } else { Yii::info('Error save: ' . print_r($model->getErrors(), true)); } } return $this->render('fullview', ['model' => $model]); }