Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve AuthEmailNotVerified exception. #3700

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions module/VuFind/src/VuFind/Auth/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,10 @@ protected function checkEmailVerified($user)
$config = $this->getConfig();
$verify_email = $config->Authentication->verify_email ?? false;
if ($verify_email && !$user->checkEmailVerified()) {
$exception = new AuthEmailNotVerifiedException(
throw new AuthEmailNotVerifiedException(
$user,
'authentication_error_email_not_verified_html'
);
$exception->user = $user;
throw $exception;
}
}

Expand Down
6 changes: 3 additions & 3 deletions module/VuFind/src/VuFind/Controller/MyResearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ protected function processAuthenticationException(AuthException $e)
return;
}
if ($e instanceof AuthEmailNotVerifiedException) {
$this->sendFirstVerificationEmail($e->user);
$this->sendFirstVerificationEmail($e->getUser());
if ($msg == 'authentication_error_email_not_verified_html') {
$this->getUserVerificationContainer()->user = $e->user->username;
$this->getUserVerificationContainer()->user = $e->getUser()->getUsername();
$url = $this->url()->fromRoute('myresearch-emailnotverified')
. '?reverify=true';
$msg = [
Expand Down Expand Up @@ -290,7 +290,7 @@ public function accountAction()
$this->getAuthManager()->create($this->getRequest());
return $this->forwardTo('MyResearch', 'Home');
} catch (AuthEmailNotVerifiedException $e) {
$this->sendFirstVerificationEmail($e->user);
$this->sendFirstVerificationEmail($e->getUser());
return $this->redirect()->toRoute('myresearch-emailnotverified');
} catch (AuthException $e) {
$this->flashMessenger()->addMessage($e->getMessage(), 'error');
Expand Down
29 changes: 26 additions & 3 deletions module/VuFind/src/VuFind/Exception/AuthEmailNotVerified.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

namespace VuFind\Exception;

use Throwable;
use VuFind\Db\Entity\UserEntityInterface;

/**
* Unverified email address exception.
*
Expand All @@ -41,9 +44,29 @@
class AuthEmailNotVerified extends \VuFind\Exception\Auth
{
/**
* User object with unverified email.
* Constructor
*
* @param UserEntityInterface $user User object with unverified email.
* @param string $message The exception message
* @param int $code The exception code
* @param ?Throwable $previous The previous exception used for exception chaining
*/
public function __construct(
protected UserEntityInterface $user,
string $message = '',
int $code = 0,
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}

/**
* Get the User object with an unverified email.
*
* @var \VuFind\Db\Row\User
* @return UserEntityInterface
*/
public $user;
public function getUser(): UserEntityInterface
{
return $this->user;
}
}
Loading