/**
  * Change the member dialog in the CMS
  *
  * This method updates the form in the member dialog to make it possible
  * to edit the new database fields.
  */
 function updateCMSFields(FieldList $fields)
 {
     // let make sure, this runs only once (because member and dataobject both extend updateCMSFields
     // 	making it run twice!)
     $cp = $fields->fieldByName('Root');
     if ($cp && $cp->fieldByName('ExternalAuthentication')) {
         return;
     }
     $sources = ExternalAuthenticator::getIDandNames();
     $sources = array_merge(array("" => "-"), $sources);
     $fields->findOrMakeTab('Root.ExternalAuthentication', _t('ExternalAuthenticator.Title'));
     $fields->addFieldToTab('Root.ExternalAuthentication', new HeaderField('External_Header', _t('ExternalAuthenticator.ModFormHead', 'ID for external authentication source')));
     $fields->addFieldToTab('Root.ExternalAuthentication', new LiteralField('ExternalDescription', _t('ExternalAuthenticator.EnterUser', 'Enter the user id and authentication source for this user')));
     $fields->addFieldToTab('Root.ExternalAuthentication', new DropdownField('External_SourceID', _t('ExternalAuthenticator.Sources'), $sources));
     $fields->addFieldToTab('Root.ExternalAuthentication', new TextField('External_Anchor', _t('ExternalAuthenticator.EnterNewId', 'ID to be used with this source')));
 }
 /**
  * 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);
 }