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.')); ?> +