2018-09-25 13:30:50 +02:00
|
|
|
<?php namespace BookStack\Auth\Access;
|
2015-09-05 21:25:57 +02:00
|
|
|
|
2018-09-25 17:58:03 +02:00
|
|
|
use BookStack\Auth\User;
|
2015-09-10 20:31:09 +02:00
|
|
|
use BookStack\Exceptions\ConfirmationEmailException;
|
2018-09-25 17:58:03 +02:00
|
|
|
use BookStack\Notifications\ConfirmEmail;
|
2015-09-05 21:25:57 +02:00
|
|
|
|
2019-08-17 16:52:33 +02:00
|
|
|
class EmailConfirmationService extends UserTokenService
|
2015-09-05 21:25:57 +02:00
|
|
|
{
|
2019-08-17 16:52:33 +02:00
|
|
|
protected $tokenTable = 'email_confirmations';
|
|
|
|
protected $expiryTime = 24;
|
2015-09-05 21:25:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create new confirmation for a user,
|
|
|
|
* Also removes any existing old ones.
|
2019-08-17 16:52:33 +02:00
|
|
|
* @param User $user
|
2015-09-05 21:25:57 +02:00
|
|
|
* @throws ConfirmationEmailException
|
|
|
|
*/
|
|
|
|
public function sendConfirmation(User $user)
|
|
|
|
{
|
2015-09-06 13:14:32 +02:00
|
|
|
if ($user->email_confirmed) {
|
2016-12-04 17:51:39 +01:00
|
|
|
throw new ConfirmationEmailException(trans('errors.email_already_confirmed'), '/login');
|
2015-09-05 21:25:57 +02:00
|
|
|
}
|
2016-09-17 19:22:04 +02:00
|
|
|
|
2019-08-17 16:52:33 +02:00
|
|
|
$this->deleteByUser($user);
|
|
|
|
$token = $this->createTokenForUser($user);
|
2016-09-17 19:22:04 +02:00
|
|
|
|
|
|
|
$user->notify(new ConfirmEmail($token));
|
|
|
|
}
|
|
|
|
|
2019-08-18 11:47:59 +02:00
|
|
|
/**
|
|
|
|
* Check if confirmation is required in this instance.
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function confirmationRequired() : bool
|
|
|
|
{
|
|
|
|
return setting('registration-confirmation')
|
|
|
|
|| setting('registration-restrict');
|
|
|
|
}
|
2018-01-28 17:58:52 +01:00
|
|
|
}
|