Jump to:

23379 Posts in 18298 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Redirect user to group page upon 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 2
Go to End
Author Topic: 665 Views
  • the-tech-guy
    Avatar
    Community Member
    13 Posts

    Redirect user to group page upon login Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Redirect user to group page upon login Link to this post

    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.

  • the-tech-guy
    Avatar
    Community Member
    13 Posts

    Re: Redirect user to group page upon login Link to this post

    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?

  • the-tech-guy
    Avatar
    Community Member
    13 Posts

    Re: Redirect user to group page upon login Link to this post

    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??

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Redirect user to group page upon login Link to this post

    Yep

  • the-tech-guy
    Avatar
    Community Member
    13 Posts

    Re: Redirect user to group page upon login Link to this post

    Great!

    Also looking further into GroupDecorator.php,

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

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Redirect user to group page upon login Link to this post

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

  • the-tech-guy
    Avatar
    Community Member
    13 Posts

    Re: Redirect user to group page upon login Link to this post

    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.

    665 Views
Page: 1 2
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.