/**
  * Taken from MemberLoginForm::__construct with minor changes
  */
 public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     $customCSS = project() . '/css/member_login.css';
     if (Director::fileExists($customCSS)) {
         Requirements::css($customCSS);
     }
     if (isset($_REQUEST['BackURL'])) {
         $backURL = $_REQUEST['BackURL'];
     } else {
         $backURL = Session::get('BackURL');
     }
     if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) {
         $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this));
         $actions = new FieldList(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
     } else {
         if (!$fields) {
             $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this));
         }
         if (!$actions) {
             $actions = new FieldList(new FormAction('dologin', _t('GoogleAuthenticator.BUTTONLOGIN', "Log in with Google")));
         }
     }
     if (isset($backURL)) {
         $fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
     }
     // Allow GET method for callback
     $this->setFormMethod('GET', true);
     parent::__construct($controller, $name, $fields, $actions);
 }
 /**
  * EmailVerificationLoginForm is the same as MemberLoginForm with the following changes:
  *  - The code has been cleaned up.
  *  - A form action for users who have lost their verification email has been added.
  *
  * We add fields in the constructor so the form is generated when instantiated.
  *
  * @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)
 {
     $email_field_label = singleton('Member')->fieldLabel(Member::config()->unique_identifier_field);
     $email_field = TextField::create('Email', $email_field_label, null, null, $this)->setAttribute('autofocus', 'autofocus');
     $password_field = PasswordField::create('Password', _t('Member.PASSWORD', 'Password'));
     $authentication_method_field = HiddenField::create('AuthenticationMethod', null, $this->authenticator_class, $this);
     $remember_me_field = CheckboxField::create('Remember', 'Remember me next time?', true);
     if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) {
         $fields = FieldList::create($authentication_method_field);
         $actions = FieldList::create(FormAction::create('logout', _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
     } else {
         if (!$fields) {
             $fields = FieldList::create($authentication_method_field, $email_field, $password_field);
             if (Security::config()->remember_username) {
                 $email_field->setValue(Session::get('SessionForms.MemberLoginForm.Email'));
             } else {
                 // Some browsers won't respect this attribute unless it's added to the form
                 $this->setAttribute('autocomplete', 'off');
                 $email_field->setAttribute('autocomplete', 'off');
             }
         }
         if (!$actions) {
             $actions = FieldList::create(FormAction::create('doLogin', _t('Member.BUTTONLOGIN', "Log in")), new LiteralField('forgotPassword', '<p id="ForgotPassword"><a href="Security/lostpassword">' . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'), new LiteralField('resendEmail', '<p id="ResendEmail"><a href="Security/verify-email">' . _t('MemberEmailVerification.BUTTONLOSTVERIFICATIONEMAIL', "I've lost my verification email") . '</a></p>'));
         }
     }
     if (isset($_REQUEST['BackURL'])) {
         $fields->push(HiddenField::create('BackURL', 'BackURL', $_REQUEST['BackURL']));
     }
     // Reduce attack surface by enforcing POST requests
     $this->setFormMethod('POST', true);
     parent::__construct($controller, $name, $fields, $actions);
     $this->setValidator(RequiredFields::create('Email', 'Password'));
 }
    /**
     * Constructor.
     *
     * @param Controller $controller
     * @param string $name method on the $controller
     * @param FieldList $fields
     * @param FieldList $actions
     * @param bool $checkCurrentUser - show logout button if logged in
     */
    public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
    {
        parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser);
        // will be used to get correct Link()
        $this->ldapSecController = Injector::inst()->create('LDAPSecurityController');
        $usernameField = new TextField('Username', _t('Member.USERNAME', 'Username'), null, null, $this);
        $this->Fields()->replaceField('Email', $usernameField);
        $this->setValidator(new RequiredFields('Username', 'Password'));
        if (Security::config()->remember_username) {
            $usernameField->setValue(Session::get('SessionForms.MemberLoginForm.Email'));
        } else {
            // Some browsers won't respect this attribute unless it's added to the form
            $this->setAttribute('autocomplete', 'off');
            $usernameField->setAttribute('autocomplete', 'off');
        }
        // Users can't change passwords unless appropriate a LDAP user with write permissions is
        // configured the LDAP connection binding
        $this->Actions()->remove($this->Actions()->fieldByName('forgotPassword'));
        $allowPasswordChange = Config::inst()->get('LDAPService', 'allow_password_change');
        if ($allowPasswordChange && $name != 'LostPasswordForm' && !Member::currentUser()) {
            $forgotPasswordLink = sprintf('<p id="ForgotPassword"><a href="%s">%s</a></p>', $this->ldapSecController->Link('lostpassword'), _t('Member.BUTTONLOSTPASSWORD', "I've lost my password"));
            $forgotPassword = new LiteralField('forgotPassword', $forgotPasswordLink);
            $this->Actions()->add($forgotPassword);
        }
        // Focus on the Username field when the page is loaded
        Requirements::block('MemberLoginFormFieldFocus');
        $js = <<<JS
