Problem/Motivation

When visiting a page that requires authentication, Drupal's default behavior is to display an "Access denied / You are not authorized to access this page." The Site Configuration page allows you to specify a redirect upon visiting a 403 or 404 page. The Redirect 403 to User Login provided additional configuration options.

Proposed resolution

Add the functionality of the Redirect 403 to User Login to Drupal core.

Remaining tasks

This issue needs a usability review, as tagged.
If approved, create core code for review.

User interface changes

Under Drupal 7 core only exposes a 403 redirect path field.
Enabling the module exposes the following options:

  • "Display access denied message on login page" boolean
  • "User login 'access denied' message" text input
  • "Redirect authenticated users to" text input
  • "User login 'access denied' message type select option
  • "Path to user login form" text input
  • "HTTP redirect code" select option
  • "Skip redirect for matching pages" text input for specifying exclusion paths

API changes

?

Data model changes

?

Original report by Bevan

I think this module would make an excellent addition to Drupal core. Has this been turned into a Drupal core patch already?

Comments

deekayen’s picture

Not that I'm aware of

Bevan’s picture

Title: Contribute to core » Redirect 403 to User Login
Project: Redirect 403 to User Login » Drupal core
Version: 7.x-1.x-dev » 7.x-dev
Component: Code » user system

The Redirect 403 to User Login module is a very useful feature that is desirable for most Drupal websites. It would be great to get this feature in Drupal core.

Bevan’s picture

mcaden’s picture

I was quite disappointed to find that module doesn't work...

then...

I found that I can solve the issue by adding:

<?php 
    global $user; 

    if (!user_is_logged_in() && $title == 'Access denied') 
    {
        header( 'Location: /user?destination=' . substr($_SERVER['REQUEST_URI'],1) ); 
    }
?> 

to the top of page.tpl.php in my template and it does the same thing.

(code source: http://drupalbin.com/508 - refactored to my style)

Bevan’s picture

The module does work when configured right. This is unrelated. Please post it in the forums instead. Thanks! :)

Bojhan’s picture

Issue tags: -Needs usability review, -ux

Ok, lets do this.

sun.core’s picture

Version: 7.x-dev » 8.x-dev
RobLoach’s picture

Issue tags: +403 access forbidden, +r4032login
heyehren’s picture

The easiest way to redirect to the login/ register page is by defining the path to a custom page in the Drupal settings.

Go to Configuration --> Site information and scroll down to the bottom :)

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Screenack’s picture

Issue summary: View changes

Updated the ticket using the issue template. Provide more specifics as it relates to Drupal 7 module.

Screenack’s picture

Issue summary: View changes
dawehner’s picture

What happens if you set /user/login, and one gets an access denied for the registered user?

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dpi’s picture

Status: Active » Closed (duplicate)
Related issues: +#111321: Provide a login form on Access Denied pages for anonymous users
dqd’s picture

Additionally to the Closed (duplicate) status I would like to point to the option in core to use 403 redirect settings in admin/config/system/site-information to redirect to the user/login path for any who humbles over this issue here.The only drawback covered here #2916746: Redirect subrequest via Basic site settings do not incoorporate correct theme rendering, suggestions and overrides for target path. : ...

It sadly makes the login page unstylable from top (like commonly used by many themes), since the redirect does not add the common login-form class to the HTML body tag.

apaderno’s picture

Issue tags: -403 (duplicate tag), -r4032login +403