'r4032login_redirect', 'access callback' => 'r4032login_access', 'type' => MENU_CALLBACK ); $items['admin/settings/r4032login'] = array( 'title' => 'Redirect 403 to User Login', 'description' => 'Toggle display of denied message on login page.', 'page callback' => 'drupal_get_form', 'page arguments' => array('r4032login_admin_settings'), 'access callback' => 'user_access', 'access arguments' => array('administer site configuration') ); return $items; } /** * Without an access callback on the menu item for r4032login_redirect, * the redirect will be 403 and just have the default access denied page anyway. */ function r4032login_access() { return TRUE; } function r4032login_admin_settings() { $form = array(); $form['r4032login_display_denied_message'] = array( '#type' => 'checkbox', '#title' => t('Display access denied message on login page'), '#default_value' => variable_get('r4032login_display_denied_message', TRUE) ); $form['r4032login_user_register_message'] = array( '#type' => 'textfield', '#title' => t('User register message'), '#description' => t('The message to display when a logged-in user tries to register another account through the !new_account. Drupal does not allow it, so regular users must log out first. Administrators should create new users in !link.', array('!new_account' => l('new account registration form', 'user/register'), '!link' => l(t('User management'), 'admin/user/user/create'))), '#default_value' => variable_get('r4032login_user_register_message', t('You are not authorized to access this page.')) ); return system_settings_form($form); } /** * Implementation of hook_theme(). */ function r4032login_theme() { return array( 'r4032login_denied' => array( 'arguments' => array() ), 'r4032login_user_register' => array( 'arguments' => array() ) ); } /** * MENU_CALLBACK for /4032login * * Redirect anonymous users from 403 Access Denied pages to the /user/login page * with a message explaining that they must login to view the requested page * and a query string parameter appended to the url to return after login. */ function r4032login_redirect() { global $user; if ($user->uid == 0) { if (variable_get('r4032login_display_denied_message', TRUE)) { drupal_set_message(t('Access denied. You must login to view this page.'), 'error'); } // using drupal_goto() with destination set causes a recursive redirect loop header('Location: '. url('user/login', array('query' => 'destination='. drupal_urlencode($_REQUEST['q']), 'absolute' => TRUE)), TRUE, 302); exit; } // checking arg() returns r4032login elseif ($_REQUEST['q'] == 'user/register') { print theme('page', theme('r4032login_user_register')); exit; } else { print theme('page', theme('r4032login_denied')); exit; } } function theme_r4032login_denied() { drupal_set_title(t('Access denied')); return '
'. t('You are not authorized to access this page.') .'
'; } function theme_r4032login_user_register() { drupal_set_title(t('Access denied')); return ''. variable_get('r4032login_user_register_message', t('You are not authorized to access this page.')) .'
'; }