/** * {@inheritdoc} */ protected function conditions(AbstractSearch $search, array $matches, $negate) { if (!$search instanceof UserSearch) { throw new LogicException('This gambit can only be applied on a UserSearch'); } $email = trim($matches[1], '"'); $user = $this->users->findByEmail($email); $search->getQuery()->where('id', $negate ? '!=' : '=', $user->id); }
/** * @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; }
/** * @param mixed $command * @param Closure $next */ public function handle($command, $next) { // Check if a command we want to hook. if ($command instanceof RequestPasswordReset) { // Find the user account requesting reset. $user = $this->users->findByEmail($command->email); // Only handle is user exists and is a singleso user. // Let the core handle unrecognized users and local only accounts. if ($user && isset($user->singleso_id)) { // Throw exception for the user to prevent reset. throw new ValidationException(['SingleSO: Direct password resetting disabled.']); } } // Continue on. return $next($command); }
/** * @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]), '{forum}' => $this->settings->get('forum_title')]; $body = $this->translator->trans('core.email.reset_password.body', $data); $this->mailer->raw($body, function (Message $message) use($user, $data) { $message->to($user->email); $message->subject('[' . $data['{forum}'] . '] ' . $this->translator->trans('core.email.reset_password.subject')); }); return $user; }