Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » BackURL login / registring

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: 3155 Views
  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    BackURL login / registring Link to this post

    I've extended my SilverStripe installation with a user registration page. I've altered a BackURL variable to the links to the login and regsitry pages.

    However, how can I include the BackURL in my altered login template to include a message that they can register for an account?

    themes/mytheme/templates/Layout/Security_login.ss

    $Content
    Login below or <a href="{$BaseHref}register?BackURL={$BackURL}">register for an user account</a>.
    $Form
    <a href="{$BaseHref}register?BackURL={$BackURL}">Register for an user account</a>

    The BackURL is added to the Form itself, but not to the 'register user account' links.

    I've tried adding a CustomLoginForm, but the BackURL information isn't available in the Security_login.ss (as it will probably need to be added to the Controller but I can't find the Form Controller.

    <?php
    class CustomLoginForm extends MemberLoginForm {
       public function BackURL() {
          if(isset($_REQUEST['BackURL'])) {
             return $_REQUEST['BackURL'];
          } else {
             return Session::get('BackURL');
          }
       }
    }

    Any help would be appreciated.

  • swaiba
    Avatar
    Forum Moderator
    1786 Posts

    Re: BackURL login / registring Link to this post

    I've used...

    Security::set_default_login_dest('urlsegment');

    to set a site wide login destination, does this help?

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: BackURL login / registring Link to this post

    No, that's not what I meant. There is a login link on each page. After a visitors successfully logs in (or chooses the register option on the login page) I want them redirected back to the page on which they clicked the login link.

  • swaiba
    Avatar
    Forum Moderator
    1786 Posts

    Re: BackURL login / registring Link to this post

    how about something like the following in Page::init()?

    Session::set('BackURL',$this->Link());

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: BackURL login / registring Link to this post

    Solution turned out to be quite simple, I've ended up putting the BackURL function in the Page_Controller so it can be included into the Security_login.ss template.

    class Page_Controller extends ContentController {

       public function BackURL() {
          if(isset($_REQUEST['BackURL'])) {
             return $_REQUEST['BackURL'];
          } else {
             return Session::get('BackURL');
          }
       }
    }

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