/** * @param User $actor * @param Discussion $discussion * @return bool|null */ public function rename(User $actor, Discussion $discussion) { if ($discussion->start_user_id == $actor->id) { $allowRenaming = $this->settings->get('allow_renaming'); if ($allowRenaming === '-1' || $allowRenaming === 'reply' && $discussion->participants_count <= 1 || $discussion->start_time->diffInMinutes(new Carbon()) < $allowRenaming) { return true; } } }
/** * {@inheritdoc} */ public function handle(ServerRequestInterface $request) { $this->assertAdmin($request->getAttribute('actor')); $settings = $request->getParsedBody(); foreach ($settings as $k => $v) { $this->dispatcher->fire(new PrepareSerializedSetting($k, $v)); $this->settings->set($k, $v); $this->dispatcher->fire(new SettingWasSet($k, $v)); } return new EmptyResponse(204); }
/** * @param RequestPasswordReset $command * @return \Flarum\Core\User * @throws ModelNotFoundException */ public function handle(RequestPasswordReset $command) { $user = $this->users->findByEmail($command->email); if (!$user) { throw new ModelNotFoundException(); } $token = PasswordToken::generate($user->id); $token->save(); $data = ['username' => $user->username, 'url' => $this->url->toRoute('resetPassword', ['token' => $token->id]), 'forumTitle' => $this->settings->get('forum_title')]; $this->mailer->send(['text' => 'flarum::emails.resetPassword'], $data, function (Message $message) use($user) { $message->to($user->email); $message->subject('Reset Your Password'); }); return $user; }
/** * Get the data that should be made available to email templates. * * @param User $user * @param string $email * * @return array */ protected function getEmailData(User $user, $email) { $token = $this->generateToken($user, $email); // TODO: Need to use AbstractUrlGenerator, but since this is part of core we // don't know that the forum routes will be loaded. Should the confirm // email route be part of core?? return ['username' => $user->username, 'url' => $this->url->toRoute('confirmEmail', ['token' => $token->id]), 'forumTitle' => $this->settings->get('forum_title')]; }
/** * {@inheritdoc} */ protected function getDefaultAttributes($model) { $gate = $this->gate->forUser($this->actor); $attributes = ['title' => $this->settings->get('forum_title'), 'description' => $this->settings->get('forum_description'), 'baseUrl' => $url = $this->app->url(), 'basePath' => parse_url($url, PHP_URL_PATH) ?: '', 'debug' => $this->app->inDebugMode(), 'apiUrl' => $this->app->url('api'), 'welcomeTitle' => $this->settings->get('welcome_title'), 'welcomeMessage' => $this->settings->get('welcome_message'), 'themePrimaryColor' => $this->settings->get('theme_primary_color'), 'allowSignUp' => (bool) $this->settings->get('allow_sign_up'), 'defaultRoute' => $this->settings->get('default_route'), 'canViewDiscussions' => $gate->allows('viewDiscussions'), 'canStartDiscussion' => $gate->allows('startDiscussion')]; if ($gate->allows('administrate')) { $attributes['adminUrl'] = $this->app->url('admin'); $attributes['version'] = $this->app->version(); } return $attributes; }
/** * @param RegisterUser $command * @throws PermissionDeniedException if signup is closed and the actor is * not an administrator. * @throws \Flarum\Core\Exception\InvalidConfirmationTokenException if an * email confirmation token is provided but is invalid. * @return User */ public function handle(RegisterUser $command) { $actor = $command->actor; $data = $command->data; if (!$this->settings->get('allow_sign_up')) { $this->assertAdmin($actor); } $username = array_get($data, 'attributes.username'); $email = array_get($data, 'attributes.email'); $password = array_get($data, 'attributes.password'); // If a valid authentication token was provided as an attribute, // then we won't require the user to choose a password. if (isset($data['attributes']['token'])) { $token = AuthToken::validOrFail($data['attributes']['token']); $password = $password ?: str_random(20); } $user = User::register($username, $email, $password); // If a valid authentication token was provided, then we will assign // the attributes associated with it to the user's account. If this // includes an email address, then we will activate the user's account // from the get-go. if (isset($token)) { foreach ($token->payload as $k => $v) { $user->{$k} = $v; } if (isset($token->payload['email'])) { $user->activate(); } } $this->events->fire(new UserWillBeSaved($user, $actor, $data)); $this->validator->assertValid(array_merge($user->getAttributes(), compact('password'))); $user->save(); if (isset($token)) { $token->delete(); } $this->dispatchEventsFor($user, $actor); return $user; }
/** * @param User $actor * @param Post $post * @return bool|null */ public function edit(User $actor, Post $post) { if ($this->discussionAllows($actor, 'edit', $post)) { return true; } // A post is allowed to be edited if the user has permission to moderate // the discussion which it's in, or if they are the author and the post // hasn't been deleted by someone else. if ($post->user_id == $actor->id && (!$post->hide_time || $post->hide_user_id == $actor->id)) { $allowEditing = $this->settings->get('allow_post_editing'); if ($allowEditing === '-1' || $allowEditing === 'reply' && $post->number >= $post->discussion->last_post_number || $post->time->diffInMinutes(new Carbon()) < $allowEditing) { return true; } } }
/** * Get the values of any LESS variables to compile into the CSS, based on * the forum's configuration. * * @return array */ protected function getLessVariables() { return ['config-primary-color' => $this->settings->get('theme_primary_color') ?: '#000', 'config-secondary-color' => $this->settings->get('theme_secondary_color') ?: '#000', 'config-dark-mode' => $this->settings->get('theme_dark_mode') ? 'true' : 'false', 'config-colored-header' => $this->settings->get('theme_colored_header') ? 'true' : 'false']; }