Jump to:

5541 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » login form

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1302 Views
  • trustnoone
    Avatar
    Community Member
    2 Posts

    login form Link to this post

    hi, im new to SilverStripe... im glad to know this cms.
    its still hard to me to customize this cms. i would like add new field to user login form (for example captcha). i do not know where to go...

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: login form Link to this post

    Hi trustnoone!

    Welcome to SS.

    The most simple way to do this is to extend MemberAuthenticator, create a new class such as MyMemberAuthenticator and create a static function called get_login_form that accepts 1 parameter ($controller). then return a new form with the fields you want. They will need to have the same names for the username and password.

    You then have to register that authenticator in your _config and unregister the existing one. So in the end you want something like this:

    MyMemberAuthenticator.php:

    class MyMemberAuthentcator extends MemberAuthenticator {
    public static function get_login_form(Controller $controller) {
    $label=singleton('Member')->fieldLabel(Member::get_unique_identifier_field());
                $fields = new FieldSet(
                   new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this),
                   //Regardless of what the unique identifer field is (usually 'Email'), it will be held in the 'Email' value, below:
                   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?")
                   ));
                }
    //push your custom fields in here
    $fields->push( ... )
    return new MemberLoginForm($controller, 'MemberLoginForm',$fields);
    }
    }

    _config.php

    Authenticator::unregister_authenticator('MemberAuthenticator');
    Authenticator::register_authenticator('MyMemberAuthenticator');

    And that should be the ground work done. Validation may be the only problem here, but you can just extend the authenticate method if you need to.

    Enjoy!

  • trustnoone
    Avatar
    Community Member
    2 Posts

    Re: login form Link to this post

    thanks for the reply...

    sorry for the late respond. i didn't tried your method yet, yesterday i tried extend MemberLoginForm class. and the functionality is running as i want. when the user tried to login 3 times (wrong login), the MathSpamProtection will show. and the validation i did in dologin function.

    i still trying to notice, what is the different with your method...

  • BenWu
    Avatar
    Community Member
    90 Posts

    Re: login form Link to this post

    I found this http://tamethebackbutton.blogspot.co.uk/2009/09/customize-your-own-silverstripe-login.html

    If you need only to change the template, you need to put Security_login.ss in your templates/Layout folder under your theme

    1302 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.