From 9615b5ffdf0c7f1455158397fafc27136f55a468 Mon Sep 17 00:00:00 2001
From: TheJoeCoder <joe@radialbog9.uk>
Date: Fri, 19 Jul 2024 20:16:53 +0100
Subject: [PATCH] Add login and profile templates

---
 requirements.txt                              |  3 +-
 tcalendar/urls.py                             |  2 +
 templates/registration/logged_out.html        | 16 +++++
 templates/registration/login.html             | 59 +++++++++++++++++++
 .../registration/password_change_done.html    | 21 +++++++
 .../registration/password_change_form.html    | 49 +++++++++++++++
 .../registration/password_reset_complete.html | 17 ++++++
 .../registration/password_reset_confirm.html  | 34 +++++++++++
 .../registration/password_reset_done.html     | 17 ++++++
 .../registration/password_reset_email.html    | 15 +++++
 .../registration/password_reset_form.html     | 25 ++++++++
 .../registration/password_reset_subject.txt   |  3 +
 templates/registration/profile.html           | 40 +++++++++++++
 13 files changed, 300 insertions(+), 1 deletion(-)
 create mode 100644 templates/registration/logged_out.html
 create mode 100644 templates/registration/login.html
 create mode 100644 templates/registration/password_change_done.html
 create mode 100644 templates/registration/password_change_form.html
 create mode 100644 templates/registration/password_reset_complete.html
 create mode 100644 templates/registration/password_reset_confirm.html
 create mode 100644 templates/registration/password_reset_done.html
 create mode 100644 templates/registration/password_reset_email.html
 create mode 100644 templates/registration/password_reset_form.html
 create mode 100644 templates/registration/password_reset_subject.txt
 create mode 100644 templates/registration/profile.html

diff --git a/requirements.txt b/requirements.txt
index 8ee0523..a6da722 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
 django-bootstrap5~=24.2
