Beispiel #1
0
 /**
  * Adds email to queue.
  * @param string $address
  * @param string $subject
  * @param string $content
  * @param integer|null $user_id
  * @return boolean
  */
 public static function queue($address, $subject, $content, $user_id = null)
 {
     try {
         $email = new Email();
         $email->user_id = $user_id;
         $email->email = $address;
         $email->subject = $subject;
         $email->content = $content;
         $email->status = Email::STATUS_PENDING;
         $email->attempt = 0;
         return $email->save();
     } catch (Exception $e) {
         Log::error($e->getMessage(), null, __METHOD__);
     }
     return false;
 }
 /**
  * Updating the profile details.
  * @return string|\yii\web\Response
  */
 public function actionDetails()
 {
     $model = User::findMe();
     if (empty($model)) {
         return $this->redirect(['account/login']);
     }
     $model->scenario = PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT ? 'accountInherit' : 'account';
     $model->current_password = null;
     $previous_new_email = $model->new_email;
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if ($model->saveChanges()) {
                 if ($previous_new_email != $model->new_email) {
                     $forum = Config::getInstance()->get('name');
                     $email = Content::fill(Content::EMAIL_NEW);
                     if ($email !== false && Email::queue($model->new_email, str_replace('{forum}', $forum, $email->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)), $email->content)), !empty($model->id) ? $model->id : null)) {
                         Log::info('New email activation link queued', $model->id, __METHOD__);
                         $this->success(Yii::t('podium/flash', 'Your account has been updated but your new e-mail address is not active yet. Click the activation link that will be sent to your new e-mail address in few minutes.'));
                     } else {
                         Log::error('Error while queuing new email activation link', $model->id, __METHOD__);
                         $this->warning(Yii::t('podium/flash', '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', $model->id, __METHOD__);
                     $this->success(Yii::t('podium/flash', 'Your account has been updated.'));
                 }
                 return $this->refresh();
             }
         }
     }
     $model->current_password = null;
     return $this->render('details', ['model' => $model]);
 }
Beispiel #3
0
 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]);
 }
Beispiel #5
0
 /**
  * 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__);
                 }
             }
         }
     }
 }
 /**
  * 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]);
 }
Beispiel #7
0
 /**
  * Prepares notification email.
  * @param integer $thread
  */
 public static function notify($thread)
 {
     if (is_numeric($thread) && $thread > 0) {
         $forum = Config::getInstance()->get('name');
         $email = Content::fill(Content::EMAIL_SUBSCRIPTION);
         $subs = static::find()->where(['thread_id' => $thread, 'post_seen' => self::POST_SEEN]);
         foreach ($subs->each() as $sub) {
             $sub->post_seen = self::POST_NEW;
             if ($sub->save()) {
                 if ($email !== false && !empty($sub->user->email)) {
                     if (Email::queue($sub->user->email, str_replace('{forum}', $forum, $email->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)), $email->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__);
                 }
             }
         }
     }
 }
 /**
  * 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]);
 }
 /**
  * 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]);
 }