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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

Custom Login Template depending on Viewer Group


Go to End


2 Posts   1558 Views

Avatar
spierala

Community Member, 80 Posts

1 December 2011 at 5:06am

Hello all,
I want to show custom Login Templates for admins and clients trying to log in on the site.
Therefore I would have to know to which Viewer Group that page belongs (client or admin).

I have already the basic setup to perform a switch...
I have a custom loginform (CustomLoginForm.php) class, which I enabled using this in config.php:

Object::useCustomClass('MemberLoginForm', 'CustomLoginForm');

To use a custom template for the login form you just have to put a file named "Security_login.ss" in the Layout folder.
So far so good.
In CustomLoginForm.php I want to check the Viewer Group of the visited page with a function.
But I do not know how to get that info. So far I can access $_REQUEST['BackURL'], which is /admin or /client/something.
I could to the switch on that BackURL, but that doesn´t seem to be a cool solution :)

Does anyone know better?
Many thanks,
Florian

Avatar
rob.s

Community Member, 78 Posts

5 December 2011 at 9:18pm

Hi,

perhaps the following approaches work for you:

Inside your Form

1. Get the instance of the current controller and check the className:

$cont = Controller::curr();
if( $cont instanceof YourPageType_Controller ) {
  // do this
} else {
  //do that
} 

2. evaluate the ViewerGroups of the current controller (the security groups that have access to the controller)

$cont = Controller::curr();
$groups = $cont->ViewerGroups(); // this is basically a many_many component set

Does this help?

Robert