Commit 7802c245 authored by Stefan Bunde's avatar Stefan Bunde
Browse files

Merge branch 'master' into '2018-04-tb-ldap'

parents f2511c7e 3a2f32a4
image: node:8.11.1-stretch
before_script:
- apt-get update --q && apt-get install -y -qq python3 python3-venv
- git config user.email "gitlab-ci@example.com"
- git fetch origin master
- git merge origin/master --no-ff
stages:
- test
test:
stage: test
script: echo "Running tests"
dist/
*.egg-info/
node_modules/
*.pyc
*.sqlite3
......@@ -15,8 +15,11 @@ makemigrations:
$(MANAGEPY) makemigrations
createsuperuser:
$(MANAGEPY) shell -c "from django.contrib.auth.models import User; User.objects.filter(username='admin') or User.objects.create_superuser('admin', 'admin@example.com', '123')"
$(MANAGEPY) shell -c "from castellum_auth.models import User; User.objects.filter(username='admin') or User.objects.create_superuser('admin', 'admin@example.com', '123')"
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/
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import User
admin.site.register(User, UserAdmin)
from django.apps import AppConfig
class CastellumAuthConfig(AppConfig):
name = 'castellum_auth'
# Generated by Django 2.0.4 on 2018-04-11 11:36
import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0009_alter_user_last_name_max_length'),
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'abstract': False,
'verbose_name_plural': 'users',
'verbose_name': 'user',
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
]
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
pass
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'i#$kwk(s24ysn+l%+c!*z9u4+45)oex!-s#!bux#wf2pv2cc0d'
DEBUG = True
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
ALLOWED_HOSTS = []
......@@ -19,6 +15,9 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bootstrap4',
'castellum_auth.apps.CastellumAuthConfig',
]
MIDDLEWARE = [
......@@ -36,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': [
......@@ -52,16 +53,6 @@ TEMPLATES = [
WSGI_APPLICATION = 'castellum_core.wsgi.application'
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
AUTH_PASSWORD_VALIDATORS = [
......@@ -92,6 +83,11 @@ AUTH_LDAP_BIND_DN = 'cn=admin,dc=example,dc=org'
AUTH_LDAP_BIND_PASSWORD = 'admin'
AUTH_LDAP_USER_SEARCH = LDAPSearch('dc=example,dc=org', ldap.SCOPE_SUBTREE, '(uid=%(user)s)')
AUTH_USER_MODEL = 'castellum_auth.User'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
# Internationalization
......@@ -108,4 +104,8 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_URL = '/static/'
from .default import *
SECRET_KEY = 'i#$kwk(s24ysn+l%+c!*z9u4+45)oex!-s#!bux#wf2pv2cc0d'
DEBUG = True
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
from django.contrib import admin
from django.urls import path
from django.contrib.auth import views as auth_views
from django.views.generic import TemplateView
urlpatterns = [
path('', TemplateView.as_view(template_name='index.html'), name='index'),
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 "Start" %} &middot; {{ block.super }}{% endblock %}
{% block content %}
{% if request.user.is_authenticated %}
<div>
{% if request.user.is_superuser %}
<div>You are logged in as admin</div>
{% else %}
<div>You are not listed as admin</div>
{% endif %}
<div>You are registered since {{ request.user.date_joined|timesince}}</div>
</div>
{% else %}
<div>
Not logged in
</div>
{% endif %}
{% endblock %}
{% 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"
}
}
......@@ -12,5 +12,6 @@ setup(
install_requires=[
"Django==2.0.4",
"django-auth-ldap==1.4.0",
"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