Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions templates/auth/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ <h2>Login</h2>

<input type="submit" value="Login">
<button type="button" onclick="window.location.href='/v1/auth/forgot-password/'">Forgot Password?</button>
<button type="button" onclick="window.location.href='/v1/auth/create/'">Signup</button>

</form>


</body>
</html>
85 changes: 63 additions & 22 deletions templates/create_user.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,72 @@
<!-- create_user.html -->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create User</title>
<style>
/* Add your custom styles here */
body {
font-family: Arial, sans-serif;
}

form {
max-width: 300px;
margin: 0 auto;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="submit"],
button[type="button"] {
width: 100%;
padding: 10px;
margin: 5px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}

input[type="submit"],
button[type="button"] {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}

input[type="submit"]:hover,
button[type="button"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h1>Create User</h1>
{% for message in messages %}
<div class="alert alert-{{ message.tags }}">{{ message }}</div>
{% endfor %}
<form method="post">
{% csrf_token %}
<div>
<label for="id_username">Username:</label>
<input type="text" id="id_username" name="username" required>
</div>
<div>
<label for="id_email">Email:</label>
<input type="email" id="id_email" name="email" required>
</div>
<div>
<label for="id_password">Password:</label>
<input type="password" id="id_password" name="password" required>
</div>
<button type="submit">Create User</button>
</form>
<h1>Create User</h1>
{% if error_message %}
<script>
alert("{{ error_message }}");
</script>
{% endif %}
{% if messages %}
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
<form method="post">
{% csrf_token %}
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>

<label for="password">Password:</label>
<input type="password" id="password" name="password" required>

<input type="submit" value="Create User">
<button type="button" onclick="window.location.href='/v1/auth/login/'">Back to login</button>
</form>
</body>
</html>
57 changes: 49 additions & 8 deletions templates/forgot_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,61 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Set New Password</title>
<script>
{% if error_message %}
window.onload = function() {
alert("{{ error_message }}");
};
{% endif %}
</script>
<style>
/* Add your custom styles here */
body {
font-family: Arial, sans-serif;
}

form {
max-width: 300px;
margin: 0 auto;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="submit"],
button[type="button"] {
width: 100%;
padding: 10px;
margin: 5px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}

input[type="submit"],
button[type="button"] {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}

input[type="submit"]:hover,
button[type="button"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h1>Set New Password</h1>
{% if error_message %}
<script>
alert("{{ error_message }}");
</script>
{% elif success_message %}
<script>
alert("{{ success_message }}");
window.location.href = "/v1/auth/login";
</script>
{% endif %}

<form method="post">
{% csrf_token %}
<label for="new_password">New Password:</label><br>
<input type="password" id="new_password" name="new_password"><br><br>
<input type="password" id="new_password" name="new_password">
<input type="submit" value="Submit">
</form>
</body>
Expand Down
37 changes: 33 additions & 4 deletions templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,38 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Profile</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
text-align: center;
}

h2 {
margin-top: 50px;
}

p {
margin-bottom: 10px;
}

button[type="submit"] {
background-color: #dc3545; /* Red */
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
text-decoration: none;
}

button[type="submit"]:hover {
background-color: #c82333; /* Darker Red */
}
</style>
</head>
<body>
<h2>User Profile</h2>
Expand All @@ -13,7 +45,4 @@ <h2>User Profile</h2>
<!-- Logout button -->
<form action="{% url 'logout' %}" method="post">
{% csrf_token %}
<button type="submit">Logout</button>
</form>
</body>
</html>
<button type="submit">Logout
37 changes: 34 additions & 3 deletions templates/reset_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reset Password</title>
<style>
/* Add your custom styles here */
body {
font-family: Arial, sans-serif;
}
form {
max-width: 300px;
margin: 0 auto;

}
input[type="text"],
input[type="email"],
input[type="submit"],
button[type="button"] {
width: 100%;
padding: 10px;
margin: 5px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
input[type="submit"],
button[type="button"] {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
input[type="submit"]:hover,
button[type="button"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h2>Reset Password</h2>
Expand All @@ -14,17 +47,15 @@ <h2>Reset Password</h2>
{% elif success_message %}
<script>
alert("{{ success_message }}");
setTimeout(function() {
window.location.href = "/v1/auth/login";
}, 500); // Redirect after 3 seconds
</script>
{% endif %}
<p>Please enter your email address below to receive instructions for resetting your password:</p>
<form method="post">
{% csrf_token %}
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<button type="submit">Submit</button>
<input type="submit" value="Continue">
</form>
</body>
</html>
24 changes: 24 additions & 0 deletions users/migrations/0002_historicalpassword.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.4 on 2024-02-29 06:12

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('users', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='HistoricalPassword',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128)),
('created_at', models.DateTimeField(auto_now_add=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
18 changes: 18 additions & 0 deletions users/migrations/0003_alter_user_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.4 on 2024-02-29 08:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0002_historicalpassword'),
]

operations = [
migrations.AlterField(
model_name='user',
name='email',
field=models.EmailField(max_length=254, unique=True),
),
]
7 changes: 7 additions & 0 deletions users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
class User(AbstractUser):
reset_password_token = models.CharField(max_length=100, blank=True, null=True)
token_created_at = models.DateTimeField(blank=True, null=True)
email = models.EmailField(unique=True)

def __str__(self):
return str(self.username)


class HistoricalPassword(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
password = models.CharField(max_length=128)
created_at = models.DateTimeField(auto_now_add=True)
10 changes: 8 additions & 2 deletions users/serializers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from rest_framework import serializers
from users.models import User
from users.models import User, HistoricalPassword


class HistoricalPasswordSerializer(serializers.ModelSerializer):
class Meta:
model = HistoricalPassword
fields = '__all__'


class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = [
'id',

'username',
'email',
'password'
Expand Down
3 changes: 1 addition & 2 deletions users/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.urls.conf import path, re_path
from django.contrib.auth.views import LoginView
from .views import (ProfileView, CustomLogoutView, CreateUserView, ResetPasswordView, ForgotPasswordView)

from .views import ProfileView, CustomLogoutView, CreateUserView, ResetPasswordView, ForgotPasswordView

urlpatterns = [
path('create/', CreateUserView.as_view(), name='create_user'),
Expand Down
Loading