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.

Form Questions /

$LoginForm action url problems please help urgent


Reply


6 Posts   2132 Views

Avatar
nimeso

Community Member, 17 Posts

3 November 2010 at 1:36pm

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

Avatar
Ryan M.

Community Member, 309 Posts

5 November 2010 at 8:21am

Did you do this?

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

Avatar
nimeso

Community Member, 17 Posts

5 November 2010 at 8:48am

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?

Avatar
Ryan M.

Community Member, 309 Posts

5 November 2010 at 2:03pm

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.

Avatar
nimeso

Community Member, 17 Posts

9 November 2010 at 4:24am

Thanks heaps Ryan,

Cheers
J

Avatar
lildiablo

Community Member, 2 Posts

8 March 2011 at 7:28am

Check your allowed actions in your page.php controller

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