Skip to content

Commit

Permalink
Merge pull request #390 from farridav/feature/password-reset
Browse files Browse the repository at this point in the history
Feature/password reset
  • Loading branch information
farridav authored Mar 27, 2022
2 parents 942504a + 9cd2702 commit d067e13
Show file tree
Hide file tree
Showing 12 changed files with 414 additions and 144 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ test_app: check-venv ## Run the test app
@printf "$(CYAN)Running test app$(COFF)\n"
$(environment) python tests/test_app/manage.py migrate
$(environment) python tests/test_app/manage.py runserver_plus

test_user: ## Make the test user
$(environment) python tests/test_app/manage.py shell -c "from django.contrib.auth.models import User; User.objects.create_superuser('[email protected]', password='test')"
195 changes: 68 additions & 127 deletions jazzmin/templates/admin/login.html
Original file line number Diff line number Diff line change
@@ -1,135 +1,76 @@
{% load i18n static jazzmin admin_urls %}
{% get_current_language as LANGUAGE_CODE %}
{% get_current_language_bidi as LANGUAGE_BIDI %}
{% extends "registration/base.html" %}

{% load i18n jazzmin %}
{% get_jazzmin_settings request as jazzmin_settings %}
{% get_jazzmin_ui_tweaks as jazzmin_ui %}

<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">

<title>{% block title %}{{ title }} | {% trans 'Log in again' %}{% endblock %}</title>

<!-- Font Awesome Icons -->
<link rel="stylesheet" href="{% static "vendor/fontawesome-free/css/all.min.css" %}">

<!-- Bootstrap and adminLTE -->
<link rel="stylesheet" href="{% static "vendor/adminlte/css/adminlte.min.css" %}">

<!-- Bootswatch theme -->
{% if jazzmin_ui.theme.name != 'default' %}
<link rel="stylesheet" href="{{ jazzmin_ui.theme.src }}" id="jazzmin-theme" />
{% endif %}

{% if jazzmin_ui.dark_mode_theme %}
<link rel="stylesheet" href="{{ jazzmin_ui.dark_mode_theme.src }}" id="jazzmin-dark-mode-theme" media="(prefers-color-scheme: dark)"/>
{% endif %}

<!-- Custom fixes for django -->
<link rel="stylesheet" href="{% static "jazzmin/css/main.css" %}">

{% if jazzmin_settings.custom_css %}
<!-- Custom CSS -->
<link rel="stylesheet" href="{% static jazzmin_settings.custom_css %}">
{% endif %}

<!-- favicons -->
<link rel="shortcut icon" href="{% static jazzmin_settings.site_icon %}" type="image/png">
<link rel="icon" href="{% static jazzmin_settings.site_icon %}" sizes="32x32" type="image/png">

<!-- Google Font: Source Sans Pro -->
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">

{% block extrastyle %} {% endblock %}
{% block extrahead %} {% endblock %}
</head>
<body class="hold-transition jazzmin-login-page">

<div class="login-box">
<div class="login-logo">
<h1><img src="{% static jazzmin_settings.site_logo %}" alt="{{ jazzmin_settings.site_header }}"></h1>
</div>

<div class="card">
<div class="card-body">
<p class="login-box-msg">{{ jazzmin_settings.welcome_sign }}</p>
<form action="{{ app_path }}" method="post">
{% csrf_token %}
{% if user.is_authenticated %}
<p class="errornote">
<div class="callout callout-danger">
<p>
{% blocktrans trimmed %}
You are authenticated as {{ username }}, but are not authorized to
access this page. Would you like to login to a different account?
{% endblocktrans %}
</p>
</div>
{% block content %}
<p class="login-box-msg">{{ jazzmin_settings.welcome_sign }}</p>
<form action="{{ app_path }}" method="post">
{% csrf_token %}
{% if user.is_authenticated %}
<p class="errornote">
<div class="callout callout-danger">
<p>
{% blocktrans trimmed %}
You are authenticated as {{ username }}, but are not authorized to
access this page. Would you like to login to a different account?
{% endblocktrans %}
</p>
{% endif %}
{% if form.errors %}

