1 <?php namespace BookStack\Auth\Access;
3 use BookStack\Auth\User;
4 use BookStack\Exceptions\ConfirmationEmailException;
5 use BookStack\Notifications\ConfirmEmail;
7 class EmailConfirmationService extends UserTokenService
9 protected $tokenTable = 'email_confirmations';
10 protected $expiryTime = 24;
13 * Create new confirmation for a user,
14 * Also removes any existing old ones.
16 * @throws ConfirmationEmailException
18 public function sendConfirmation(User $user)
20 if ($user->email_confirmed) {
21 throw new ConfirmationEmailException(trans('errors.email_already_confirmed'), '/login');
24 $this->deleteByUser($user);
25 $token = $this->createTokenForUser($user);
27 $user->notify(new ConfirmEmail($token));
31 * Check if confirmation is required in this instance.
34 public function confirmationRequired() : bool
36 return setting('registration-confirmation')
37 || setting('registration-restrict');