Jump to:

23481 Posts in 18965 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Redirect to a page after login

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: 4838 Views
  • Sec
    Avatar
    Community Member
    13 Posts

    Redirect to a page after login Link to this post

    How can I redirect to a specific page after login? I use $LoginForm on the frontpage, and want the users to end up at /account after successful login.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Redirect to a page after login Link to this post

    Hi Sec

    I have just poste a tutorial on SSbits to do just this

    http://www.ssbits.com/custom-login-form-with-group-based-redirection/

    hope it helps

    Aram

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Redirect to a page after login Link to this post

    Hi Aram,

    SSbits.com looks great added it to my Google Reader.

    One question, how could we extend this to redirect to a specific page in the admin ie. test.com/admin/show/5 based on the security group?

    Thanks,
    Howard

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Redirect to a page after login Link to this post

    Hi Howard

    Sorry for the late reply, I forget to subscribe to this thread and just came accross it again!

    The way to do this is to have the link be /admin/show/$ID of the page you want to redirect to. So I image you extract the Id from the TreeDropdownField and insert it into the redirector so change these lines:

    $Link = DataObject::get_by_id("SiteTree", "{$Group->LinkPageID}")->URLSegment;

    to this:

    $ID = DataObject::get_by_id("SiteTree", "{$Group->LinkPageID}")->ID;

    Abd this line:

    Director::redirect(Director::baseURL() . $Link);

    to this:

    Director::redirect(Director::baseURL() . "admin/show/" . $ID);

    That should work

    Aram

  • styleboy
    Avatar
    Community Member
    1 Post

    Re: Redirect to a page after login Link to this post

    I've used the code as ssbits but for some reason I can't get users to redirect. After login it says "I'm sorry, but you can't access that part of the CMS. If you want to log in as someone else, do so below"

    I have setup the page using $LoginForm

    Also, after I login on this page and I get that message, if I try to goto the page where this user is ABLE to access, it makes me login again @ /Security/login

    then if I go directly to /Security/login, it will log in and say welcome back, user. you are logged in as user. and there will be no redirect.

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