-django-gravatar2~=1.4.4
\ No newline at end of file
+django-gravatar2~=1.4.4
+Django~=5.0.7
\ No newline at end of file
diff --git a/tcalendar/urls.py b/tcalendar/urls.py
index dbc2470..945c2eb 100644
--- a/tcalendar/urls.py
+++ b/tcalendar/urls.py
@@ -16,9 +16,11 @@ Including another URLconf
 """
 from django.contrib import admin
 from django.urls import path, include
+from django.views.generic import TemplateView
 
 urlpatterns = [
     path('admin/', admin.site.urls),
     path("accounts/", include("django.contrib.auth.urls")),
+    path("accounts/profile/", TemplateView.as_view(template_name="registration/profile.html"), name="profile"),
     path('', include("tcal.urls")),
 ]
diff --git a/templates/registration/logged_out.html b/templates/registration/logged_out.html
new file mode 100644
index 0000000..c160b12
--- /dev/null
+++ b/templates/registration/logged_out.html
@@ -0,0 +1,16 @@
+{% extends "base.html" %}
+
+{% block title %}Logged Out{% endblock %}
+
+{% block content %}
+    <br>
+    <div class="card">
+        <div class="card-header">
+            Message
+        </div>
+        <div class="card-body">
+            You have been logged out. To log back in, <a href="{% url "login" %}">click here</a>.
+        </div>
+    </div>
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/registration/login.html b/templates/registration/login.html
new file mode 100644
index 0000000..24d38a6
--- /dev/null
+++ b/templates/registration/login.html
@@ -0,0 +1,59 @@
+{% extends "base.html" %}
+
+{% block title %}Login{% endblock %}
+
+{% block content %}
+    <br>
+    {% if form.errors and not form.non_field_errors %}
+        <div class="alert alert-danger" role="alert">
+            Please correct the error(s) below.
+        </div>
+    {% endif %}
+    {% if form.non_field_errors %}
+        {% for error in form.non_field_errors %}
+            <div class="alert alert-danger" role="alert">
+                {{ error }}
+            </div>
+        {% endfor %}
+    {% endif %}
+    {% if user.is_authenticated %}
+        <div class="alert alert-danger" role="alert">
+            You are authenticated as {{ username }}, but are not authorized to
+            access this page. Would you like to login to a different account?
+        </div>
+    {% endif %}
+    <div class="card">
+        <div class="card-header">
+            Login
+        </div>
+        <div class="card-body">
+            {% if form.errors and not form.non_field_errors %}
+
+            {% endif %}
+            <form method="post">
+                {% csrf_token %}
+                <div class="mb-3">
+                    {{ form.username.errors }}
+                    <label for="id_username" class="form-label">Username</label>
+                    <input type="text" class="form-control" id="id_username" name="username">
+                </div>
+                <div class="mb-3">
+                    {{ form.password.errors }}
+                    <label for="id_password" class="form-label">Password</label>
+                    <input type="password" class="form-control" id="id_password" name="password">
+                </div>
+                <button type="submit" class="btn btn-primary">Submit</button>
+            </form>
+        </div>
+    </div>
+    <br>
+    <div class="card">
+        <div class="card-header">
+            Forgotten Password
+        </div>
+        <div class="card-body">
+            <p>If you have forgotten your password, please click <a href="{% url "password_reset" %}">here</a>.</p>
+        </div>
+    </div>
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/registration/password_change_done.html b/templates/registration/password_change_done.html
new file mode 100644
index 0000000..3e6ad91
--- /dev/null
+++ b/templates/registration/password_change_done.html
@@ -0,0 +1,21 @@
+{% extends "base.html" %}
+
+{% block title %}Logged Out{% endblock %}
+
+{% block navbar_items %}
+    {{ block.super }}
+    <a class="nav-link active" aria-current="page" href="{% url "profile" %}">Profile</a>
+{% endblock %}
+
+{% block content %}
+    <br>
+    <div class="card">
+        <div class="card-header">
+            Success
+        </div>
+        <div class="card-body">
+            Your password has been changed.
+        </div>
+    </div>
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/registration/password_change_form.html b/templates/registration/password_change_form.html
new file mode 100644
index 0000000..d20d3c7
--- /dev/null
+++ b/templates/registration/password_change_form.html
@@ -0,0 +1,49 @@
+{% extends "base.html" %}
+
+{% block title %}Change Password{% endblock %}
+
+{% block navbar_items %}
+    {{ block.super }}
+    <a class="nav-link active" aria-current="page" href="{% url "profile" %}">Profile</a>
+{% endblock %}
+
+{% block content %}
+    <br>
+    <div class="card">
+        <div class="card-header">
+            Change Password
+        </div>
+        <div class="card-body">
+            {% if form.errors %}
+                <p class="errornote"><strong>
+                    {% if form.errors.items|length > 1 %}
+                        Please correct the errors below.
+                    {% else %}
+                        Please correct the error below.
+                    {% endif %}
+                </strong></p>
+            {% endif %}
+            <p class="lead">Please enter your old password, for security’s sake, and then enter your new password twice so we can verify you typed it in correctly.</p>
+            <form method="post">
+                {% csrf_token %}
+                <div class="mb-3">
+                    {{ form.old_password.errors }}
+                    <label for="id_old_password" class="form-label">Old Password:</label>
+                    <input type="password" class="form-control" id="id_old_password" name="old_password">
+                </div>
+                <div class="mb-3">
+                    {{ form.new_password1.errors }}
+                    <label for="id_new_password1" class="form-label">New Password:</label>
+                    <input type="password" class="form-control" id="id_new_password1" name="new_password1">
+                </div>
+                <div class="mb-3">
+                    {{ form.new_password2.errors }}
+                    <label for="id_new_password2" class="form-label">New Password (repeat):</label>
+                    <input type="password" class="form-control" id="id_new_password2" name="new_password2">
+                </div>
+                <button type="submit" class="btn btn-primary">Change my password</button>
+            </form>
+        </div>
+    </div>
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/registration/password_reset_complete.html b/templates/registration/password_reset_complete.html
new file mode 100644
index 0000000..29468b3
--- /dev/null
+++ b/templates/registration/password_reset_complete.html
@@ -0,0 +1,17 @@
+{% extends "base.html" %}
+
+{% block title %}Password Reset Complete{% endblock %}
+
+{% block content %}
+    <br>
+    <div class="card">
+        <div class="card-header">
+            Success
+        </div>
+        <div class="card-body">
+            <p>Your password has been set. You may go ahead and log in now.</p>
+            <p><a class="btn btn-primary" href="{{ login_url }}">Log in</a></p>
+        </div>
+    </div>
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/registration/password_reset_confirm.html b/templates/registration/password_reset_confirm.html
new file mode 100644
index 0000000..43d0091
--- /dev/null
+++ b/templates/registration/password_reset_confirm.html
@@ -0,0 +1,34 @@
+{% extends "base.html" %}
+
+{% block title %}Password Reset{% endblock %}
+
+{% block content %}
+    <br>
+    <div class="card">
+        <div class="card-header">
+            Password Reset Confirmation
+        </div>
+        <div class="card-body">
+            {% if validlink %}
+                <p class="lead">Please enter your new password twice, so we can verify you typed it in correctly.</p>
+                <form method="post">
+                    {% csrf_token %}
+                    <div class="mb-3">
+                        {{ form.new_password1.errors }}
+                        <label for="id_new_password1" class="form-label">New Password</label>
+                        <input type="password" class="form-control" id="id_new_password1" name="new_password1">
+                    </div>
+                    <div class="mb-3">
+                        {{ form.new_password2.errors }}
+                        <label for="id_new_password2" class="form-label">Confirm Password</label>
+                        <input type="password" class="form-control" id="id_new_password2" name="new_password2">
+                    </div>
+                    <button type="submit" class="btn btn-primary">Change password</button>
+                </form>
+            {% else %}
+                <p>The password reset link was invalid, possibly because it has already been used.  Please request a new password reset.</p>
+            {% endif %}
+        </div>
+    </div>
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/registration/password_reset_done.html b/templates/registration/password_reset_done.html
new file mode 100644
index 0000000..9d5df12
--- /dev/null
+++ b/templates/registration/password_reset_done.html
@@ -0,0 +1,17 @@
+{% extends "base.html" %}
+
+{% block title %}Logged Out{% endblock %}
+
+{% block content %}
+    <br>
+    <div class="card">
+        <div class="card-header">
+            Success
+        </div>
+        <div class="card-body">
+            We’ve emailed you instructions for setting your password, if an account exists with the email you entered. You should receive them shortly.<br>
+            If you don’t receive an email, please make sure you’ve entered the address you registered with, and check your spam folder.
+        </div>
+    </div>
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/registration/password_reset_email.html b/templates/registration/password_reset_email.html
new file mode 100644
index 0000000..48a87de
--- /dev/null
+++ b/templates/registration/password_reset_email.html
@@ -0,0 +1,15 @@
+{% extends "email_base.html" %}
+
+{% block content %}
+    You're receiving this email because you requested a password reset for your user account at {{ site_name }}.
+
+    Please go to the following page and choose a new password:
+    {% block reset_link %}
+    {{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}
+    {% endblock %}
+    Your username, in case you’ve forgotten: {{ user.get_username }}
+
+    Thanks for using our site!
+
+    The {{ site_name }} team
+{% endblock %}
\ No newline at end of file
diff --git a/templates/registration/password_reset_form.html b/templates/registration/password_reset_form.html
new file mode 100644
index 0000000..772ee81
--- /dev/null
+++ b/templates/registration/password_reset_form.html
@@ -0,0 +1,25 @@
+{% extends "base.html" %}
+
+{% block title %}Password Reset{% endblock %}
+
+{% block content %}
+    <br>
+    <div class="card">
+        <div class="card-header">
+            Password Reset
+        </div>
+        <div class="card-body">
+            <p class="lead">Forgotten your password? Enter your email address below, and we’ll email instructions for setting a new one.</p>
+            <form method="post">
+                {% csrf_token %}
+                <div class="mb-3">
+                    {{ form.email.errors }}
+                    <label for="id_email" class="form-label">Email</label>
+                    <input type="email" class="form-control" id="id_email" name="email" autocomplete="email">
+                </div>
+                <button type="submit" class="btn btn-primary">Submit</button>
+            </form>
+        </div>
+    </div>
+
+{% endblock %}
\ No newline at end of file
diff --git a/templates/registration/password_reset_subject.txt b/templates/registration/password_reset_subject.txt
new file mode 100644
index 0000000..61c6198
--- /dev/null
+++ b/templates/registration/password_reset_subject.txt
@@ -0,0 +1,3 @@
+{% autoescape off %}
+Password reset on {{ site_name }}
+{% endautoescape %}
\ No newline at end of file
diff --git a/templates/registration/profile.html b/templates/registration/profile.html
new file mode 100644
index 0000000..d5b2217
--- /dev/null
+++ b/templates/registration/profile.html
@@ -0,0 +1,40 @@
+{% extends "base.html" %}
+{% load gravatar %}
+
+{% block title %}Profile{% endblock %}
+
+{% block navbar_items %}
+    {{ block.super }}
+    <li class="nav-item">
+        <a class="nav-link active" aria-current="page" href="{% url "profile" %}">Profile</a>
+    </li>
+{% endblock %}
+
+{% block content %}
+    <div class="card" id="card-profile">
+        <div class="card-header">
+            Profile
+        </div>
+        <div class="card-body">
+            <div class="row">
+                <div class="col-md-4">
+                    <img src="{% gravatar_url user.email 150 %}" class="rounded-circle mx-auto d-block" alt="Profile image" width="150" height="150">
+                </div>
+                <div class="col-md-8">
+                    {% if user.first_name or user.last_name %}
+                        <h3>{{ user.first_name }} {{ user.last_name }}</h3>
+                    {% else %}
+                        <h3>{{ user.username }}</h3>
+                    {% endif %}
+                    <br>
+                    <p><b>Username:</b> {{ user.username }}</p>
+                    <p><b>Primary Email:</b> {{ user.email }}</p>
+                    <p><b>Account Created:</b> {{ user.date_joined }}</p>
+                    <br>
+                    <p><a class="btn btn-primary" href="{% url "password_change" %}">Change Password</a></p>
+                </div>
+            </div>
+        </div>
+    </div>
+    <br>
+{% endblock %}
-- 
GitLab