]> BookStack Code Mirror - bookstack/blob - app/Auth/Access/EmailConfirmationService.php
Added force option for update-url command
[bookstack] / app / Auth / Access / EmailConfirmationService.php
1 <?php
2
3 namespace BookStack\Auth\Access;
4
5 use BookStack\Auth\User;
6 use BookStack\Exceptions\ConfirmationEmailException;
7 use BookStack\Notifications\ConfirmEmail;
8
9 class EmailConfirmationService extends UserTokenService
10 {
11     protected string $tokenTable = 'email_confirmations';
12     protected int $expiryTime = 24;
13
14     /**
15      * Create new confirmation for a user,
16      * Also removes any existing old ones.
17      *
18      * @throws ConfirmationEmailException
19      */
20     public function sendConfirmation(User $user)
21     {
22         if ($user->email_confirmed) {
23             throw new ConfirmationEmailException(trans('errors.email_already_confirmed'), '/login');
24         }
25
26         $this->deleteByUser($user);
27         $token = $this->createTokenForUser($user);
28
29         $user->notify(new ConfirmEmail($token));
30     }
31
32     /**
33      * Check if confirmation is required in this instance.
34      */
35     public function confirmationRequired(): bool
36     {
37         return setting('registration-confirmation')
38             || setting('registration-restrict');
39     }
40 }