2021-06-26 11:23:15 -04:00
|
|
|
<?php
|
|
|
|
|
2023-05-17 12:56:55 -04:00
|
|
|
namespace BookStack\Access;
|
2019-08-17 10:52:33 -04:00
|
|
|
|
2023-09-11 14:26:28 -04:00
|
|
|
use BookStack\Access\Notifications\UserInviteNotification;
|
2023-05-17 12:56:55 -04:00
|
|
|
use BookStack\Users\Models\User;
|
2019-08-17 10:52:33 -04:00
|
|
|
|
|
|
|
class UserInviteService extends UserTokenService
|
|
|
|
{
|
2023-04-04 05:44:38 -04:00
|
|
|
protected string $tokenTable = 'user_invites';
|
|
|
|
protected int $expiryTime = 336; // Two weeks
|
2019-08-17 10:52:33 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send an invitation to a user to sign into BookStack
|
|
|
|
* Removes existing invitation tokens.
|
2024-09-29 11:41:18 -04:00
|
|
|
* @throws UserInviteException
|
2019-08-17 10:52:33 -04:00
|
|
|
*/
|
|
|
|
public function sendInvitation(User $user)
|
|
|
|
{
|
|
|
|
$this->deleteByUser($user);
|
|
|
|
$token = $this->createTokenForUser($user);
|
2024-09-29 11:41:18 -04:00
|
|
|
|
|
|
|
try {
|
|
|
|
$user->notify(new UserInviteNotification($token));
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
throw new UserInviteException($exception->getMessage(), $exception->getCode(), $exception);
|
|
|
|
}
|
2019-08-17 10:52:33 -04:00
|
|
|
}
|
|
|
|
}
|