Commit 05a73122 authored by cynddl's avatar cynddl

Initial support for django-allauth: account signup/login/logout

parent 50cdd3ae
......@@ -11,6 +11,7 @@ DJANGO_APPS = [
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.contenttypes",
"django.contrib.sites"
]
CONTRIB_APPS = [
......@@ -20,7 +21,11 @@ CONTRIB_APPS = [
# https://github.com/philipn/django-rest-framework-filters
# "rest_framework_filters",
"taggit",
"crispy_forms"
"crispy_forms",
"allauth",
"allauth.account",
"allauth.socialaccount",
]
if DEBUG:
......
......@@ -12,6 +12,8 @@ AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
# Email or Username for login
"core.auth_backends.EmailOrUsernameModelBackend",
# Use django-allauth for authentication
"allauth.account.auth_backends.AuthenticationBackend",
]
# Password validation
......@@ -35,3 +37,7 @@ AUTH_PASSWORD_VALIDATORS = [
"NumericPasswordValidator"),
},
]
# Disable two steps logout
ACCOUNT_LOGOUT_ON_GET = True
......@@ -17,7 +17,8 @@ router.extend(rp_router)
urlpatterns = [
url(r"^admin/", admin.site.urls),
url(r"^api/", include(router.urls, namespace="api")),
url(r"^rp/", include("rp.urls", namespace="rp"))
url(r"^rp/", include("rp.urls", namespace="rp")),
url(r'^accounts/', include('allauth.urls')),
]
if settings.DEBUG:
......
{% extends "base.html" %}
{% load i18n %}
{% load account socialaccount %}
{% load crispy_forms_tags %}
{% block head_title %}{% trans "Sign In" %}{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-sm-6">
<h1>{% trans "Sign In" %}</h1>
{% get_providers as socialaccount_providers %}
{% if socialaccount_providers %}
<p>{% blocktrans with site.name as site_name %}Please sign in with one
of your existing third party accounts. Or, <a href="{{ signup_url }}">sign up</a>
for a {{ site_name }} account and sign in below:{% endblocktrans %}</p>
<div class="socialaccount_ballot">
<ul class="socialaccount_providers">
{% include "socialaccount/snippets/provider_list.html" with process="login" %}
</ul>
<div class="login-or">{% trans 'or' %}</div>
</div>
{% include "socialaccount/snippets/login_extra.html" %}
{% else %}
<p>{% blocktrans %}If you have not created an account yet, then please
<a href="{{ signup_url }}">sign up</a> first.{% endblocktrans %}</p>
{% endif %}
<form class="login" method="POST" action="{% url 'account_login' %}">
{% csrf_token %}
{{ form | crispy }}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<a class="btn btn-secondary" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>
<button class="btn btn-primary" type="submit">{% trans "Sign In" %}</button>
</form>
</div>
{% endblock %}
{% extends "account/base.html" %}
{% load i18n %}
{% load account %}
{% load crispy_forms_tags %}
{% block head_title %}{% trans "Password Reset" %}{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-sm-6">
<h1>{% trans "Password Reset" %}</h1>
{% if user.is_authenticated %}
{% include "account/snippets/already_logged_in.html" %}
{% endif %}
<p>{% trans "Forgotten your password? Enter your e-mail address below, and we'll send you an e-mail allowing you to reset it." %}</p>
<form method="POST" action="{% url 'account_reset_password' %}" class="password_reset">
{% csrf_token %}
{{ form | crispy }}
<input class="btn btn-primary" type="submit" value="{% trans 'Reset My Password' %}" />
</form>
<p>{% blocktrans %}Please contact us if you have any trouble resetting your password.{% endblocktrans %}</p>
</div>
</div>
{% endblock %}
{% extends "account/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block head_title %}{% trans "Signup" %}{% endblock %}
{% block content %}
<div class="row justify-content-center">
<div class="col-sm-6">
<h1>{% trans "Sign Up" %}</h1>
<p>{% blocktrans %}Already have an account? Then please <a href="{{ login_url }}">sign in</a>.{% endblocktrans %}</p>
<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">
{% csrf_token %}
{{ form | crispy }}
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
{% endif %}
<button class="btn btn-primary" type="submit">{% trans "Sign Up" %} &raquo;</button>
</form>
</div>
</div>
{% endblock %}
......@@ -19,86 +19,18 @@
<link rel="stylesheet" href="{% static 'app.bundle.css' %}">
</head>
<body>
<div class="modal-form " id="login">
<div class="modal-form-title modal-form-only">
<a class="close modal-form-only" href="/#"><span>Fermer</span></a>
<h1>Se connecter</h1>
</div>
<form method="POST" class="form-inline" action="/login">
<div class="modal-form-body">
<input type="hidden" name="csrf" id="csrf" value="f0c2e16b60242fe65b800778d3b90f91" />
<fieldset class="form-group modal-form-only">
<div class="modal-row form-group">
<label for="email">Adresse mail</label>
<input class="form-control" type="email" name="email" id="email" required>
</div>
<div class="modal-row form-group">
<label for="password">Mot de passe</label>
<input class="form-control" type="password" name="password" id="password" required>
</div>
<div class="modal-row">
<a href="#password-reset">Réinitialiser votre mot de passe</a>
<input class="btn btn-lg btn-modal" type="submit" name="submit" id="submit" value="Connexion">
</div>
</fieldset>
</div>
</form>
</div>
<div class="modal-form" id="add-account">
<div class="modal-form-title modal-form-only">
<a class="close modal-form-only" href="#"><span>Fermer</span></a>
<h1>Créer un compte</h1>
</div>
<form method="POST" class="form-inline" action="/login">
<div class="modal-form-body">
<input type="hidden" name="csrf" id="csrf" value="f0c2e16b60242fe65b800778d3b90f91" />
<input type="hidden" name="action" id="action" value="create_account" />
<fieldset class="form-group modal-form-only">
<div class="modal-row form-group">
<label for="email">Adresse mail</label>
<input class="form-control" type="email" name="email" id="email" required>
</div>
<div class="modal-row form-group">
<label for="password">Mot de passe</label>
<input class="form-control" type="password" name="password" id="password" required>
</div>
<div class="modal-row">
<input class="btn btn-lg btn-modal" type="submit" name="submit" id="submit" value="Création du compte">
</div>
</fieldset>
</div>
</form>
</div>
<div class="modal-form" id="password-reset">
<div class="modal-form-title modal-form-only">
<a class="close modal-form-only" href="/#"><span>Fermer</span></a>
<h1>Réinitialiser votre mot de passe</h1>
</div>
<form method="POST" class="form-inline" action="/login">
<div class="modal-form-body">
<input type="hidden" name="csrf" id="csrf" value="f0c2e16b60242fe65b800778d3b90f91" />
<input type="hidden" name="action" id="action" value="renew_password" />
<fieldset class="form-group modal-form-only">
<div class="modal-row form-group">
<label for="email">Adresse mail</label>
<input class="form-control" type="email" name="email" id="email" required>
</div>
<div class="modal-row">
<input class="btn btn-lg btn-modal" type="submit" name="submit" id="submit" value="Réinitialiser le mot de passe">
</div>
</fieldset>
</div>
</form>
</div>
<div>
<nav class="navbar navbar-sm sticky-top navbar-toggleable-md dark-blue-bg">
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="nav-link" href="#add-account">Créer un compte</a></li>
<li class="nav-item"><a class="nav-link" href="#login">Se connecter</a></li>
{% if user.is_authenticated %}
{% comment %} <li class="nav-item"><a class="nav-link" href="{% url 'account_profile' %}">Mon profile</a></li> {% endcomment %}
<li class="nav-item"><a class="nav-link" href="{% url 'account_logout' %}">Déconnexion</a></li>
{% else %}
<li class="nav-item"><a class="nav-link" href="{% url 'account_signup' %}">Créer un compte</a></li>
<li class="nav-item"><a class="nav-link" href="{% url 'account_login' %}">Se connecter</a></li>
{% endif %}
<li class="nav-item"><a class="nav-link" href="https://soutien.laquadrature.net">[FR]</a></li>
<li class="nav-item"><a class="nav-link" href="https://support.laquadrature.net">[EN]</a></li>
</ul>
......@@ -108,13 +40,17 @@
<nav class="navbar navbar-toggleable-md">
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<a class="navbar-brand" href="/"><img class="float-left" src="/static/img/logo.png" alt=""></a>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#add-account">
{% if user.is_authenticated %}
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link">
Vous êtes Padawan<img class="inline-image ml-2" role="img" src="{% static 'img/padawan.svg' %}" />
</a>
</li>
</ul>
</a>
</li>
</ul>
{% else %}
<span class="navbar-text ml-auto text-muted">For jedis by jedis</span>
{% endif %}
</div>
</nav>
</div>
......
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