{% if form.username.errors %}
<div class="callout callout-danger">
<p>{{ form.username.label }}: {{ form.username.errors|join:', ' }}</p>
</div>
{% endif %}

{% if form.password.errors %}
<div class="callout callout-danger">
<p>{{ form.password.label }}: {{ form.password.errors|join:', ' }}</p>
</div>
{% endif %}

{% if form.non_field_errors %}
<div class="callout callout-danger">
{% for error in form.non_field_errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}

{% endif %}
<div class="input-group mb-3">
<input type="text" name="username" class="form-control" placeholder="{{ form.username.label }}" required>
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-user"></span>
</div>
</div>
</div>
<div class="input-group mb-3">
<input type="password" name="password" class="form-control" placeholder="{{ form.password.label }}" required>
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</p>
{% endif %}
{% if form.errors %}
{% if form.username.errors %}
<div class="callout callout-danger">
<p>{{ form.username.label }}: {{ form.username.errors|join:', ' }}</p>
</div>
<div class="row">
<div class="col-12">
<button type="submit" class="btn {{ jazzmin_ui.button_classes.primary }} btn-block">{% trans "Log in" %}</button>
</div>
{% endif %}
{% if form.password.errors %}
<div class="callout callout-danger">
<p>{{ form.password.label }}: {{ form.password.errors|join:', ' }}</p>
</div>
</form>

{% endif %}
{% if form.non_field_errors %}
<div class="callout callout-danger">
{% for error in form.non_field_errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
{% endif %}
<div class="input-group mb-3">
<input type="text" name="username" class="form-control" placeholder="{{ form.username.label }}" required>
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-user"></span>
</div>
</div>
</div>
</div>
</div>

<!-- jQuery -->
<script src="{% static "admin/js/vendor/jquery/jquery.js" %}"></script>
<!-- Bootstrap 4 -->
<script src="{% static 'vendor/bootstrap/js/bootstrap.min.js' %}"></script>
<!-- AdminLTE App -->
<script src="{% static 'vendor/adminlte/js/adminlte.min.js' %}"></script>

{% if jazzmin_settings.custom_js %}
<script src="{% static jazzmin_settings.custom_js %}"></script>
{% endif %}

</body>
</html>
<div class="input-group mb-3">
<input type="password" name="password" class="form-control" placeholder="{{ form.password.label }}" required>
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
{% url 'admin_password_reset' as password_reset_url %}
{% if password_reset_url %}
<div class="mb-3">
<div class="password-reset-link" style="text-align: center;">
<a href="{{ password_reset_url }}">
{% trans 'Forgotten your password or username?' %}
</a>
</div>
</div>
{% endif %}
<div class="row">
<div class="col-12">
<button type="submit" class="btn {{ jazzmin_ui.button_classes.primary }} btn-block">
{% trans "Log in" %}
</button>
</div>
</div>
</form>
{% endblock %}
75 changes: 75 additions & 0 deletions jazzmin/templates/registration/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{% load i18n static jazzmin admin_urls %}
{% get_current_language as LANGUAGE_CODE %}
{% get_current_language_bidi as LANGUAGE_BIDI %}
{% get_jazzmin_settings request as jazzmin_settings %}
{% get_jazzmin_ui_tweaks as jazzmin_ui %}

<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %}>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">

<title>{% block title %}{{ title }} | {{ jazzmin_settings.site_title }}{% endblock %}</title>

<!-- Font Awesome Icons -->
<link rel="stylesheet" href="{% static "vendor/fontawesome-free/css/all.min.css" %}">

<!-- Bootstrap and adminLTE -->
<link rel="stylesheet" href="{% static "vendor/adminlte/css/adminlte.min.css" %}">

<!-- Bootswatch theme -->
{% if jazzmin_ui.theme.name != 'default' %}
<link rel="stylesheet" href="{{ jazzmin_ui.theme.src }}" id="jazzmin-theme" />
{% endif %}

{% if jazzmin_ui.dark_mode_theme %}
<link rel="stylesheet" href="{{ jazzmin_ui.dark_mode_theme.src }}" id="jazzmin-dark-mode-theme" media="(prefers-color-scheme: dark)"/>
{% endif %}

<!-- Custom fixes for django -->
<link rel="stylesheet" href="{% static "jazzmin/css/main.css" %}">

