Created
April 23, 2017 09:35
-
-
Save sminnee/2d09c2efc7f460f5b9b81373af0222ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/mysite/code/CustomAuthenticator.php b/mysite/code/CustomAuthenticator.php | |
| new file mode 100644 | |
| index 0000000..141a9f1 | |
| --- /dev/null | |
| +++ b/mysite/code/CustomAuthenticator.php | |
| @@ -0,0 +1,14 @@ | |
| +<?php | |
| + | |
| +use SilverStripe\Security\MemberAuthenticator\Authenticator; | |
| + | |
| +class CustomAuthenticator extends Authenticator | |
| +{ | |
| + /** | |
| + * @inherit | |
| + */ | |
| + public function getLoginHandler($link) | |
| + { | |
| + return CustomLoginHandler::create($link, $this); | |
| + } | |
| +} | |
| diff --git a/mysite/code/CustomLoginHandler.php b/mysite/code/CustomLoginHandler.php | |
| new file mode 100644 | |
| index 0000000..435a7fa | |
| --- /dev/null | |
| +++ b/mysite/code/CustomLoginHandler.php | |
| @@ -0,0 +1,58 @@ | |
| +<?php | |
| + | |
| +use SilverStripe\Security\MemberAuthenticator\LoginHandler; | |
| + | |
| +class CustomLoginHandler extends LoginHandler | |
| +{ | |
| + | |
| + private static $allowed_actions = [ | |
| + 'step2', | |
| + 'secondStepForm', | |
| + ]; | |
| + | |
| + public function doLogin($data, $formHandler) | |
| + { | |
| + die('here'); | |
| + if($member = $this->checkLogin($data)) { | |
| + Session::set('CustomLoginHandler.Member', $member); | |
| + $this->redirect($this->link('step2')); | |
| + } | |
| + | |
| + // Fail to login redirects back to form | |
| + return $formHandler->redirectBackToForm(); | |
| + } | |
| + | |
| + public function step2() | |
| + { | |
| + return [ | |
| + "Form" => $this->secondStepForm() | |
| + ]; | |
| + } | |
| + | |
| + public function secondStepForm() | |
| + { | |
| + return new Form( | |
| + $this, | |
| + "secondStepForm", | |
| + new FieldList( | |
| + new TextField('SecondFactor', 'Your 2FA (12345)') | |
| + ), | |
| + new FieldList( | |
| + new FormAction('completeSecondStep', 'Login in') | |
| + ) | |
| + ); | |
| + } | |
| + | |
| + public function completeSecondStep($data, $formHandler) | |
| + { | |
| + if ($this->checkSecondFactor($data)) { | |
| + $member = Session::get('CustomLoginHandler.Member', $member); | |
| + $this->performLogin($member); | |
| + $this->redirectAfterSuccessfulLogin(); | |
| + } | |
| + | |
| + | |
| + // Fail to login redirects back to form | |
| + return $formHandler->redirectBackToForm(); | |
| + } | |
| +} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment