From 7f3354e3559eca30b78ef49b65c07ea539edeed4 Mon Sep 17 00:00:00 2001 From: lhark Date: Fri, 8 Jul 2016 20:11:53 +0200 Subject: [PATCH] Add login system --- re2o/settings.py | 8 ++++++-- re2o/urls.py | 3 +++ templates/base.html | 12 +++++++++++- templates/registration/login.html | 32 +++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 templates/registration/login.html diff --git a/re2o/settings.py b/re2o/settings.py index d1a7b122..8788c33e 100644 --- a/re2o/settings.py +++ b/re2o/settings.py @@ -29,6 +29,8 @@ PASSWORD_HASHERS = ( ) AUTH_USER_MODEL = 'users.User' +LOGIN_URL = '/login' +LOGIN_REDIRECT_URL = '/' # Application definition @@ -80,6 +82,10 @@ TEMPLATES = [ }, ] +TEMPLATE_CONTEXT_PROCESSORS = ( + 'django.core.context_processors.request', + ) + WSGI_APPLICATION = 're2o.wsgi.application' @@ -119,5 +125,3 @@ STATICFILES_DIRS = ( STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static_files') - -LOGIN_URL = '/admin/' diff --git a/re2o/urls.py b/re2o/urls.py index fe6776d8..01d86a88 100644 --- a/re2o/urls.py +++ b/re2o/urls.py @@ -14,11 +14,14 @@ Including another URLconf """ from django.conf.urls import include, url from django.contrib import admin +from django.contrib.auth import views as auth_views from logs.views import index urlpatterns = [ url(r'^$', index), + url('^logout/', auth_views.logout, {'next_page': '/'}), + url('^', include('django.contrib.auth.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^users/', include('users.urls', namespace='users')), url(r'^search/', include('search.urls', namespace='search')), diff --git a/templates/base.html b/templates/base.html index 544c0952..75c56b1c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -46,7 +46,17 @@ diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 00000000..66b1644f --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,32 @@ +{% extends "base.html" %} + +{% load bootstrap3 %} + +{% block title %}Login{% endblock %} + +{% block content %} + +{% if form.errors %} +

Your username and password didn't match. Please try again.

+{% endif %} + +{% if next %} + {% if user.is_authenticated %} +

Your account doesn't have access to this page. To proceed, + please login with an account that has access.

+ {% else %} +

Please login to see this page.

+ {% endif %} +{% endif %} + +
+ {% csrf_token %} + {% bootstrap_form form %} + {% bootstrap_button "Login" button_type="submit" icon="log-in" %} + +
+ +{# Assumes you setup the password_reset view in your URLconf #} +{#

Lost password?

#} + +{% endblock %}