Silverstripe subsites with independent user registrations

半腔热情 提交于 2019-12-11 07:45:13

问题


I'm using the subsites module to make a multi site system.

I'd like the users logins to the sites to be independent. So if a user has registered on one site, they can't just go to another subsite and login - they have to register for that site too.

In other words - registrations on each subsite is completely independent.

Is this possible?


回答1:


Technically it would be possible to write a DataObjectDecorator for the Member class, and add a SubsiteID to each member, and then add a filter for that SubsiteID with argumentSQL().
And you need to modify the register form to consider the SubsiteID and hook into the authenticator.
But could very well be that there are a couple of other points you need to hook into to get this to work.

So yes, it should be possible, but it is going to take a long time, and it will be a pain in the arse to get it working properly.

you should carefully consider if you really need it that bad that you need to go this way.
It should be possible to just work around this by using groups, and setting group permissions.




回答2:


I know this is pretty old thread, but in case someone stumble upon this thread, it will be useful. There is another hack for this.

/mysite/extensions/CustomLeftAndMain.php

<?php
class CustomLeftAndMain extends Extension {

    public function onAfterInit() {

        self::handleUser();

    }



    public static function handleUser(){
        $currentSubsiteID = Subsite::currentSubsiteID();

        $member =  Member::currentUser();
        $memberBelongsToSubsite =  $member->SubsiteID; 

        if($memberBelongsToSubsite>0 && $currentSubsiteID!=$memberBelongsToSubsite){
            Security::logout(false);
            Controller::curr()->redirect("/Security/login/?_c=1001");
        }
    }


}

and in /mysite/_config.php add an extension

LeftAndMain::add_extension('CustomLeftAndMain');

What above code basically does is, the system lets user login no matter which subsite they belong to. And as long as application is initiated, whether the logged in user belongs to current website or not (method handleUser does it.). If user doesnot belong to current site, then they are logged out and then redirected to login page.




回答3:


The description says (among other things):

  • "The subsites module allows multiple websites to run from a single installation of SilverStripe, and share users, content, and assets between them."
  • "The branches can have separate users/admins, and information that is individual."

If you don't have a common "headquarter", I'm not sure the module is right for you. Instead of hacking the module to do something it isn't intended to do, why not make separate installations?



来源:https://stackoverflow.com/questions/7507871/silverstripe-subsites-with-independent-user-registrations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!