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