/**
  * Creates inherited user account.
  */
 public function init()
 {
     parent::init();
     if (!Yii::$app->user->isGuest) {
         if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
             $user = User::findMe();
             if (empty($user)) {
                 $new = new User();
                 $new->setScenario('installation');
                 $new->inherited_id = Yii::$app->user->id;
                 $new->status = User::STATUS_ACTIVE;
                 $new->role = User::ROLE_MEMBER;
                 $new->timezone = User::DEFAULT_TIMEZONE;
                 if ($new->save()) {
                     $this->success(Yii::t('podium/flash', 'Hey! Your new forum account has just been automatically created! Go to {link} to complement it.', ['link' => Html::a(Yii::t('podium/view', 'Profile'))]));
                     Cache::clearAfterActivate();
                     Log::info('Inherited account created', $new->id, __METHOD__);
                 } else {
                     throw new Exception(Yii::t('podium/view', 'There was an error while creating inherited user account. Podium can not run with the current configuration. Please contact administrator about this problem.'));
                 }
             } elseif ($user->status == User::STATUS_BANNED) {
                 return $this->redirect(['default/ban']);
             }
         } else {
             $user = Yii::$app->user->identity;
         }
         if ($user && !empty($user->timezone)) {
             Yii::$app->formatter->timeZone = $user->timezone;
         }
     }
 }
Example #2
0
 /**
  * Adds Administrator account.
  * @return string result message.
  */
 protected function _addAdmin()
 {
     try {
         $podium = PodiumModule::getInstance();
         if ($podium->userComponent == PodiumModule::USER_INHERIT) {
             if (!empty($podium->adminId)) {
                 $this->authManager->assign($this->authManager->getRole('podiumAdmin'), $podium->adminId);
                 return $this->outputSuccess(Yii::t('podium/flash', Messages::ADMINISTRATOR_PRIVILEGES_SET, ['id' => $podium->adminId]));
             } else {
                 return $this->outputWarning(Yii::t('podium/flash', Messages::NO_ADMINISTRATOR_PRIVILEGES_SET));
             }
         } else {
             $admin = new User();
             $admin->setScenario('installation');
             $admin->username = self::DEFAULT_USERNAME;
             $admin->email = self::DEFAULT_USER_EMAIL;
             $admin->status = User::STATUS_ACTIVE;
             $admin->role = User::ROLE_ADMIN;
             $admin->generateAuthKey();
             $admin->setPassword(self::DEFAULT_USERNAME);
             if ($admin->save()) {
                 $this->authManager->assign($this->authManager->getRole('podiumAdmin'), $admin->getId());
                 return $this->outputSuccess(Yii::t('podium/flash', Messages::ADMINISTRATOR_ACCOUNT_CREATED) . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Login') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME) . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Password') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME));
             } else {
                 $this->setError(true);
                 return $this->outputDanger(Yii::t('podium/flash', Messages::ACCOUNT_CREATING_ERROR) . ': ' . Html::tag('pre', VarDumper::dumpAsString($admin->getErrors())));
             }
         }
     } catch (Exception $e) {
         Yii::error([$e->getName(), $e->getMessage()], __METHOD__);
         $this->setError(true);
         return $this->outputDanger(Yii::t('podium/flash', Messages::ACCOUNT_CREATING_ERROR) . ': ' . Html::tag('pre', $e->getMessage()));
     }
 }
Example #3
0
 /**
  * Creates inherited user account.
  */
 public function init()
 {
     parent::init();
     if (!Yii::$app->user->isGuest) {
         if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
             $user = User::findMe();
             if (empty($user)) {
                 $new = new User();
                 $new->setScenario('installation');
                 $new->inherited_id = Yii::$app->user->id;
                 $new->status = User::STATUS_ACTIVE;
                 $new->role = User::ROLE_MEMBER;
                 $new->timezone = User::DEFAULT_TIMEZONE;
                 if ($new->save()) {
                     $this->success(Yii::t('podium/flash', Messages::ACCOUNT_INHERITED, ['link' => Html::a(Yii::t('podium/layout', 'Profile'))]));
                     Cache::clearAfterActivate();
                     Log::info('Inherited account created', $new->id, __METHOD__);
                 } else {
                     throw new Exception(Yii::t('podium/view', Messages::ACCOUNT_INHERITED_ERROR));
                 }
             } elseif ($user->status == User::STATUS_BANNED) {
                 return $this->redirect(['default/ban']);
             }
         } else {
             $user = Yii::$app->user->identity;
         }
         if ($user && !empty($user->timezone)) {
             Yii::$app->formatter->timeZone = $user->timezone;
         }
     }
 }
