| 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 |  |  | class YubikeyForm extends LoginForm | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         RequestHandler $controller = null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $name = self::DEFAULT_NAME | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $this->controller = $controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $fields = $this->getFormFields(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $actions = $this->getFormActions(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $validator = RequiredFields::create(['yubiauth']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         parent::__construct($controller, $name, $fields, $actions, $validator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     public function getFormFields() | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         $fields = FieldList::create( | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |             [ | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |                 PasswordField::create('yubiauth', 'Yubikey second factor authentication') | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |             ] | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $backURL = $this->controller->getRequest()->getVar('BackURL'); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         if ($backURL) { | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |             $fields->push(HiddenField::create('BackURL', $backURL)); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         return $fields; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     public function getFormActions() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $action = FieldList::create( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 FormAction::create('validateYubikey', 'Validate') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         return $action; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     public function getAuthenticatorName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return _t('YubikeyForm.TITLE', 'Yubikey authentication'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |  |