0

E.g. My site has two subdomains : domain_a and domain_b.

And My site has three roles: role_a, role_b, role_c.

I hope:

User with role_a can login domain_a, can't login domain_b. (When user visit domain_b user status is not logined and not lost domain_a logined status)

User with role_b can login domain_b, can't login domain_a.

User with role_c can login domain_a and domain_b.

Does anyone have any solution?

2

You have two options:

Domain Access has it figured out

Domain Access module excerpt:

The Domain Access project is a suite of modules that provide tools for running a group of affiliated sites from one Drupal installation and a single shared database. The module allows you to share users, content, and configurations across a group of sites such as:

  • example.com
  • one.example.com
  • two.example.com
  • my.example.com
  • thisexample.com <-- can use any domain string
  • example.com:3000 <-- treats non-standard ports as unique

Then, you need Domain Roles:

Allows you to save user roles per domain. Allows a certain user to be just authenticated on one domain and admin on another etc.

You can't totally prevent cross-logins, but you can make user logged in with no permissions at all, except to log out.

If you prefer Multisite approach

You can change the settings for the access to the database that are contained in the settings.php file used by your Drupal site to something similar to the following one (replace the values between brackets with the correct values for your site):

$databases['default']['default'] = array(
  'driver' => '[Your database engine]',
  'database' => '[Your database name]',
  'username' => '[Your username for the access to the database engine]',
  'password' => '[The password for the access to the database]',
  'host' => 'localhost',
  'prefix' => array(
    'default'   => 'main_',
    'users'     => 'shared_',
    'sessions'  => 'shared_',
    'role'      => 'shared_',
    'authmap'   => 'shared_',
  ),
  'collation' => 'utf8_general_ci',
);

Taken from this answer.

Then, in hook_user_login(&$edit, $account) test if user has a role he needs to access given page, and if not, logout him with proper message.

|improve this answer|||||
  • @Rylyn answer updated. – Mołot Jun 28 '13 at 8:34
  • Thank your idea, @Molot. But domain_roles can't solve my problem. I hope role_a visit domain_b, doesn't lose domain_a login status. – Rylyn Jun 28 '13 at 9:56
  • @Rylyn With domain roles? Nope. – Mołot Jun 28 '13 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.