\t\t\t(function() {
\t\t\t\tvar el = document.getElementById("Username");
\t\t\t\tif(el && el.focus && (typeof jQuery == 'undefined' || jQuery(el).is(':visible'))) el.focus();
\t\t\t})();
JS;
        Requirements::customScript($js, 'LDAPLoginFormFieldFocus');
    }
 public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) {
     } else {
     }
     $backURL = isset($_REQUEST['BackURL']) ? $_REQUEST['BackURL'] : Session::get('BackURL');
     if (isset($backURL)) {
         $fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
     }
     return parent::__construct($controller, $name, $fields, $actions);
 }
Exemplo n.º 5
0
    public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
    {
        // This is now set on the class directly to make it easier to create subclasses
        // $this->authenticator_class = $authenticatorClassName;
        $customCSS = project() . '/css/member_login.css';
        if (Director::fileExists($customCSS)) {
            Requirements::css($customCSS);
        }
        if (isset($_REQUEST['BackURL'])) {
            $backURL = $_REQUEST['BackURL'];
        } else {
            $backURL = Session::get('BackURL');
        }
        if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) {
            $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this));
            $actions = new FieldList(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
        } else {
            if (!$fields) {
                $label = singleton('Member')->fieldLabel(Member::config()->unique_identifier_field);
                $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this), $emailField = new TextField("Email", $label, null, null, $this), new PasswordField("Password", _t('Member.PASSWORD', 'Password')));
                if (Security::config()->remember_username) {
                    $emailField->setValue(Session::get('SessionForms.MemberLoginForm.Email'));
                } else {
                    // Some browsers won't respect this attribute unless it's added to the form
                    $this->setAttribute('autocomplete', 'off');
                    $emailField->setAttribute('autocomplete', 'off');
                }
                if (Security::config()->autologin_enabled) {
                    $fields->push(new CheckboxField("Remember", _t('Member.REMEMBERME', "Remember me next time?")));
                }
            }
            if (!$actions) {
                $actions = new FieldList(new FormAction('dologin', _t('Member.BUTTONLOGIN', "Log in")), new LiteralField('forgotPassword', '<p id="ForgotPassword"><a href="Security/lostpassword">' . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'));
            }
        }
        if (isset($backURL)) {
            $fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
        }
        // Reduce attack surface by enforcing POST requests
        $this->setFormMethod('POST', true);
        parent::__construct($controller, $name, $fields, $actions);
        $this->setValidator(new RequiredFields());
        // Focus on the email input when the page is loaded
        $js = <<<JS
\t\t\t(function() {
\t\t\t\tvar el = document.getElementById("MemberLoginForm_LoginForm_Email");
\t\t\t\tif(el && el.focus && (typeof jQuery == 'undefined' || jQuery(el).is(':visible'))) el.focus();
\t\t\t})();
JS;
        Requirements::customScript($js, 'MemberLoginFormFieldFocus');
    }
 public function __construct($controller = null, $name = null, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     if (!$controller) {
         $controller = Controller::curr();
     }
     if (!$name) {
         $name = "LoginForm";
     }
     parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser);
     $this->Fields()->bootstrapify();
     $this->Actions()->bootstrapify();
     $this->setTemplate("BootstrapForm");
     $this->invokeWithExtensions('updateBoostrapMemberLoginForm', $this);
 }
 public function __construct($controller = null, $name = null, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     if (!$controller) {
         $controller = Controller::curr();
     }
     if (!$name) {
         $name = "LoginForm";
     }
     parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser);
     $this->Fields()->bootstrapify();
     $this->Actions()->bootstrapify();
     $this->setTemplate("FoundationForm");
     $this->invokeWithExtensions('updateFoundationMemberLoginForm', $this);
     Requirements::css(FOUNDATIONFORMS_DIR . '/css/foundationforms.css');
 }
 public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) {
         $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this));
         $actions = new FieldList(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
     } else {
         $fields = new FieldList(new LiteralField('FacebookLoginIn', "<fb:login-button scope='" . $controller->getFacebookPermissions() . "'></fb:login-button>"));
         $actions = new FieldList(new LiteralField('FacebookLoginLink', "<!-- <a href='" . $controller->getFacebookLoginLink() . "'>" . _t('FacebookLoginForm.LOGIN', 'Login') . "</a> -->"));
     }
     $backURL = isset($_REQUEST['BackURL']) ? $_REQUEST['BackURL'] : Session::get('BackURL');
     if (isset($backURL)) {
         $fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
     }
     return parent::__construct($controller, $name, $fields, $actions);
 }
 /**
  * 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
  * @param string $authenticatorClassName Name of the authenticator class that this form uses.
  */
 function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     // This is now set on the class directly to make it easier to create subclasses
     // $this->authenticator_class = $authenticatorClassName;
     $customCSS = project() . '/css/member_login.css';
     if (Director::fileExists($customCSS)) {
         Requirements::css($customCSS);
     }
     if (isset($_REQUEST['BackURL'])) {
         $_REQUEST['BackURL'] = str_replace("/RegistrationForm", "", $_REQUEST['BackURL']);
         $backURL = $_REQUEST['BackURL'];
     } else {
         if (strpos(Session::get('BackURL'), "/RegistrationForm") > 0) {
             Session::set('BackURL', str_replace("/RegistrationForm", "", Session::get('BackURL')));
         }
         $backURL = str_replace("/RegistrationForm", "", Session::get('BackURL'));
     }
     if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) {
         $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this));
         $actions = new FieldList(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
     } else {
         if (!$fields) {
             $label = singleton('Member')->fieldLabel(Member::get_unique_identifier_field());
             $fields = new FieldList(new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this), new TextField("Email", $label, Session::get('SessionForms.MemberLoginForm.Email'), null, $this), new PasswordField("Password", _t('Member.PASSWORD', 'Password')));
             if (Security::$autologin_enabled) {
                 $fields->push(new CheckboxField("Remember", _t('Member.REMEMBERME', "Remember me next time?")));
             }
         }
         if (!$actions) {
             $actions = new FieldList(new FormAction('dologin', _t('Member.BUTTONLOGIN', "Log in")), new LiteralField('forgotPassword', '<p id="ForgotPassword"><a href="Security/lostpassword">' . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'), new LiteralField('resendEmail', '<p id="ResendEmail"><a href="Security/verifyemail">' . _t('EmailVerifiedMember.BUTTONRESENDEMAIL', "I've lost my verification email") . '</a></p>'));
         }
     }
     if (isset($backURL)) {
         $fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
     }
     parent::__construct($controller, $name, $fields, $actions);
     // Focus on the email input when the page is loaded
     // Only include this if other form JS validation is enabled
     /*		if($this->getValidator()->getJavascriptValidationHandler() != 'none') {
     			Requirements::customScript(<<<JS
     				(function() {
     					var el = document.getElementById("MemberLoginForm_LoginForm_Email");
     					if(el && el.focus) el.focus();
     				})();
     JS
     			);
     		}*/
 }