Example #4
0
 /**
  * Adds Administrator account.
  * @return string result message.
  */
 protected function _addAdmin()
 {
     try {
         $podium = PodiumModule::getInstance();
         if ($podium->userComponent == PodiumModule::USER_INHERIT) {
             if (!empty($podium->adminId)) {
                 $admin = new User();
                 $admin->setScenario('installation');
                 $admin->inherited_id = $podium->adminId;
                 $admin->username = self::DEFAULT_USERNAME;
                 $admin->status = User::STATUS_ACTIVE;
                 $admin->role = User::ROLE_ADMIN;
                 $admin->timezone = User::DEFAULT_TIMEZONE;
                 if ($admin->save()) {
                     $this->authManager->assign($this->authManager->getRole(Rbac::ROLE_ADMIN), $podium->adminId);
                     return $this->outputSuccess(Yii::t('podium/flash', 'Administrator privileges have been set for the user of ID {id}.', ['id' => $podium->adminId]));
                 } else {
                     $this->setError(true);
                     return $this->outputDanger(Yii::t('podium/flash', 'Error during account creating') . ': ' . Html::tag('pre', VarDumper::dumpAsString($admin->getErrors())));
                 }
             } else {
                 return $this->outputWarning(Yii::t('podium/flash', 'No administrator privileges have been set.'));
             }
         } else {
             $admin = new User();
             $admin->setScenario('installation');
             $admin->username = self::DEFAULT_USERNAME;
             $admin->status = User::STATUS_ACTIVE;
             $admin->role = User::ROLE_ADMIN;
             $admin->timezone = User::DEFAULT_TIMEZONE;
             $admin->generateAuthKey();
             $admin->setPassword(self::DEFAULT_USERNAME);
             if ($admin->save()) {
                 $this->authManager->assign($this->authManager->getRole(Rbac::ROLE_ADMIN), $admin->getId());
                 return $this->outputSuccess(Yii::t('podium/flash', 'Administrator account has been created.') . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Login') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME) . ' ' . Html::tag('strong', Yii::t('podium/flash', 'Password') . ':') . ' ' . Html::tag('kbd', self::DEFAULT_USERNAME));
             } else {
                 $this->setError(true);
                 return $this->outputDanger(Yii::t('podium/flash', 'Error during account creating') . ': ' . Html::tag('pre', VarDumper::dumpAsString($admin->getErrors())));
             }
         }
     } catch (Exception $e) {
         Yii::error([$e->getName(), $e->getMessage()], __METHOD__);
         $this->setError(true);
         return $this->outputDanger(Yii::t('podium/flash', 'Error during account creating') . ': ' . Html::tag('pre', $e->getMessage()));
     }
 }
 /**
  * Registering the new account and sending the activation link.
  * @return string|\yii\web\Response
  */
 public function actionRegister()
 {
     if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
         $this->info(Yii::t('podium/flash', 'Please use application Register form to sign up.'));
         return $this->module->goPodium();
     }
     $model = new User();
     $model->setScenario('register');
     if ($model->load(Yii::$app->request->post()) && $model->register()) {
         $email = Content::find()->where(['name' => 'email-reg'])->limit(1)->one();
         if ($email) {
             $topic = $email->topic;
             $content = $email->content;
         } else {
             $topic = Messages::EMAIL_REG_TITLE;
             $content = Messages::EMAIL_REG_BODY;
         }
         $forum = Config::getInstance()->get('name');
         if (!empty($model->email)) {
             if (Email::queue($model->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['account/activate', 'token' => $model->activation_token], true), Url::to(['account/activate', 'token' => $model->activation_token], true)), $content)), !empty($model->id) ? $model->id : null)) {
                 Log::info('Activation link queued', !empty($model->id) ? $model->id : '', __METHOD__);
                 $this->success(Yii::t('podium/flash', 'Your account has been created but it is not active yet. Click the activation link that has been sent to your e-mail address.'));
             } else {
                 Log::warning('Error while queuing activation link', !empty($model->id) ? $model->id : '', __METHOD__);
                 $this->warning(Yii::t('podium/flash', 'Your account has been created but it is not active yet. ' . 'Unfortunately there was some error while sending you the activation link. ' . 'Contact administrator about this or try to {resend the link}.', ['resend the link' => Html::a(Yii::t('podium/flash', 'resend the link'), ['account/reactivate'])]));
             }
         } else {
             Log::error('Error while queuing activation link - no email set', $model->id, __METHOD__);
             $this->error(Yii::t('podium/flash', 'Sorry! There is no e-mail address saved with your account. Contact administrator about activating.'));
         }
         return $this->module->goPodium();
     }
     return $this->render('register', ['model' => $model, 'terms' => Content::findOne(['name' => 'terms'])]);
 }
 /**
  * Registering the new account and sending the activation link.
  * @return string|\yii\web\Response
  */
 public function actionRegister()
 {
     $model = new User();
     $model->setScenario('register');
     if ($model->load(Yii::$app->request->post()) && $model->register()) {
         $email = Content::find()->where(['name' => 'email-reg'])->one();
         if ($email) {
             $topic = $email->topic;
             $content = $email->content;
         } else {
             $topic = Content::REG_TITLE;
             $content = Content::REG_BODY;
         }
         $forum = Config::getInstance()->get('name');
         if (Email::queue($model->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['account/activate', 'token' => $model->activation_token], true), Url::to(['account/activate', 'token' => $model->activation_token], true)), $content)), !empty($model->id) ? $model->id : null)) {
             Log::info('Activation link queued', !empty($model->id) ? $model->id : '', __METHOD__);
             $this->success('Your account has been created but it is not active yet. Click the activation link that has been sent to your e-mail address.');
         } else {
             Log::warning('Error while queuing activation link', !empty($model->id) ? $model->id : '', __METHOD__);
             $this->warning('Your account has been created but it is not active yet. ' . 'Unfortunately there was some error while sending you the activation link. ' . 'Contact administrator about this or try to {link}resend the link{closelink}.', ['link' => Html::beginTag('a', ['href' => Url::to('account/reactivate')]), 'closelink' => Html::endTag('a')]);
         }
         return $this->module->goPodium();
     }
     return $this->render('register', ['model' => $model, 'terms' => Content::findOne(['name' => 'terms'])]);
 }