0

我想要一个阻止人们登录的权限。(因此,可以暂时阻止角色 X 的所有用户,同时保持他们的个人资料页面可用。)

Pro Drupal Development 2nd Edition 的登录过程摘录:

  1. 从登录表单发布
  2. 用户被屏蔽?
  3. 用户被访问控制拒绝?

我想在流程的第三步停止用户。我有一个模块:

/**
 * Implementation of hook_perm().
 */
function odp_perm() {
  return array('log in');
}

/**
 * Implementation of hook_user
 * lock out without the 'log in' permission
 */
function odp_user($op, &$edit, &$account, $category = NULL) {
    if ($op == 'login' && ! user_access('log in')) {
      drupal_set_message("You do not have access to log in.", "error");
      drupal_goto('logout'); //doesn't work
      drupal_goto('content/party-tonight'); //also doesn't work
    }
}

也许我使用 drupal_goto 错误。

4

2 回答 2

1

我相信这可以完成您想要做的事情。

/**
 * Implementation of hook_user
 * lock out without the 'log in' permission
 */
function odp_user($op, &$edit, &$account, $category = NULL) {
    if ($op == 'login' && ! user_access('log in')) {
        drupal_set_message("You don't have permission to log in");

        //prevent login
        header("Location: http://www.example.com/?q=logout");
        // header("Location: http://www.example.com/logout"); if using clean URLs
    }
}

这会将用户注销并显示一条消息。如果我没记错的话,带有 $op login 的 hook_user 会在用户登录后触发,所以这会立即将他们重新注销——本质上是让他们无法登录。

于 2009-09-03T16:53:10.213 回答
0

我没有在 ATM 上测试这个的 Drupal 实例,但我认为你想要这个:

/**
 * Implementation of hook_user
 * lock out without the 'log in' permission
 */
function odp_user($op, &$edit, &$account, $category = NULL) {
    if ($op == 'login' && ! user_access('log in')) {
        global $user;
        $user = drupal_anonymous_user();
        drupal_set_message("You don't have permission to log in");

    }
}

这会删除他们的用户信息,并将其替换为匿名用户。

于 2009-09-03T17:08:46.453 回答