Jump to:

23001 Posts in 11702 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » Redirect on Login Failure

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

Page: 1
Go to End
Author Topic: 1173 Views
  • TerryMiddleton
    Avatar
    Community Member
    108 Posts

    Redirect on Login Failure Link to this post

    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

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Redirect on Login Failure Link to this post

    Hi Terry

    If you look at my tutorial on Login redirection, 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.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Redirect on Login Failure Link to this post

    Duplicate post

  • TerryMiddleton
    Avatar
    Community Member
    108 Posts

    Re: Redirect on Login Failure Link to this post

    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

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