From cc7f3915833f8894f3302107cad8d297a5327a40 Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Tue, 4 Oct 2022 14:44:29 +0200 Subject: [PATCH] fixup! Testing the addition of email auth to login --- lib/Provider/AtLoginProvider.php | 13 ++++++++----- templates/error_email_empty.php | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 templates/error_email_empty.php diff --git a/lib/Provider/AtLoginProvider.php b/lib/Provider/AtLoginProvider.php index 19b8285..8318c48 100644 --- a/lib/Provider/AtLoginProvider.php +++ b/lib/Provider/AtLoginProvider.php @@ -19,7 +19,7 @@ class AtLoginProvider implements ILoginSetupProvider { private $myUser; /** @var EmailService */ - private $EmailService; + private $emailService; /** @var OCCONFIG */ private $occonfig; @@ -36,7 +36,7 @@ class AtLoginProvider implements ILoginSetupProvider { public function __construct(IUser $myUser, $mySecret, EmailService $EmailService, OCCONFIG $occonfig, IRegistry $registry, Email $provider, StateStorage $stateStorage) { $this->myUser = $myUser; $this->mySecret = $mySecret; - $this->EmailService = $EmailService; + $this->emailService = $EmailService; $this->occonfig = $occonfig; $this->registry = $registry; $this->provider = $provider; @@ -47,14 +47,17 @@ private function setEnabledActivity() { $isEnforced = $this->occonfig->getSystemValue('twofactor_enforced'); if ($isEnforced) { $this->registry->enableProviderFor($this->provider, $this->myUser); + $state = new State($this->myUser, EmailProvider::STATE_ENABLED); + $this->stateStorage->persist($state->verify()); } - $state = new State($this->myUser, EmailProvider::STATE_ENABLED); - $this->stateStorage->persist($state->verify()); } public function getBody(): Template { + if($this->myUser->getEMailAddress() === null) { + return new Template('twofactor_email', 'error_email_empty'); + } try { - $this->EmailService->send($this->myUser, $this->mySecret); + $this->emailService->send($this->myUser, $this->mySecret); } catch (\Exception $ex) { return new Template('twofactor_email', 'error'); } diff --git a/templates/error_email_empty.php b/templates/error_email_empty.php new file mode 100644 index 0000000..0127896 --- /dev/null +++ b/templates/error_email_empty.php @@ -0,0 +1,3 @@ +
+ t('Error: you do not have an email address set. Please use a different 2FA method or ask your administrator to set up your email address for you.')); ?> +