Added basic code and templates to handle user accounts without user initiated registration.

main
Calum Andrew Morrell 2025-11-09 11:55:03 +00:00
parent 4402e694c5
commit d2213562bb
11 changed files with 142 additions and 2 deletions

View File

@ -1,3 +1,10 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
# Register your models here.
from .models import User
@admin.register(User)
class UserAdmin(UserAdmin):
list_display = ["username", "email", "first_name", "last_name", "display_name"]
list_filter = ["is_active"]

View File

@ -1,3 +1,18 @@
from django.contrib.auth.models import AbstractUser
from django.db import models
# Create your models here.
class User(AbstractUser):
display_name = models.CharField(
max_length=200, help_text="Display name", blank=True, null=True
)
def __str__(self):
if self.display_name:
return self.display_name
elif self.first_name and self.last_name:
return f"{self.first_name} {self.last_name}"
elif self.first_name:
return self.first_name
else:
return self.username

View File

@ -0,0 +1,17 @@
{% extends 'base.html' %}
{% block content %}
<div>
<h1>Login</h1>
{% if form.errors %}
<p>The username and password combination entered did not match an active account.</p>
{% endif %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Login"/>
<a href="{% url 'core:homepage' %}">Cancel</a>
</form>
</div>
{% endblock %}

View File

@ -0,0 +1,9 @@
{% extends 'base.html' %}
{% block content %}
<div>
<h1>Password change complete</h1>
<p>Your password has been successfully changed. Don't forget your new password!</p>
</div>
{% endblock %}

View File

@ -0,0 +1,14 @@
{% extends 'base.html' %}
{% block content %}
<div>
<h1>Change your password</h1>
<form method="post">
{% csrf_token %} {{ form.as_p }}
<button type="submit">Change password</button>
<button type="reset">Reset form</button>
<a href="{% url 'display_profile' %}">Cancel</a>
</form>
</div>
{% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'base.html' %}
{% block content %}
<div>
<h1>Password reset</h1>
<p>
Your password has been reset successfully. You can <a href="{% url 'login' %}">login now</a>.
</p>
</div>
{% endblock %}

View File

@ -0,0 +1,25 @@
{% extends 'base.html' %}
{% block content %}
<div>
<h1>Reset your password</h1>
{% if validlink %}
<p>Enter your new password twice.</p>
<form method="post">
{% csrf_token %} {{ form.as_p }}
<input type="submit" value="Change my password"/>
<a href="{% url 'core:homepage' %}">Cancel</a>
</form>
{% else %}
<p>
The password reset link you clicked was invalid. This may mean it has already been used or too much time
has passed since you requested it.
</p>
<p>
If you have not already reset your password successfully, you may request a <a
href="{% url 'password_reset' %}">new password reset.</a>
</p>
{% endif %}
</div>
{% endblock %}

View File

@ -0,0 +1,13 @@
{% extends 'base.html' %}
{% block content %}
<div>
<h1>Password reset requested</h1>
<p>An email has been sent with a link which will allow you to reset your password.</p>
<p>
If you do not receive it, check your spam or junk folders and ensure you typed the email address connected
with your account.
</p>
</div>
{% endblock %}

View File

@ -0,0 +1,10 @@
A request to reset the password associated with this account has been made on our health website.
If this was you, please click the following link to reset your password.
{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}
If you did not make this request, we would suggest you log into your account to confirm there has been no malicious activity. You may also want to consider changing your password as a precaution.
--
The Dazed Gerbil

View File

@ -0,0 +1,14 @@
{% extends 'base.html' %}
{% block content %}
<div>
<h1>Reset your password</h1>
<p>Have you forgotten your password? Enter your email address to request a password reset.</p>
<form action="" method="post">
{% csrf_token %} {{ form.as_p }}
<input type="submit" value="Reset my password"/>
<a href="{% url 'core:homepage' %}">Cancel</a>
</form>
</div>
{% endblock %}

5
accounts/urls.py Normal file
View File

@ -0,0 +1,5 @@
from django.urls import include, path
urlpatterns = [
path("", include("django.contrib.auth.urls")),
]