/**
  * 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;
         }
     }
 }
Esempio n. 2
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;
         }
     }
 }
Esempio n. 3
0
 /**
  * Activating the account based on the provided activation token.
  * @param string $token
  * @return \yii\web\Response
  */
 public function actionActivate($token)
 {
     $model = User::findByActivationToken($token);
     if ($model) {
         $model->setScenario('token');
         if ($model->activate()) {
             Cache::clearAfterActivate();
             Log::info('Account activated', !empty($model->id) ? $model->id : '', __METHOD__);
             $this->success('Your account has been activated. You can sign in now.');
         } else {
             Log::error('Error while activating account', !empty($model->id) ? $model->id : '', __METHOD__);
             $this->error('Sorry! There was some error while activating your account. Contact administrator about this problem.');
         }
         return $this->module->goPodium();
     } else {
         $this->error('The provided activation token is invalid or expired.');
         return $this->module->goPodium();
     }
 }
Esempio n. 4
0
 /**
  * Activating the account based on the provided activation token.
  * @param string $token
  * @return \yii\web\Response
  */
 public function actionActivate($token)
 {
     if (PodiumModule::getInstance()->userComponent == PodiumModule::USER_INHERIT) {
         $this->info(Yii::t('podium/flash', 'Please contact the administrator to activate your account.'));
         return $this->module->goPodium();
     }
     $model = User::findByActivationToken($token);
     if ($model) {
         $model->setScenario('token');
         if ($model->activate()) {
             Cache::clearAfterActivate();
             Log::info('Account activated', $model->id, __METHOD__);
             $this->success(Yii::t('podium/flash', 'Your account has been activated. You can sign in now.'));
         } else {
             Log::error('Error while activating account', $model->id, __METHOD__);
             $this->error(Yii::t('podium/flash', 'Sorry! There was some error while activating your account. Contact administrator about this problem.'));
         }
         return $this->module->goPodium();
     } else {
         $this->error(Yii::t('podium/flash', 'The provided activation token is invalid or expired.'));
         return $this->module->goPodium();
     }
 }