BookStack/app/Auth/Access/EmailConfirmationService.php

40 lines
1.1 KiB
PHP
Raw Normal View History

<?php namespace BookStack\Auth\Access;
use BookStack\Auth\User;
use BookStack\Exceptions\ConfirmationEmailException;
use BookStack\Notifications\ConfirmEmail;
2019-08-17 16:52:33 +02:00
class EmailConfirmationService extends UserTokenService
{
2019-08-17 16:52:33 +02:00
protected $tokenTable = 'email_confirmations';
protected $expiryTime = 24;
/**
* Create new confirmation for a user,
* Also removes any existing old ones.
2019-08-17 16:52:33 +02:00
* @param User $user
* @throws ConfirmationEmailException
*/
public function sendConfirmation(User $user)
{
if ($user->email_confirmed) {
2016-12-04 17:51:39 +01:00
throw new ConfirmationEmailException(trans('errors.email_already_confirmed'), '/login');
}
2019-08-17 16:52:33 +02:00
$this->deleteByUser($user);
$token = $this->createTokenForUser($user);
$user->notify(new ConfirmEmail($token));
}
/**
* Check if confirmation is required in this instance.
* @return bool
*/
public function confirmationRequired() : bool
{
return setting('registration-confirmation')
|| setting('registration-restrict');
}
}