Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

Commit b9ff851b authored by Kris Steinhoff's avatar Kris Steinhoff
Browse files

Merge branch 'login-views' into 'master'

Login views

Closes #1

See merge request !3
parents 72fd877e 160a6a7e
Pipeline #17843 passed with stage
in 32 seconds
......@@ -144,4 +144,5 @@ cython_debug/
# Misc
\ No newline at end of file
\ No newline at end of file
import unicodedata
from django.conf import settings
from mozilla_django_oidc.auth import OIDCAuthenticationBackend
def using_oidc_auth():
return (
settings.OIDC_RP_CLIENT_ID and
def generate_username(email):
return unicodedata.normalize('NFKC', email).split('@')[0]
from django.urls import reverse
from django.conf import settings
from oidc_auth.auth import using_oidc_auth
def login_url(request):
return {'LOGIN_URL': settings.LOGIN_URL}
def logout_url(request):
return {'LOGOUT_URL': reverse('oidc_logout') if using_oidc_auth() else reverse('logout')}
{% extends "base.html" %}
{% block content %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
{% if next %}
{% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed,
please login with an account that has access.</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}
<div class="card">
<div class="card-body">
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<div class="form-row">
<div class="form-group col-md-6">
<label for="username">Username</label>
<input class="form-control" type="text" placeholder="Username" autofocus autocapitalize="none" autocomplete="username" maxlength="150" required id="username">
<div class="form-group col-md-6">
<label for="password">Password</label>
<input class="form-control" type="password" placeholder="Password" autofocus autocomplete="current-password" required id="password">
<button type="submit" class="btn btn-primary">Login</button>
<input type="hidden" name="next" value="{{ next }}">
<div class="card-footer">
<a href="{% url 'password_reset' %}">Lost password?</a>
{% endblock %}
from django.conf.urls import url
from django.urls import include
from django.urls import include, path
from oidc_auth.auth import using_oidc_auth
urlpatterns = [
url(r'^oidc/', include('mozilla_django_oidc.urls')),
if not using_oidc_auth():
urlpatterns += [path('accounts/', include('django.contrib.auth.urls'))]
......@@ -92,6 +92,8 @@ TEMPLATES = [
......@@ -108,12 +110,10 @@ AUTHENTICATION_BACKENDS = [
LOGIN_URL = '/accounts/login/'
if DEBUG is True:
LOGIN_URL = '/admin'
# Mozilla OIDC
......@@ -30,15 +30,15 @@
<a class="nav-link dropdown-toggle" href="#" id="userMenu" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ request.user.username }}
<div class="dropdown-menu" aria-labelledby="userMenu">
<form action="{% url 'oidc_logout' %}" method="post">
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="userMenu">
<form action="{{ LOGOUT_URL }}" method="post">
{% csrf_token %}
<input type="submit" value="logout" style="background-color: white" class="dropdown-item">
{% else %}
<a href="{% url 'oidc_authentication_init' %}" class="nav-link">Login</a>
<a href="{{ LOGIN_URL }}" class="nav-link">Login</a>
{% endif %}
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