public static function notify($thread) { if (is_numeric($thread) && $thread > 0) { $email = Content::find()->where(['name' => 'email-sub'])->one(); if ($email) { $topic = $email->topic; $content = $email->content; } else { $topic = 'New post in subscribed thread at {forum}'; $content = '<p>There has been new post added in the thread you are subscribing. Click the following link to read the thread.</p><p>{link}</p><p>See you soon!<br />{forum}</p>'; } $forum = Config::getInstance()->get('name'); $subs = static::find()->where(['thread_id' => (int) $thread, 'post_seen' => static::POST_SEEN]); foreach ($subs->each() as $sub) { $sub->post_seen = static::POST_NEW; if ($sub->save()) { if (Email::queue($sub->user->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['default/last', 'id' => $sub->thread_id], true), Url::to(['default/last', 'id' => $sub->thread_id], true)), $content)), !empty($sub->user_id) ? $sub->user_id : null)) { Log::info('Subscription notice link queued', !empty($sub->user_id) ? $sub->user_id : '', __METHOD__); } else { Log::error('Error while queuing subscription notice link', !empty($sub->user_id) ? $sub->user_id : '', __METHOD__); } } } } }
/** * Updating the profile details. * @return string|\yii\web\Response */ public function actionDetails() { if ($this->module->userComponent == PodiumModule::USER_OWN) { $model = User::findOne(Yii::$app->user->id); if (empty($model)) { return $this->redirect(['account/login']); } $model->setScenario('account'); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { if ($model->saveChanges()) { if ($model->new_email) { $email = Content::find()->where(['name' => 'email-new'])->one(); if ($email) { $topic = $email->topic; $content = $email->content; } else { $topic = 'New e-mail activation link at {forum}'; $content = '<p>{forum} New E-mail Address Activation</p><p>To activate your new e-mail address open the following link in your Internet browser and follow the instructions on screen.</p><p>{link}</p><p>Thank you<br />{forum}</p>'; } $forum = Config::getInstance()->get('name'); if (Email::queue($model->new_email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['account/new-email', 'token' => $model->email_token], true), Url::to(['account/new-email', 'token' => $model->email_token], true)), $content)), !empty($model->id) ? $model->id : null)) { Log::info('New email activation link queued', !empty($model->id) ? $model->id : '', __METHOD__); $this->success('Your account has been updated but your new e-mail address is not active yet. ' . 'Click the activation link that has been sent to your new e-mail address.'); } else { Log::error('Error while queuing new email activation link', !empty($model->id) ? $model->id : '', __METHOD__); $this->warning('Your account has been updated but your new e-mail address is not active yet. ' . 'Unfortunately there was some error while sending you the activation link. ' . 'Contact administrator about this problem.'); } } else { Log::info('Details updated', !empty($model->id) ? $model->id : '', __METHOD__); $this->success('Your account has been updated.'); } return $this->refresh(); } } else { $model->current_password = null; } } } else { $model = (new PodiumUser())->findOne(Yii::$app->user->id); if (empty($model)) { return $this->module->goPodium(); } } return $this->render('details', ['model' => $model]); }
/** * Prepares notification email. * @param integer $thread */ public static function notify($thread) { if (is_numeric($thread) && $thread > 0) { $email = Content::find()->where(['name' => 'email-sub'])->limit(1)->one(); if ($email) { $topic = $email->topic; $content = $email->content; } else { $topic = Messages::EMAIL_SUB_TITLE; $content = Messages::EMAIL_SUB_BODY; } $forum = Config::getInstance()->get('name'); $subs = static::find()->where(['thread_id' => (int) $thread, 'post_seen' => self::POST_SEEN]); foreach ($subs->each() as $sub) { $sub->post_seen = self::POST_NEW; if ($sub->save()) { if (!empty($sub->user->email)) { if (Email::queue($sub->user->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['default/last', 'id' => $sub->thread_id], true), Url::to(['default/last', 'id' => $sub->thread_id], true)), $content)), $sub->user_id)) { Log::info('Subscription notice link queued', $sub->user_id, __METHOD__); } else { Log::error('Error while queuing subscription notice link', $sub->user_id, __METHOD__); } } else { Log::error('Error while queuing subscription notice link - no email set', $sub->user_id, __METHOD__); } } } } }
/** * Listing the contents. * @param string $name content name * @return string|\yii\web\Response */ public function actionContents($name = '') { $allowed = ['terms', 'email-reg', 'email-new', 'email-react', 'email-pass', 'email-sub']; if ($name == '' || !in_array($name, $allowed)) { $name = 'terms'; } $model = Content::find()->where(['name' => $name])->limit(1)->one(); if (!$model) { $model = new Content(); $model->name = $name; } if ($model->load(Yii::$app->request->post())) { if (User::can(Rbac::PERM_CHANGE_SETTINGS)) { if ($model->save()) { $this->success(Yii::t('podium/flash', 'Content has been saved.')); } else { $this->error(Yii::t('podium/flash', 'Sorry! There was some error while saving the content.')); } } else { $this->error(Yii::t('podium/flash', 'You are not allowed to perform this action.')); } return $this->refresh(); } return $this->render('contents', ['model' => $model]); }
/** * Sending the account password reset link. * @return string|\yii\web\Response */ public function actionReset() { if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) { $this->info(Yii::t('podium/flash', 'Please contact the administrator to reset your account password.')); return $this->module->goPodium(); } $model = new ReForm(); if ($model->load(Yii::$app->request->post())) { if ($model->reset()) { $email = Content::find()->where(['name' => 'email-pass'])->limit(1)->one(); if ($email) { $topic = $email->topic; $content = $email->content; } else { $topic = Messages::EMAIL_PASS_TITLE; $content = Messages::EMAIL_PASS_BODY; } $forum = Config::getInstance()->get('name'); if (!empty($model->email)) { if (Email::queue($model->user->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['account/password', 'token' => $model->user->password_reset_token], true), Url::to(['account/password', 'token' => $model->user->password_reset_token], true)), $content)), !empty($model->user->id) ? $model->user->id : null)) { Log::info('Password reset link queued', $model->user->id, __METHOD__); $this->success(Yii::t('podium/flash', 'The password reset link has been sent to your e-mail address.')); } else { Log::error('Error while queuing password reset link', $model->user->id, __METHOD__); $this->error(Yii::t('podium/flash', 'Sorry! There was some error while sending you the password reset link. Contact administrator about this problem.')); } } else { Log::error('Error while queuing password reset link - no email set', $model->user->id, __METHOD__); $this->error(Yii::t('podium/flash', 'Sorry! There is no e-mail address saved with your account. Contact administrator about resetting password.')); } return $this->module->goPodium(); } else { $this->error(Yii::t('podium/flash', 'Sorry! We can not find the account with that user name or e-mail address.')); } } return $this->render('reset', ['model' => $model]); }
/** * Sending the account password reset link. * @return string|\yii\web\Response */ public function actionReset() { $model = new ReForm(); if ($model->load(Yii::$app->request->post())) { if ($model->reset()) { $email = Content::find()->where(['name' => 'email-pass'])->one(); if ($email) { $topic = $email->topic; $content = $email->content; } else { $topic = Content::PASS_TITLE; $content = Content::PASS_BODY; } $forum = Config::getInstance()->get('name'); if (Email::queue($model->getUser()->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['account/password', 'token' => $model->getUser()->password_reset_token], true), Url::to(['account/password', 'token' => $model->getUser()->password_reset_token], true)), $content)), !empty($model->getUser()->id) ? $model->getUser()->id : null)) { Log::info('Password reset link queued', !empty($model->getUser()->id) ? $model->getUser()->id : '', __METHOD__); $this->success('The password reset link has been sent to your e-mail address.'); } else { Log::error('Error while queuing password reset link', !empty($model->getUser()->id) ? $model->getUser()->id : '', __METHOD__); $this->error('Sorry! There was some error while sending you the password reset link. Contact administrator about this problem.'); } return $this->module->goPodium(); } else { $this->error('Sorry! We can not find the account with that user name or e-mail address.'); } } return $this->render('reset', ['model' => $model]); }
/** * Listing the contents. * @param string $name content name * @return string|\yii\web\Response */ public function actionContents($name = '') { $allowed = ['terms', 'email-reg', 'email-new', 'email-react', 'email-pass', 'email-sub']; if ($name == '' || !in_array($name, $allowed)) { $name = 'terms'; } $model = Content::find()->where(['name' => $name])->one(); if (!$model) { $model = new Content(); $model->name = $name; } if ($model->load(Yii::$app->request->post()) && $model->save()) { $this->success('Content has been saved.'); return $this->refresh(); } return $this->render('contents', ['model' => $model]); }
/** * Returns email content. * @param string $name content's name * @return Content * @since 0.2 */ public static function fill($name) { $email = Content::find()->where(['name' => $name])->limit(1)->one(); if (empty($email)) { $email = Content::prepareDefault($name); } return $email; }
/** * Sending the account password reset link. * @return string|\yii\web\Response */ public function actionReset() { if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) { $this->info(Yii::t('podium/flash', 'Please contact the administrator to reset your account password.')); return $this->module->goPodium(); } $model = new ReForm(); if ($model->load(Yii::$app->request->post())) { if ($model->reset()) { $email = Content::find()->where(['name' => 'email-pass'])->limit(1)->one(); if ($email) { $topic = $email->topic; $content = $email->content; } else { $topic = '{forum} password reset link'; $content = '<p>{forum} Password Reset</p><p>You are receiving this e-mail because someone has started the process of changing the account password at {forum}.<br>If this person is you open the following link in your Internet browser and follow the instructions on screen.</p><p>{link}</p><p>If it was not you just ignore this e-mail.</p><p>Thank you!<br>{forum}</p>'; } $forum = Config::getInstance()->get('name'); if (!empty($model->email)) { if (Email::queue($model->user->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['account/password', 'token' => $model->user->password_reset_token], true), Url::to(['account/password', 'token' => $model->user->password_reset_token], true)), $content)), !empty($model->user->id) ? $model->user->id : null)) { Log::info('Password reset link queued', $model->user->id, __METHOD__); $this->success(Yii::t('podium/flash', 'The password reset link has been sent to your e-mail address.')); } else { Log::error('Error while queuing password reset link', $model->user->id, __METHOD__); $this->error(Yii::t('podium/flash', 'Sorry! There was some error while sending you the password reset link. Contact administrator about this problem.')); } } else { Log::error('Error while queuing password reset link - no email set', $model->user->id, __METHOD__); $this->error(Yii::t('podium/flash', 'Sorry! There is no e-mail address saved with your account. Contact administrator about resetting password.')); } return $this->module->goPodium(); } else { $this->error(Yii::t('podium/flash', 'Sorry! We can not find the account with that user name or e-mail address.')); } } return $this->render('reset', ['model' => $model]); }