diff --git a/PageProtector.module.php b/PageProtector.module.php index d206b09..7810f65 100644 --- a/PageProtector.module.php +++ b/PageProtector.module.php @@ -288,43 +288,102 @@ public function protectedCheck(HookEvent $event) { } elseif($this->wire('input')->post->username && $this->wire('input')->post->pass) { $username = $this->wire('sanitizer')->username($this->wire('input')->post->username); - $user = $this->wire('session')->login($username, $this->wire('input')->post->pass); - if(!$user) $this->wire('session')->loginFailed = true; - $this->wire('session')->redirect(htmlspecialchars($_SERVER['REQUEST_URI'])); + $user = $this->wire('users')->get($username); + $has_tfa = false; + + // if the user exist, override the $has_tfa var with a not dummy value + if ($user->id) { + $has_tfa = $user->hasTfa(); + } + + if (!empty($has_tfa)) { + // $tfa = $this->wire('modules')->get('ProcessLogin')->getTfa(); + $tfa = $user->hasTfa(true); + // get the actual Tfa instance we need + $this->wire('session')->loginFailed = !$tfa->start($username, $this->wire('input')->post->pass); + if ($this->wire('session')->loginFailed) { + $this->wire('session')->redirect(htmlspecialchars($_SERVER['REQUEST_URI'])); + } + //tfa login supercedes normal login function + } + else { + $user = $this->wire('session')->login($username, $this->wire('input')->post->pass); + if(!$user) $this->wire('session')->loginFailed = true; + $this->wire('session')->redirect(htmlspecialchars($_SERVER['REQUEST_URI'])); + } } else { - $loginForm = " - -
- "; + $tfa = $this->wire('modules')->get('ProcessLogin')->getTfa(); - if($this->wire('session')->loginFailed) $this->wire('session')->loginFailed = false; - - if($this->data['login_template'] == '') { - $event->return = " - - - - - - -