mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
d12e8ec923
Added specific handling to show relevant error message when user creation fails due to invite sending errors, while also returning user to the form with previous input. Includes test to cover. For #5195
30 lines
817 B
PHP
30 lines
817 B
PHP
<?php
|
|
|
|
namespace BookStack\Access;
|
|
|
|
use BookStack\Access\Notifications\UserInviteNotification;
|
|
use BookStack\Users\Models\User;
|
|
|
|
class UserInviteService extends UserTokenService
|
|
{
|
|
protected string $tokenTable = 'user_invites';
|
|
protected int $expiryTime = 336; // Two weeks
|
|
|
|
/**
|
|
* Send an invitation to a user to sign into BookStack
|
|
* Removes existing invitation tokens.
|
|
* @throws UserInviteException
|
|
*/
|
|
public function sendInvitation(User $user)
|
|
{
|
|
$this->deleteByUser($user);
|
|
$token = $this->createTokenForUser($user);
|
|
|
|
try {
|
|
$user->notify(new UserInviteNotification($token));
|
|
} catch (\Exception $exception) {
|
|
throw new UserInviteException($exception->getMessage(), $exception->getCode(), $exception);
|
|
}
|
|
}
|
|
}
|