Brachamul
Brachamul

Reputation: 1974

How to override wagtail authentication?

When I attempt to access my wagtail back-office at /cms/, I get redirected to wagtail's login page, /cms/login/.

However, I would like to use my own custom login, which is default for the rest of the site, and sits at /auth/.

My LOGIN_URL is already set to /auth/ in django settings.

EDIT : it's been suggested that this is a generic question of how do you override namespaced url patterns but this is not the case. The urls are not namespaced, and I was looking for wagtail functionality that adressed this specific issue. Fortunately, that functionality does exist.

Upvotes: 5

Views: 2975

Answers (3)

Bas
Bas

Reputation: 21

To elaborate on Erick M's answer, since this is the working answer:

You do need to set the correct permission (wagtailadmin.access_admin) or set the is_superuser flag in Django's auth_user database table to be able to access the CMS, otherwise you still get a "permission denied" error.

I thought this had to do with my implementation, but it was already working, but failed because of the above reason.

Upvotes: 1

Erick M
Erick M

Reputation: 485

WAGTAIL_FRONTEND_LOGIN_URL suggested above is specifically intended just for front end users and there is not an equivalent setting for admin users. You could use redirect_to_login like so:

from django.contrib.auth.views import redirect_to_login
from django.urls import reverse

from wagtail.admin import urls as wagtailadmin_urls


def redirect_to_my_auth(request):
    return redirect_to_login(reverse('wagtailadmin_home'), login_url='myauth:login')



urlpatterns = [
    url(r'^cms/login', redirect_to_my_auth, name='wagtailadmin_login'),
    url(r'^cms/', include(wagtailadmin_urls)),
]

Upvotes: 4

Martey
Martey

Reputation: 1631

The Wagtail setting WAGTAIL_FRONTEND_LOGIN_URL allows you to configure how users login to the Wagtail admin.

From http://docs.wagtail.io/en/v1.10.1/advanced_topics/privacy.html#setting-up-a-login-page:

If the stock Django login view is not suitable - for example, you wish to use an external authentication system, or you are integrating Wagtail into an existing Django site that already has a working login view - you can specify the URL of the login view via the WAGTAIL_FRONTEND_LOGIN_URL setting

Upvotes: 2

Related Questions