commit 993c0b7bf80797b107f5ca43ccb42f2c012634fb from: Tracey Emery date: Thu May 12 14:12:52 2022 UTC add two factor authentication for members who have not used the site for 24 hours. really fix the 10 minute mark commit - a6db4a20d5b9d856a54376cecd639369f64411f3 commit + 993c0b7bf80797b107f5ca43ccb42f2c012634fb blob - e0b3b628851baabd27d7ae763adc09852642b035 blob + c20696d45ab25f3bf424bdd66170aec79aa50537 --- module/Securitx/src/Controller/SecuritxController.php +++ module/Securitx/src/Controller/SecuritxController.php @@ -14,6 +14,7 @@ use Securitx\Form\UploaderForm; use Securitx\Form\CompanyForm; use Securitx\Form\ForgotForm; use Securitx\Form\SendForm; +use Securitx\Form\TwofaForm; use Laminas\Mvc\InjectApplicationEventInterface; use Laminas\Mvc\Controller\AbstractActionController; @@ -62,7 +63,7 @@ class SecuritxController extends AbstractActionControl if (!$member || !$member->verified) return $this->redirect()->toRoute('securitx'); if ((time() - $member->moddate) > 60 * 60 * 24) { - if ((time() - $member->twofa_moddate) > 60 * 60 * 10 || + if ((time() - $member->twofa_moddate) > 60 * 10 || !$member->twofa_moddate) { $member->twofa = rand(1000000, 9999999); $member->twofa_moddate = time(); @@ -470,19 +471,6 @@ class SecuritxController extends AbstractActionControl ]); } } - public function twofaAction() { - $member = new Member('member'); - $id = $this->params()->fromRoute('id'); - - try { - $member = $this->member_table->getVMember($id); - } catch (\InvalidArgumentException $ex) { - return $this->redirect()->toRoute('securitx'); - } - return new ViewModel([ - 'member' => $member, - ]); - } public function requestadminAction() { if (!$this->checkAnyAdmin()) return $this->redirect()->toRoute('securitx'); @@ -804,6 +792,68 @@ class SecuritxController extends AbstractActionControl } } + public function twofaAction() { + $member = new Member('member'); + $id = $this->params()->fromRoute('id'); + + try { + $member = $this->member_table->getVMember($id); + } catch (\InvalidArgumentException $ex) { + return $this->redirect()->toRoute('securitx'); + } + + $form = new TwofaForm(); + if ((time() - $member->twofa_moddate) > 60 * 10) + $expired = true; + else + $expired = false; + $request = $this->getRequest(); + if (!$request->isPost()) { + return new ViewModel([ + 'member' => $member, + 'valid' => '', + 'expired' => $expired, + 'form' => $form, + ]); + } + $form->setData($request->getPost()); + if (!$form->isValid()) { + return new ViewModel([ + 'member' => $member, + 'valid' => '', + 'expired' => $expired, + 'form' => $form, + ]); + } + $data = $form->getData(); + if (!$data['code']) { + return new ViewModel([ + 'member' => $member, + 'valid' => 'A code is required', + 'expired' => $expired, + 'form' => $form, + ]); + } + if($data['code'] != $member->twofa) { + return new ViewModel([ + 'member' => $member, + 'valid' => 'Incorrect code', + 'expired' => $expired, + 'form' => $form, + ]); + } else { + $member->moddate = time(); + $member->twofa = ''; + $member->twofa_moddate = ''; + $this->member_table->saveMember($member); + return $this->redirect()->toRoute('securitx', + array( + 'action' => 'home', + 'id' => $member->u_key, + ) + ); + } + } public function requestAction() { if (!$this->checkAnyAdmin()) return $this->redirect()->toRoute('securitx'); blob - /dev/null blob + 5e0ff4cfdbcdc7be147ebd81461c79c8d59d48f7 (mode 644) --- /dev/null +++ module/Securitx/src/Form/TwofaForm.php @@ -0,0 +1,28 @@ +add([ + 'name' => 'code', + 'type' => 'text', + 'options' => [ + 'label' => 'Verification code', + ], + ]); + $this->add([ + 'name' => 'submit', + 'type' => 'submit', + 'attributes' => [ + 'value' => 'Verify Code', + 'id' => 'submitbutton', + ], + ]); + } +} blob - 7931b5775fa1ded4b911dba83e096545f8bb214e blob + ea243b9c8111572072235ebedeb7ab6077303f55 --- module/Securitx/view/securitx/home/home.phtml +++ module/Securitx/view/securitx/home/home.phtml @@ -29,8 +29,8 @@ if ($has_domain && !$member->r_admin && !$member->r_editor && !$member->is_admin && !$member->is_editor) { echo "You are an employee of the company. Please request an action below."; } - if ($has_domain && !$member->is_admin && !$member->is_editor) { - echo "Please wait for an administrator to review your request"; + if ($has_domain && !$member->is_admin && !$member->is_editor && ($member->r_admin || $member->r_editor)) { + echo "
Please wait for an administrator to review your request"; } if (!$member->is_admin && !$member->is_editor && !$has_domain) { ?>

Upload files to »

blob - 4f61cec26348400ff9ca32726e54cc546119d9f1 blob + 7d998b470d399af9657c04d176ca1e407ff3a603 --- module/Securitx/view/securitx/twofa/twofa.phtml +++ module/Securitx/view/securitx/twofa/twofa.phtml @@ -7,4 +7,35 @@

Hello, first ?>,
Please enter the code that was emailed to you.
If you have not received the email, check your Junk folder.


+get('code'); + $code->setAttribute('class', 'form-control'); + $code->setAttribute('placeholder', 'Please enter the code you received'); + + $submit = $form->get('submit'); + $submit->setAttribute('class', 'btn btn-primary'); + + $form->setAttribute('action', $this->url('securitx', + ['action' => 'twofa', 'id'=> $member->u_key])); + $form->prepare(); + + echo $this->form()->openTag($form); + if (!$expired) { +?> +
+ formLabel($code) ?> + formElement($code) ?> + formElementErrors()->render($code, + ['class' => 'help-block']) ?> +
+

+
+ formSubmit($form->get('submit')) ?> +
+

Go home

+u_key\">click here to receive a new code."; + } +?>