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 $tokenTable = 'email_confirmations';
12 protected $expiryTime = 24;
15 * Create new confirmation for a user,
16 * Also removes any existing old ones.
20 * @throws ConfirmationEmailException
22 public function sendConfirmation(User $user)
24 if ($user->email_confirmed) {
25 throw new ConfirmationEmailException(trans('errors.email_already_confirmed'), '/login');
28 $this->deleteByUser($user);
29 $token = $this->createTokenForUser($user);
31 $user->notify(new ConfirmEmail($token));
35 * Check if confirmation is required in this instance.
39 public function confirmationRequired(): bool
41 return setting('registration-confirmation')
42 || setting('registration-restrict');