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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

BackURL login / registring


Go to End


5 Posts   4984 Views

Avatar
MarijnKampf

Community Member, 176 Posts

28 September 2010 at 4:12am

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.

Avatar
swaiba

Forum Moderator, 1899 Posts

28 September 2010 at 4:22am

I've used...

Security::set_default_login_dest('urlsegment');

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

Avatar
MarijnKampf

Community Member, 176 Posts

28 September 2010 at 5:26am

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.

Avatar
swaiba

Forum Moderator, 1899 Posts

28 September 2010 at 5:32am

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

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

Avatar
MarijnKampf

Community Member, 176 Posts

28 September 2010 at 7:13am

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');
		}
	}
}