]> BookStack Code Mirror - bookstack/blob - app/Access/UserInviteService.php
Lexical: Fixed code in lists, removed extra old alignment code
[bookstack] / app / Access / UserInviteService.php
1 <?php
2
3 namespace BookStack\Access;
4
5 use BookStack\Access\Notifications\UserInviteNotification;
6 use BookStack\Users\Models\User;
7
8 class UserInviteService extends UserTokenService
9 {
10     protected string $tokenTable = 'user_invites';
11     protected int $expiryTime = 336; // Two weeks
12
13     /**
14      * Send an invitation to a user to sign into BookStack
15      * Removes existing invitation tokens.
16      * @throws UserInviteException
17      */
18     public function sendInvitation(User $user)
19     {
20         $this->deleteByUser($user);
21         $token = $this->createTokenForUser($user);
22
23         try {
24             $user->notify(new UserInviteNotification($token));
25         } catch (\Exception $exception) {
26             throw new UserInviteException($exception->getMessage(), $exception->getCode(), $exception);
27         }
28     }
29 }