{% if jazzmin_settings.custom_css %}
<!-- Custom CSS -->
<link rel="stylesheet" href="{% static jazzmin_settings.custom_css %}">
{% endif %}

<!-- favicons -->
<link rel="shortcut icon" href="{% static jazzmin_settings.site_icon %}" type="image/png">
<link rel="icon" href="{% static jazzmin_settings.site_icon %}" sizes="32x32" type="image/png">

<!-- Google Font: Source Sans Pro -->
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">

{% block extrastyle %} {% endblock %}
{% block extrahead %} {% endblock %}
</head>
<body class="hold-transition jazzmin-login-page">

<div class="login-box">
<div class="login-logo">
<h1><img src="{% static jazzmin_settings.site_logo %}" alt="{{ jazzmin_settings.site_header }}"></h1>
</div>

<div class="card">
<div class="card-body">
{% block content %} {% endblock %}
</div>
</div>
</div>

<!-- jQuery -->
<script src="{% static "admin/js/vendor/jquery/jquery.js" %}"></script>
<!-- Bootstrap 4 -->
<script src="{% static 'vendor/bootstrap/js/bootstrap.min.js' %}"></script>
<!-- AdminLTE App -->
<script src="{% static 'vendor/adminlte/js/adminlte.min.js' %}"></script>

{% if jazzmin_settings.custom_js %}
<script src="{% static jazzmin_settings.custom_js %}"></script>
{% endif %}

</body>
</html>
14 changes: 14 additions & 0 deletions jazzmin/templates/registration/password_reset_complete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "registration/base.html" %}

{% load i18n %}

{% block content %}
<p class="login-box-msg">{% trans "Your password has been set. You may go ahead and log in now." %}</p>
<div class="row">
<div class="col-12">
<a href="{{ login_url }}">
<button class="btn {{ jazzmin_ui.button_classes.primary }} btn-block">{% trans 'Log in' %}</button>
</a>
</div>
</div>
{% endblock %}
60 changes: 60 additions & 0 deletions jazzmin/templates/registration/password_reset_confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{% extends "registration/base.html" %}

{% load i18n %}

{% block content %}
{% if validlink %}
<p class="login-box-msg">
{% trans "Please enter your new password twice so we can verify you typed it in correctly." %}
</p>
<form method="post">{% csrf_token %}
{% if form.errors %}
{% if form.new_password1.errors %}
<div class="callout callout-danger">
<p>{{ form.new_password1.label }}: {{ form.new_password1.errors|join:', ' }}</p>
</div>
{% endif %}
{% if form.new_password2.errors %}
<div class="callout callout-danger">
<p>{{ form.new_password2.label }}: {{ form.new_password2.errors|join:', ' }}</p>
</div>
{% endif %}
{% if form.non_field_errors %}
<div class="callout callout-danger">
{% for error in form.non_field_errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
{% endif %}
<input class="hidden" autocomplete="username" value="{{ form.user.get_username }}">
<div class="input-group mb-3">
<input type="password" name="new_password1" class="form-control" placeholder="{{ form.new_password1.label }}" required>
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<div class="input-group mb-3">
<input type="password" name="new_password2" class="form-control" placeholder="{{ form.new_password2.label }}" required>
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<button type="submit" class="btn {{ jazzmin_ui.button_classes.primary }} btn-block">
{% trans 'Change my password' %}
</button>
</div>
</div>
</form>
{% else %}
<p>
{% trans "The password reset link was invalid, possibly because it has already been used. Please request a new password reset." %}
</p>
{% endif %}
{% endblock %}
20 changes: 20 additions & 0 deletions jazzmin/templates/registration/password_reset_done.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends "registration/base.html" %}

{% load i18n %}

{% block content %}
<p>
{% blocktrans trimmed %}
We’ve emailed you instructions for setting your password,
if an account exists with the email you entered.
You should receive them shortly.
{% endblocktrans %}
</p>
<p>
{% blocktrans trimmed %}
If you don’t receive an email, please make sure
you’ve entered the address you registered with,
and check your spam folder.
{% endblocktrans %}
</p>
{% endblock %}
Loading

0 comments on commit d067e13

Please sign in to comment.