Commit 28389228 authored by Timo's avatar Timo
Browse files

Merge branch '2018-04-tb-auth-views' into 'master'

258: auth views

See merge request !7
parents 61eb6429 7051f913
dist/
*.egg-info/
node_modules/
*.pyc
*.sqlite3
......@@ -20,3 +20,6 @@ createsuperuser:
install:
pip install tox ipdb
pip install -e .
npm install
mkdir -p castellum_core/static/
cp node_modules/bootstrap/dist/css/bootstrap.min.css castellum_core/static/
......@@ -15,6 +15,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bootstrap4',
'castellum_auth.apps.CastellumAuthConfig',
]
......@@ -34,7 +35,9 @@ ROOT_URLCONF = 'castellum_core.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -69,6 +72,9 @@ AUTH_PASSWORD_VALIDATORS = [
AUTH_USER_MODEL = 'castellum_auth.User'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
# Internationalization
......@@ -85,4 +91,8 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_URL = '/static/'
from django.contrib import admin
from django.urls import path
from django.contrib.auth import views as auth_views
urlpatterns = [
path('login/', auth_views.LoginView.as_view(template_name="login.html"), name='login'),
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
path('admin/', admin.site.urls),
]
<!DOCTYPE html>
{% load i18n static bootstrap4 %}
{% get_current_language as LANGUAGE_CODE %}
<html lang="{{ LANGUAGE_CODE }}">
<head>
<meta charset="utf-8" />
<title>{% block title %}Castellum{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% static 'bootstrap.min.css' %}" />
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Security-Policy" content="default-src 'self'" />
</head>
<body>
<header class="bg-dark">
<div class="container">
<div class="row navbar navbar-dark">
<a href="/" rel="home" class="navbar-brand">Castellum</a>
{% if request.user.is_authenticated %}
<div>
<span class="navbar-text">{{ request.user }}</span>
<a href="{% url 'logout' %}?next={{ request.get_full_path|iriencode }}" class="btn btn-secondary">{% trans 'Logout' %}</a>
</div>
{% else %}
<a href="{% url 'login' %}?next={{ request.get_full_path|iriencode }}" class="btn btn-primary">{% trans 'Login' %}</a>
{% endif %}
</div>
</div>
</header>
<main class="container pt-3">
<div class="row justify-content-center">
<div class="col-lg-8 col-md-10">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li class="alert {{ message.tags }}" role="alert">
{{ message }}
</li>
{% endfor %}
</ul>
{% endif %}
{% block content %}{% endblock %}
</div>
</div>
</main>
</body>
</html>
{% extends "base.html" %}
{% load i18n bootstrap4 %}
{% block title %}{% trans "Log in" %} &middot; {{ block.super }}{% endblock %}
{% block content %}
<form method="post" action="{% url 'login' %}">
{% for error in form.non_field_errors %}
<p class="alert alert-danger" role="alert">{{ error }}</p>
{% endfor %}
{% csrf_token %}
{% bootstrap_field form.username %}
{% bootstrap_field form.password %}
<input type="submit" class="btn btn-primary" value="{% trans 'Login' %}" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
{% endblock %}
{
"name": "castellum-core",
"dependencies": {
"bootstrap": "^4.0.0"
}
}
......@@ -11,5 +11,6 @@ setup(
install_requires=[
"Django==2.0.4",
"django-bootstrap4==0.0.6",
],
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment