Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » $LoginForm action url problems please help urgent

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

Page: 1
Go to End
Author Topic: 2025 Views
  • nimeso
    Avatar
    Community Member
    17 Posts

    $LoginForm action url problems please help urgent Link to this post

    Hi all please help.. have no idea what I'm doing wrong

    I have standard login redirect

    class ExtendedLoginForm extends MemberLoginForm {

       public function dologin($data) {
          
    if($this->performLogin($data)) {
    $this->redirectByGroup($data);
    Director::redirect(Director::baseURL());
    } else {
    if($badLoginURL = Session::get("BadLoginURL")) {
    Director::redirect($badLoginURL);
    } else {
    Director::redirectBack();
    }
    }
    }

       public function redirectByGroup($data)
    {
    // gets the current member that is logging in
    $member = Member::currentUser();

    // gets all the groups.
    $Groups = DataObject::get("Group");

    //cycle through each group
    foreach($Groups as $Group)
    {
    //if the member is in the group and that group has GoToAdmin checked
    if($member && $member->inGroup($Group->ID) && $Group->GoToAdmin)
    {
    ////redirect to the admin page
    return Director::redirect(Director::baseURL() . 'admin' );
    }
    //otherwise if the member is in the group and that group has a page linked
    else if($member && $member->inGroup($Group->ID) && $Page = $Group->LinkedPage())
    {
    ////direct to that page
    return Director::redirect(Director::baseURL() . $Page->URLSegment);

    }
    }
    return false;
    }

    }

    and it works great! if I log in via http://guardian.nimeso/Security/login BUT...

    When I put $LoginForm (eg:in homepage.ss) anywhere in the template it doesn't seem to do ANYTHING in ExtendedLoginForm and redirects to http://guardian.nimeso/home/LoginForm and dosn't log me in?

    Please someone help? I've wasted 7 hours tryin to sort.

    Ta heaps
    Jamie

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: $LoginForm action url problems please help urgent Link to this post

    Did you do this?

    DataObject::add_extension('MemberLoginForm','ExtendedLoginForm');

  • nimeso
    Avatar
    Community Member
    17 Posts

    Re: $LoginForm action url problems please help urgent Link to this post

    Hi Thanks heaps Ryan!

    Yes it works fine on the Security page but no-where else. I have 'hard-coded' the form markup and form action and it works but no best soloution.

    Problem is the form action it reads /home/LoginForm (boots me to page not found) which dosn't work where as /Security/LoginForm does work 100% a-ok with re-direct working

    Thoughts?

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: $LoginForm action url problems please help urgent Link to this post

    You might need to copy the LoginForm function and paste it into Page.php within your mysite/code/ folder. So that way, whichever page the LoginForm is called from, will be able to access the LoginForm function.

  • nimeso
    Avatar
    Community Member
    17 Posts

    Re: $LoginForm action url problems please help urgent Link to this post

    Thanks heaps Ryan,

    Cheers
    J

  • lildiablo
    Avatar
    Community Member
    2 Posts

    Re: $LoginForm action url problems please help urgent Link to this post

    Check your allowed actions in your page.php controller

    public static $allowed_actions = array ('LoginForm');

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