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.

General Questions /

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

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

Redirect on Login Failure


Reply


4 Posts   1282 Views

Avatar
TerryMiddleton

Community Member, 108 Posts

1 May 2009 at 7:24am

I need to redirect the user to a registration form when they try to login and it fails.

How can I do this? I will apologize in advance bacause I'm technical, but have not educated myself on the whole php5 class concepts. So while I sort of understand it, I don't know enough to pull it off.

I know once I get it life will be much better, so I'm learning.

Has anyone done this when a user logs in and it fails?

Terry

Avatar
Carbon Crayon

Community Member, 598 Posts

2 May 2009 at 12:22pm

Hi Terry

If you look at [url=http://www.ssbits.com/custom-login-form-with-group-based-redirection/]my tutorial on Login redirection[/url], in part II there is a CustomLogin function that looks like this:

class CustomLogin extends MemberLoginForm {
02. public function dologin($data) {
03. if($this->performLogin($data)) {
04. if(!$this->redirectByGroup($data))
05. Director::redirect(Director::baseURL());
06. } else {
07. if($badLoginURL = Session::get("BadLoginURL")) {
08. Director::redirect($badLoginURL);
09. } else {
10. Director::redirectBack();
11. }
12. }
13. }
14.}

On line 07 - 11 you can see that on a bad login the user is directed to either the $BadLoginURL or if taht fails then just back. If you subclass the login in the way described by the tutorial you should be able to replace this bit of code with any URL you like and SS will prform the redirection if the login fails.

As a side note, I would be pretty annoyed if I was trying to login to a site and I mistyped my login (as often happens) and it then redirected me to a registration form instead of back to the login to try again.....just a thought :)

Hope that helps.

Avatar
Carbon Crayon

Community Member, 598 Posts

2 May 2009 at 12:22pm

Edited: 02/05/2009 12:23pm

Duplicate post

Avatar
TerryMiddleton

Community Member, 108 Posts

2 May 2009 at 12:48pm

aram,

Thank you for this. It works great.

Yeah, I agree with the registration form from a bad login. I tried to talk the client out of it but they probably have to see it first before they understand that it will be annoying.

Thanks again. My first SS site is started to have look very promising.

I appreciate your help.

Terry