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

Redirect user to group page upon login


Go to End


15 Posts   2737 Views

Avatar
the-tech-guy

Community Member, 13 Posts

19 February 2014 at 7:02pm

Hello Everyone,

Forgive me if this has been covered, I have tried to search but only found a few redirection topics relevant to SS 2.4 and I am using SS 3.0.

I have a site that I am building and each user is part of a group

There maybe one or more users to a group

I have a base page setup for each group and the groups only have permission to see there own page,

My question is, how do I have SS redirect these users to there page upon login?

I have researched and found a line to add into the _config.php to provide a login redirection: Security::set_default_login_dest('urlofpage');

Forgive me as I have only just started to use SS but I am really enjoying it.

Avatar
Willr

Forum Moderator, 5523 Posts

19 February 2014 at 10:41pm

Tutorial is for 2.4, but same concept for 3. http://www.ssbits.com/tutorials/2009/custom-login-form-with-group-based-redirection/. Just replace the usage of Decorators with DataExtension.

Avatar
the-tech-guy

Community Member, 13 Posts

21 February 2014 at 6:14pm

Thanks again Will!

Implementation doesn't seem to difficult, however im not 100% sure on how to replace the usage of Decorators with DataExtension, Do I just replace the "Decorator word with DataExtension" is there any documentation / threads relevant to this?

Avatar
the-tech-guy

Community Member, 13 Posts

21 February 2014 at 6:18pm

Okay sorry to be a pain, I think I understand it,

So does that mean that I would have to change this:
mysite/code/GroupDecorator.php

<?php
class GroupDecorator extends DataObjectDecorator {
}

To this:

mysite/code/GroupDecorator.php

<?php
class GroupDecorator extends DataExtension {
}

Am I on the right track??

Avatar
Willr

Forum Moderator, 5523 Posts

21 February 2014 at 6:46pm

Yep

Avatar
the-tech-guy

Community Member, 13 Posts

21 February 2014 at 6:55pm

Great!

Also looking further into GroupDecorator.php,

Can "extraStatics()" still be used in SS3??

Avatar
Willr

Forum Moderator, 5523 Posts

21 February 2014 at 8:20pm

No, so in 3.* you can now just do normal statics (like you would on the data object i.e private static $db = array()).

Avatar
the-tech-guy

Community Member, 13 Posts

24 February 2014 at 6:40pm

Okay so I have spent a little bit of time trying to migrate the code to work with SS3,

I have added new row to the DB before with no hassles, but this time is doesn't seem to be working,

I think where I have gone wrong is "DataExtension", the last time I used private static, the class extended the page template "page.php", where as now it extends DataExtension and I have no idea what that is

<?php
class GroupDecorator extends DataExtension {

private static $db = array(
'GoToAdmin' => 'Boolean',
'LinkedPage' => 'SiteTree'

);

}

The original code for SS 2.3 looked like this:

class GroupDecorator extends DataObjectDecorator {

public function extraStatics(){

return array(
'db' => array(
"GoToAdmin" => "Boolean"
),
'has_one' => array(
"LinkedPage" => "SiteTree"
),
);
}
}

PS: Anyone helping out with this I would like to create a new / update the old guide for a custom login form with group based redirection to help others looking for this solution also.

Go to Top