Browse Source

Switch from using the admin login/logout pages to custom 'lemonauth' pages

pull/1/head
Danielle McLean 4 years ago
parent
commit
c210650ca7
Signed by: 00dani GPG Key ID: 5A5D2D1AFF12EEC5
  1. 0
      lemonauth/__init__.py
  2. 4
      lemonauth/static/lemonauth/css/login.styl
  3. 46
      lemonauth/templates/lemonauth/login.html
  4. 6
      lemonauth/templates/lemonauth/tags/form_field.html
  5. 0
      lemonauth/templatetags/__init__.py
  6. 8
      lemonauth/templatetags/lemonauth_tags.py
  7. 8
      lemonauth/urls.py
  8. 7
      lemonauth/views.py
  9. 5
      lemoncurry/settings/base.py
  10. 3
      lemoncurry/templates/lemoncurry/layout.html
  11. 4
      lemoncurry/templatetags/lemoncurry_tags.py
  12. 1
      lemoncurry/urls.py

0
lemonauth/__init__.py

4
lemonauth/static/lemonauth/css/login.styl

@ -0,0 +1,4 @@
.container
display flex
flex-direction column
justify-content center

46
lemonauth/templates/lemonauth/login.html

@ -0,0 +1,46 @@
{% extends 'lemoncurry/layout.html' %}
{% load lemonauth_tags static %}
{% block title %}log in ~ {{ block.super }}{% endblock %}
{% block styles %}
<link rel="stylesheet" type="text/stylus" href="{% static 'lemonauth/css/login.styl' %}" />
{% endblock %}
{% block main %}
<div class="container">
{% if form.errors %}
<p class="alert alert-danger">
<strong>Uh oh!</strong> Your username and password didn't match. Please try again.
</p>
{% endif %}
{% if next %}
{% if user.is_authenticated %}
<p class="alert alert-warning">
<strong>Hang on!</strong> Your account doesn't have access to this page. To proceed, please log in to an account that does have access.
</p>
{% else %}
<p class="alert alert-warning">
<strong>Oops!</strong> Please log in to see this page.
</p>
{% endif %}
{% endif %}
<form class="card" method="post" action="{% url 'lemonauth:login' %}">
<div class="card-body">
{% form_field form.username %}
{% form_field form.password %}
</div>
<div class="card-footer">
<button class="btn btn-primary" type="submit">
<i class="fa fa-sign-in"></i>
log in
</button>
</div>
{% csrf_token %}
<input type="hidden" name="next" value="{{ next }}" />
</form>
</div>
{% endblock %}

6
lemonauth/templates/lemonauth/tags/form_field.html

@ -0,0 +1,6 @@
<div class="form-group{% if field.errors %} has-error{% endif %}">
<label for="{{ field.id_for_label }}">{{ field.label | lower }}</label>
<input id="{{ field.id_for_label }}" class="form-control" type="{{ field.field.widget.input_type }}"
name="{{ field.html_name }}"{% if field.value %} value="{{ field.value }}"{% endif %}{% if field.help_text %} aria-describedby="{{ field.id_for_label }}-help"{% endif %} />
{% if field.help_text %}<p id="{{ field.id_for_label }}-help" class="form-text">{{ field.help_text }}</p>{% endif %}
</div>

0
lemonauth/templatetags/__init__.py

8
lemonauth/templatetags/lemonauth_tags.py

@ -0,0 +1,8 @@
from django import template
register = template.Library()
@register.inclusion_tag('lemonauth/tags/form_field.html')
def form_field(field):
return {'field': field}

8
lemonauth/urls.py

@ -0,0 +1,8 @@
from django.conf.urls import url
from . import views
app_name = 'lemonauth'
urlpatterns = [
url('^login$', views.login, name='login'),
url('^logout$', views.logout, name='logout'),
]

7
lemonauth/views.py

@ -0,0 +1,7 @@
from django.contrib.auth import views as auth_views
login = auth_views.LoginView.as_view(
template_name='lemonauth/login.html',
redirect_authenticated_user=True,
)
logout = auth_views.LogoutView.as_view()

5
lemoncurry/settings/base.py

@ -70,6 +70,7 @@ INSTALLED_APPS = [
'lemoncurry',
'home',
'lemonauth',
'users',
'wellknowns',
]
@ -147,6 +148,10 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
LOGIN_URL = 'lemonauth:login'
LOGIN_REDIRECT_URL = 'home:index'
LOGOUT_REDIRECT_URL = LOGIN_REDIRECT_URL
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

3
lemoncurry/templates/lemoncurry/layout.html

@ -1,7 +1,7 @@
{% load compress favtags lemoncurry_tags meta static %}<!doctype html>
<html lang="en" class="{% block html_class %}{% endblock %}">
<head{% meta_namespaces %}>
<title class="p-name">{% site_name %}</title>
<title class="p-name">{% block title %}{% site_name %}{% endblock %}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
{% include 'meta/meta.html' %}
@ -11,6 +11,7 @@
integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous" />
{% compress css %}
<link rel="stylesheet" type="text/stylus" href="{% static 'lemoncurry/css/layout.styl' %}" />
{% block styles %}{% endblock %}
{% endcompress %}
<script type="text/javascript" src="https://use.fontawesome.com/4fbab4ae27.js"></script>
</head>

4
lemoncurry/templatetags/lemoncurry_tags.py

@ -43,10 +43,10 @@ def nav_right(request):
if request.user.is_authenticated():
items = (
MenuItem(label='admin', icon='fa fa-gear', url='admin:index'),
MenuItem(label='log out', icon='fa fa-sign-out', url='admin:logout'),
MenuItem(label='log out', icon='fa fa-sign-out', url='lemonauth:logout'),
)
else:
items = (
MenuItem(label='log in', icon='fa fa-sign-in', url='admin:login'),
MenuItem(label='log in', icon='fa fa-sign-in', url='lemonauth:login'),
)
return {'items': items}

1
lemoncurry/urls.py

@ -28,6 +28,7 @@ urlpatterns = [
url('', include('home.urls')),
url('^.well-known/', include('wellknowns.urls')),
url('^admin/', admin.site.urls),
url('^auth/', include('lemonauth.urls')),
url(r'^sitemap\.xml$', sitemap.index, maps),
url(r'^sitemaps/(?P<section>.+)\.xml$', sitemap.sitemap, maps,

Loading…
Cancel
Save