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.
17 * @throws ConfirmationEmailException
19 public function sendConfirmation(User $user)
21 if ($user->email_confirmed) {
22 throw new ConfirmationEmailException(trans('errors.email_already_confirmed'), '/login');
25 $this->deleteByUser($user);
26 $token = $this->createTokenForUser($user);
28 $user->notify(new ConfirmEmail($token));
32 * Check if confirmation is required in this instance.
34 public function confirmationRequired(): bool
36 return setting('registration-confirmation')
37 || setting('registration-restrict');