5

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.

Brachamul
  • 1,886
  • 2
  • 21
  • 34

3 Answers3

4

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)),
]
Erick M
  • 465
  • 4
  • 9
  • I am able to override the login url, but it is not redirecting me to CMS admin. Instead it always redirect me to dashboard even though redirect url is present in the url bar. – Tasawer Nawaz Jun 25 '19 at 07:07
2

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

Martey
  • 1,631
  • 2
  • 13
  • 23
  • Wagtail seems to ignore that setting... still redirecting to `/cms/login/` – Brachamul Jun 24 '17 at 21:40
  • What version of wagtail are you using? – Martey Jun 25 '17 at 00:59
  • Latest version, 1.10.1 – Brachamul Jun 28 '17 at 07:43
  • Verify that this isn't an artifact of how your custom authentication system works and file an issue on Wagtail's bug tracker? – Martey Jun 28 '17 at 21:27
  • It seems `WAGTAIL_FRONTEND_LOGIN_URL` is specifically intended just for front end users and there is not an equivalent setting for admin users. You could use [`redirect_to_login`](https://docs.djangoproject.com/en/2.0/topics/auth/default/#django.contrib.auth.views.redirect_to_login) – Erick M Apr 17 '18 at 06:20
1

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.

Bas
  • 11
  • 2