Skip to content
Permalink
Browse files

User Accounts with Signup/Login (Authentication)

  • Loading branch information...
KalobTaulien committed Sep 9, 2019
1 parent 6109533 commit 6ab586eb420e09c5a79c00f4040d3969caeee3a6
Showing with 104 additions and 1 deletion.
  1. +31 −0 mysite/settings/base.py
  2. +57 −0 mysite/templates/account/login.html
  3. +12 −0 mysite/templates/base.html
  4. +3 −1 mysite/urls.py
  5. +1 −0 requirements.txt
@@ -62,12 +62,19 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sitemaps',
'django.contrib.sites',

'captcha',
'wagtailcaptcha',
'rest_framework',

'allauth',
'allauth.account',
'allauth.socialaccount',
]

SITE_ID = 1

MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
@@ -102,6 +109,13 @@
},
]

AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
'django.contrib.auth.backends.ModelBackend',
# `allauth` specific authentication methods, such as login by e-mail
'allauth.account.auth_backends.AuthenticationBackend',
)

WSGI_APPLICATION = 'mysite.wsgi.application'


@@ -188,3 +202,20 @@
RECAPTCHA_PUBLIC_KEY = "6LcNrZcUAAAAAADyWEJTIOXKr6x-8POg3Iqp8rEM"
RECAPTCHA_PRIVATE_KEY = "6LcNrZcUAAAAAPISF06kecWBC4EJPXy2uo_penMC"
NOCAPTCHA = True


LOGIN_URL = '/login/'
LOGIN_REDIRECT_URL = '/'
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
ACCOUNT_CONFIRM_EMAIL_ON_GET = True
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True
ACCOUNT_LOGOUT_ON_GET = True
ACCOUNT_LOGIN_ON_PASSWORD_RESET = True
ACCOUNT_LOGOUT_REDIRECT_URL = '/login/'
ACCOUNT_PRESERVE_USERNAME_CASING = False
ACCOUNT_SESSION_REMEMBER = True
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = False
ACCOUNT_USERNAME_BLACKLIST = ["kalob", "admin", "god"]
ACCOUNT_USERNAME_MIN_LENGTH = 2
@@ -0,0 +1,57 @@
{% extends "account/base.html" %}

{% load i18n %}
{% load account socialaccount %}

{% block title %}{% trans "Sign In" %}{% endblock %}

{% block content %}

<div class="container mt-5 mb-5">
<div class="row">
<div class="col-md-6 offset-md-3">


<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.as_p }}
{% 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 In" %}</button>

<a class="btn btn-link" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>

</form>
</div>
</div>
</div>

{% endblock %}
@@ -53,6 +53,18 @@
{% endfor %}
{% endcache %}
</ul>
<ul class="navbar-nav">
<li class="nav-item">
{% if request.user.is_authenticated %}
Hi {{ request.user.username }},
<a href="{% url 'account_logout' %}" class="nav-link d-inline">Logout?</a>
{% else %}
Hi Guest!
<a href="{% url 'account_login' %}" class="nav-link d-inline">Login?</a>

{% endif %}
</li>
</ul>
<!--
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search">
@@ -24,6 +24,8 @@
url(r'^api/v2/', api_router.urls),

url(r'^sitemap.xml$', sitemap),
url(r'', include('allauth.urls')),
# url(r'^accounts/', include('allauth.urls')),
# For anything not caught by a more specific rule above, hand over to
# Wagtail's page serving mechanism. This should be the last pattern in
# the list:
@@ -46,4 +48,4 @@
import debug_toolbar
urlpatterns = [
path('__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
] + urlpatterns
@@ -7,3 +7,4 @@ black==19.3b0
flake8
isort
wagtail-django-recaptcha==1.0
django-allauth==0.40.0

1 comment on commit 6ab586e

Please sign in to comment.
You can’t perform that action at this time.