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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Custom Login Form


Go to End


2 Posts   4132 Views

Avatar
Liam

Community Member, 470 Posts

29 November 2013 at 9:10am

I extended MemberLoginForm similar to like the old SSbits tutorial for client redirection http://www.ssbits.com/tutorials/2009/custom-login-form-with-group-based-redirection/

But is it possible to have 2 login forms, instead of overriding? The reason being, I want 1 form for admin logins, and the custom form for the client redirection since they will never need CMS access. I realize the SSbits tutorial takes it into account, but I'd rather keep it simple since none of the client logins will need access and I"m curious for my own knowledge. If not, I can just do it similar to how SSBits handles it.

Ideally I want to create a client login page and put the custom form on it. Is there a way to attach the extended form to my pagetype and have a variable like $CustomLoginForm in my template? Something like that.

CustomLoginForm.php

<?php
class CustomLoginForm extends MemberLoginForm {
   public function dologin($data) {
        if($this->performLogin($data)) {
                if(!$this->redirectByClient($data))
                   Controller::curr()->redirect(Director::baseURL());
        } else {
            if($badLoginURL = Session::get('BadLoginURL')) {
                Controller::curr()->redirect($badLoginURL);
            } else {
                Controller::curr()->redirectBack();
            }
        }      
    }

    public function redirectByClient($data) {   
        $member = Member::currentUser();
        
        if ($member && $Page = $member->ClientPage()) {
            return Controller::curr()->redirect($Page->Link());
        }

        return false;
    }
}

Avatar
swaiba

Forum Moderator, 1899 Posts

5 December 2013 at 3:57am

Hi Liam,

I know this doesn't answer your question directly but maybe it helps - I noticed this new module that handles this for admin forms in SS3 - https://github.com/axyr/silverstripe-adminlogin

Barry