]> BookStack Code Mirror - bookstack/blob - app/Auth/Access/EmailConfirmationService.php
Cleaned some unused elements during testing
[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 $tokenTable = 'email_confirmations';
12     protected $expiryTime = 24;
13
14     /**
15      * Create new confirmation for a user,
16      * Also removes any existing old ones.
17      * @throws ConfirmationEmailException
18      */
19     public function sendConfirmation(User $user)
20     {
21         if ($user->email_confirmed) {
22             throw new ConfirmationEmailException(trans('errors.email_already_confirmed'), '/login');
23         }
24
25         $this->deleteByUser($user);
26         $token = $this->createTokenForUser($user);
27
28         $user->notify(new ConfirmEmail($token));
29     }
30
31     /**
32      * Check if confirmation is required in this instance.
33      */
34     public function confirmationRequired(): bool
35     {
36         return setting('registration-confirmation')
37             || setting('registration-restrict');
38     }
39 }