/** * 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 (empty($model)) { $this->error(Yii::t('podium/flash', 'The provided activation token is invalid or expired.')); return $this->module->goPodium(); } $model->scenario = 'token'; if ($model->activate()) { Cache::clearAfter('activate'); 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(); }
/** * Performs new post creation and subscription. * If previous post in thread has got the same author posts are merged. * @param Post $previous previous post * @return boolean * @throws Exception * @since 0.2 */ public function podiumNew($previous = null) { $transaction = static::getDb()->beginTransaction(); try { $id = null; if (!empty($previous) && $previous->author_id == User::loggedId()) { $previous->content .= '<hr>' . $this->content; $previous->edited = 1; $previous->touch('edited_at'); if ($previous->save()) { $previous->markSeen(); $previous->thread->touch('edited_post_at'); $id = $previous->id; $thread = $previous->thread; } } else { if ($this->save()) { $this->markSeen(); $this->forum->updateCounters(['posts' => 1]); $this->thread->updateCounters(['posts' => 1]); $this->thread->touch('new_post_at'); $this->thread->touch('edited_post_at'); $id = $this->id; $thread = $this->thread; } } if (empty($id)) { throw new Exception('Saved Post ID missing'); } Subscription::notify($thread->id); if ($this->subscribe && !$thread->subscription) { $subscription = new Subscription(); $subscription->user_id = User::loggedId(); $subscription->thread_id = $thread->id; $subscription->post_seen = Subscription::POST_SEEN; $subscription->save(); } $transaction->commit(); Cache::clearAfter('newPost'); Log::info('Post added', $id, __METHOD__); return true; } catch (Exception $e) { $transaction->rollBack(); Log::error($e->getMessage(), null, __METHOD__); } return false; }
/** * Creates inherited account. * @return boolean * @since 0.2 */ public static function createInheritedAccount() { try { if (!Yii::$app->user->isGuest) { $new = new User(); $new->scenario = 'installation'; $new->inherited_id = Yii::$app->user->id; $new->status = self::STATUS_ACTIVE; $new->role = self::ROLE_MEMBER; $new->timezone = self::DEFAULT_TIMEZONE; if (!$new->save()) { throw new Exception('Account creating error'); } Yii::$app->authManager->assign(Yii::$app->authManager->getRole(Rbac::ROLE_USER), $new->id); Cache::clearAfter('activate'); Log::info('Inherited account created', $new->id, __METHOD__); return true; } } catch (Exception $e) { Log::error($e->getMessage(), null, __METHOD__); } return false; }
/** * Performs new thread with first post creation and subscription. * @return boolean * @since 0.2 */ public function podiumNew() { $transaction = static::getDb()->beginTransaction(); try { if ($this->save()) { $this->forum->updateCounters(['threads' => 1]); $post = new Post(); $post->content = $this->post; $post->thread_id = $this->id; $post->forum_id = $this->forum_id; $post->author_id = User::loggedId(); $post->likes = 0; $post->dislikes = 0; if ($post->save()) { $post->markSeen(); $this->forum->updateCounters(['posts' => 1]); $this->updateCounters(['posts' => 1]); $this->touch('new_post_at'); $this->touch('edited_post_at'); if ($this->subscribe) { $subscription = new Subscription(); $subscription->user_id = User::loggedId(); $subscription->thread_id = $this->id; $subscription->post_seen = Subscription::POST_SEEN; $subscription->save(); } } } $transaction->commit(); Cache::clearAfter('newThread'); Log::info('Thread added', $this->id, __METHOD__); return true; } catch (Exception $e) { $transaction->rollBack(); Log::error($e->getMessage(), null, __METHOD__); } return false; }
/** * Deleting the forum of given ID. * @param integer $cid parent category ID * @param integer $id forum ID * @return \yii\web\Response */ public function actionDeleteForum($cid = null, $id = null) { if (!User::can(Rbac::PERM_DELETE_FORUM)) { $this->error(Yii::t('podium/flash', 'You are not allowed to perform this action.')); } else { $model = Forum::find()->where(['id' => $id, 'category_id' => $cid])->limit(1)->one(); if (empty($model)) { $this->error(Yii::t('podium/flash', 'Sorry! We can not find Forum with this ID.')); } else { if ($model->delete()) { Cache::clearAfter('forumDelete'); Log::info('Forum deleted', $model->id, __METHOD__); $this->success(Yii::t('podium/flash', 'Forum has been deleted.')); } else { Log::error('Error while deleting forum', $model->id, __METHOD__); $this->error(Yii::t('podium/flash', 'Sorry! There was some error while deleting the forum.')); } } } return $this->redirect(['admin/forums', 'cid' => $cid]); }