1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Firesphere\YubiAuth\Forms; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Control\RequestHandler; |
6
|
|
|
use SilverStripe\Forms\FieldList; |
7
|
|
|
use SilverStripe\Forms\FormAction; |
8
|
|
|
use SilverStripe\Forms\HiddenField; |
9
|
|
|
use SilverStripe\Forms\PasswordField; |
10
|
|
|
use SilverStripe\Forms\RequiredFields; |
11
|
|
|
use SilverStripe\Security\LoginForm; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class YubikeyForm |
15
|
|
|
* @package Firesphere\YubiAuth\Forms |
16
|
|
|
*/ |
17
|
|
|
class YubikeyForm extends LoginForm |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* YubikeyForm constructor. |
21
|
|
|
* @param RequestHandler|null $controller |
22
|
|
|
* @param string $name |
23
|
|
|
*/ |
24
|
|
|
public function __construct( |
25
|
|
|
RequestHandler $controller = null, |
26
|
|
|
$name = self::DEFAULT_NAME |
27
|
|
|
) { |
28
|
|
|
$this->controller = $controller; |
29
|
|
|
$fields = $this->getFormFields(); |
30
|
|
|
$actions = $this->getFormActions(); |
31
|
|
|
$validator = RequiredFields::create(['yubiauth']); |
32
|
|
|
|
33
|
|
|
parent::__construct($controller, $name, $fields, $actions, $validator); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return FieldList|static |
38
|
|
|
*/ |
39
|
|
|
public function getFormFields() |
40
|
|
|
{ |
41
|
|
|
$fields = FieldList::create( |
42
|
|
|
[ |
43
|
|
|
PasswordField::create( |
44
|
|
|
'yubiauth', |
45
|
|
|
_t(self::class . '.YUBIKEYSECONDFACTORFIELD', 'Yubikey second factor authentication') |
46
|
|
|
) |
47
|
|
|
] |
48
|
|
|
); |
49
|
|
|
$backURL = $this->controller->getRequest()->getVar('BackURL'); |
50
|
|
|
if ($backURL) { |
51
|
|
|
$fields->push(HiddenField::create('BackURL', $backURL)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $fields; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return FieldList|static |
59
|
|
|
*/ |
60
|
|
|
public function getFormActions() |
61
|
|
|
{ |
62
|
|
|
$action = FieldList::create( |
63
|
|
|
[ |
64
|
|
|
FormAction::create('validateToken', _t(self::class . '.VALIDATE', 'Validate')) |
65
|
|
|
] |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
return $action; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public function getAuthenticatorName() |
75
|
|
|
{ |
76
|
|
|
return _t(self::class . '.TITLE', 'Yubikey authentication'); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|