]> BookStack Code Mirror - bookstack/blob - app/Auth/Access/EmailConfirmationService.php
Apply fixes from StyleCI
[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      *
18      * @param User $user
19      *
20      * @throws ConfirmationEmailException
21      */
22     public function sendConfirmation(User $user)
23     {
24         if ($user->email_confirmed) {
25             throw new ConfirmationEmailException(trans('errors.email_already_confirmed'), '/login');
26         }
27
28         $this->deleteByUser($user);
29         $token = $this->createTokenForUser($user);
30
31         $user->notify(new ConfirmEmail($token));
32     }
33
34     /**
35      * Check if confirmation is required in this instance.
36      *
37      * @return bool
38      */
39     public function confirmationRequired(): bool
40     {
41         return setting('registration-confirmation')
42             || setting('registration-restrict');
43     }
44 }