/**
  * Constructor
  *
  * @param Controller $controller The parent controller, necessary to
  *                               create the appropriate form action tag.
  * @param string $name The method on the controller that will return this
  *                     form object.
  * @param FieldList|FormField $fields All of the fields in the form - a
  *                                   {@link FieldList} of {@link FormField}
  *                                   objects.
  * @param FieldList|FormAction $actions All of the action buttons in the
  *                                     form - a {@link FieldList} of
  *                                     {@link FormAction} objects
  * @param bool $checkCurrentUser If set to TRUE, it will be checked if a
  *                               the user is currently logged in, and if
  *                               so, only a logout button will be rendered
  */
 function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     $this->authenticator_class = 'ExternalAuthenticator';
     $customCSS = project() . '/css/external_login.css';
     if (Director::fileExists($customCSS)) {
         Requirements::css($customCSS);
     }
     if (isset($_REQUEST['BackURL'])) {
         $backURL = $_REQUEST['BackURL'];
     } else {
         $backURL = Session::get('BackURL');
     }
     if ($checkCurrentUser && Member::currentUserID()) {
         $fields = new FieldList();
         $actions = new FieldList(new FormAction('logout', _t('ExternalAuthenticator.LogOutIn', 'Log in as someone else')), new HiddenField('AuthenticationMethod', null, $this->authenticator_class, $this));
     } else {
         if (!$fields) {
             if (!ExternalAuthenticator::getUseAnchor()) {
                 $fields = new FieldList(new HiddenField('AuthenticationMethod', null, $this->authenticator_class, $this), new HiddenField('External_SourceID', 'External_SourceID', 'empty'), new HiddenField('External_Anchor', 'External_Anchor', 'empty'), new TextField('External_MailAddr', _t('ExternalAuthenticator.MailAddr', 'e-Mail address'), Session::get('SessionForms.ExternalLoginForm.External_MailAddr')), new PasswordField('Password', _t('ExternalAuthenticator.Password', 'Password')));
             } else {
                 $userdesc = ExternalAuthenticator::getAnchorDesc();
                 $sources = ExternalAuthenticator::getIDandNames();
                 $fields = new FieldList(new HiddenField('AuthenticationMethod', null, $this->authenticator_class, $this), new HiddenField('External_MailAddr', 'External_MailAddr', 'empty'), new DropdownField('External_SourceID', _t('ExternalAuthenticator.Sources', 'Authentication sources'), $sources, Session::get('SessionForms.ExternalLoginForm.External_SourceID')), new TextField('External_Anchor', $userdesc, Session::get('SessionForms.ExternalLoginForm.External_Anchor')), new PasswordField('Password', _t('ExternalAuthenticator.Password')));
             }
             if (Security::$autologin_enabled) {
                 $fields->push(new CheckboxField("Remember", _t('ExternalAuthenticator.Remember', 'Remember me next time?'), Session::get('SessionForms.ExternalLoginForm.Remember'), $this));
             }
         }
         if (!$actions) {
             $actions = new FieldList(new FormAction('dologin', _t('ExternalAuthenticator.Login', 'Log in')));
         }
     }
     if (isset($backURL)) {
         $fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
     }
     parent::__construct($controller, $name, $fields, $actions);
 }