Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

login form


Reply


4 Posts   1342 Views

Avatar
trustnoone

Community Member, 2 Posts

24 June 2011 at 6:06pm

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...

Avatar
Pigeon

Community Member, 243 Posts

25 June 2011 at 4:06am

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!

Avatar
trustnoone

Community Member, 2 Posts

27 June 2011 at 1:29pm

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...

Avatar
BenWu

Community Member, 90 Posts

2 June 2012 at 2:19am

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