3 namespace BookStack\Auth\Access;
5 use BookStack\Auth\User;
6 use BookStack\Exceptions\ConfirmationEmailException;
7 use BookStack\Notifications\ConfirmEmail;
9 class EmailConfirmationService extends UserTokenService
11 protected string $tokenTable = 'email_confirmations';
12 protected int $expiryTime = 24;
15 * Create new confirmation for a user,
16 * Also removes any existing old ones.
18 * @throws ConfirmationEmailException
20 public function sendConfirmation(User $user)
22 if ($user->email_confirmed) {
23 throw new ConfirmationEmailException(trans('errors.email_already_confirmed'), '/login');
26 $this->deleteByUser($user);
27 $token = $this->createTokenForUser($user);
29 $user->notify(new ConfirmEmail($token));
33 * Check if confirmation is required in this instance.
35 public function confirmationRequired(): bool
37 return setting('registration-confirmation')
38 || setting('registration-restrict');