7

I have managed to do this in Drupal 7 with the following code:

function my_special_paths_menu() {

    $items['authenticate'] = array(
        'title' => 'Log in',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('user_login'),   
        'access callback' => 'user_is_anonymous',   
      );
     return $items;
    }

My question, is this code complete or is it missing some configuration in the menu item array? Is the code safe the way it is?

7

Yes, your code is complete, and is as safe as the default login form.

However, do bear in mind that if you want to replace the /user/login form, you will need to think about all scenarios in which users might end up there (e.g. [site:login-url] token, other modules, etc.) and handle them appropriately via redirects or access denied response (e.g. if you will be the only registered user on the site).

Here are the basics:

Redirecting

If you want to redirect users from /user/login to /authenticate for whatever reason, you will either need to use the Redirect module, or implement hook_menu_alter() in your custom module:

function YOUR_MODULE_menu_alter(&$items) {
  $items['user/login']['page callback'] = 'drupal_goto';
  $items['user/login']['page arguments'] = 'authenticate';
}

Replacing

If you want to make /user/login inaccessible to all other users, you can simply disable that path by again implementing the hook_menu_alter() in your custom module:

function YOUR_MODULE_menu_alter(&$items) {
  $items['user/login']['access callback'] = FALSE;
}

However, do bear in mind that you will have to test everything thoroughly and make sure that you have no modules that depend on the system /user/login, as well as that there are no workflows that will be affected (e.g. [site:login-url] tokens).

Hope this helps.

0

I've used Rename Admin Paths on one of my sites to have another URL instead of /user/... and /admin/... Works great, right out of the box.

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.