Exemplo n.º 10
0
    public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
    {
        parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser);
        if ($this->Actions()->fieldByName('forgotPassword')) {
            // replaceField won't work, since it's a dataless field
            $this->Actions()->removeByName('forgotPassword');
            $this->Actions()->push(new LiteralField('forgotPassword', '<p id="ForgotPassword"><a href="AdminSecurity/lostpassword">' . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'));
        }
        Requirements::customScript(<<<'JS'
			(function() {
				var el = document.getElementById("AdminLoginForm_LoginForm_Email");
				if(el && el.focus) el.focus();
			})();
JS
);
    }
 public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     $form_action_url = Controller::join_links(BASE_URL, "Security", $name);
     $lost_password_url = Controller::join_links(BASE_URL, "Security", "lostpassword");
     if (isset($_REQUEST['BackURL'])) {
         $backURL = $_REQUEST['BackURL'];
     } else {
         $backURL = Session::get('BackURL');
     }
     $fields = new FieldList(HiddenField::create("AuthenticationMethod", null, $this->authenticator_class, $this), TextField::create('Identity', 'Username or Email'), PasswordField::create("Password", _t('Member.PASSWORD', 'Password')));
     if (Security::config()->autologin_enabled) {
         $fields->push(new CheckboxField("Remember", _t('Member.REMEMBERME', "Remember me?")));
     }
     $actions = new FieldList(FormAction::create('dologin', 'Login'), LiteralField::create('forgotPassword', '<p id="ForgotPassword"><a href="' . $lost_password_url . '">' . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>'));
     // LoginForm does its magic
     parent::__construct($controller, $name, $fields, $actions);
     $this->setAttribute("action", $form_action_url);
 }
 public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true)
 {
     parent::__construct($controller, $name, $fields, $actions, $checkCurrentUser);
     $this->fields->renameField('Email', 'Username');
 }