Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/add-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YashSahsani committed Jun 23, 2024
2 parents 81df96f + d579886 commit e493a2c
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 127 deletions.
27 changes: 15 additions & 12 deletions Auth/templates/Auth/base.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}{% endblock %}</title>
<script src="https://cdn.tailwindcss.com/"></script>
<link rel="stylesheet" href="{% static 'css/app.css' %}">
</head>

<body class="bg-gray-100 flex items-center justify-center h-screen">

{% include 'alert.html' %}
{% include 'alert.html' %}

<div class="bg-white shadow-lg rounded-lg overflow-hidden w-full max-w-4xl">
<div class="md:flex">
<div class="hidden md:block md:w-1/2">
<img class="object-cover h-full w-full" src="{% static 'images/logo.png' %}" alt="Random Image">
</div>
<div class="w-full md:w-1/2 p-8">
{% block content %}
{% endblock %}
<div class="bg-white shadow-lg rounded-lg overflow-hidden w-full max-w-4xl">
<div class="md:flex">
<div class="hidden md:block md:w-1/2">
<img class="object-cover h-full w-full" src="{% static 'images/logo.png' %}" alt="Random Image">
</div>
<div class="w-full md:w-1/2 p-8">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</div>

<script src="{% static 'js/setTimeoutForAlert.js' %}"> </script>
<script src="{% static 'js/setTimeoutForAlert.js' %}"> </script>
</body>
</html>

</html>
29 changes: 17 additions & 12 deletions Auth/templates/Auth/forgot_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
{% block title %}GreenCart | Forgot password?{% endblock %}

{% block content %}
<h2 class="text-2xl font-bold text-gray-800 mb-6">Forgot your password?</h2>
<form method="post">
{% csrf_token %}
<div class="mb-4">
{{ form.email.label_tag }}
{{ form.email }}
</div>
<div class="mt-6">
<button type="submit" class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Reset Password</button>
</div>
</form>
<p class="mt-4 text-sm text-center text-gray-600">Remembered your password? <a href="{% url 'Auth:login' %}" class="font-medium text-indigo-600 hover:text-indigo-500">Sign in</a></p>
<h2 class="text-2xl font-bold text-gray-800 mb-6">Forgot your password?</h2>
<form method="post">
{% csrf_token %}
<div class="mb-4">
<label for="{{ form.email.id_for_label }}" class="block text-sm font-medium text-gray-700">
{{ form.email.label }}{% if form.email.field.required %}<span class="text-red-500">*</span>{% endif %}
</label>
{{ form.email }}
</div>
<div class="mt-6">
<button type="submit"
class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Reset
Password</button>
</div>
</form>
<p class="mt-4 text-sm text-center text-gray-600">Remembered your password? <a href="{% url 'Auth:login' %}"
class="font-medium text-indigo-600 hover:text-indigo-500">Sign in</a></p>

{% endblock %}
60 changes: 34 additions & 26 deletions Auth/templates/Auth/login.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
{% extends 'Auth/base.html' %}
{% extends 'Auth/base.html' %}
{% block title %}GreenCart | Login{% endblock %}

{% block content %}

<h2 class="text-2xl font-bold text-gray-800 mb-6">Welcome Back</h2>
<form method="post" action="{% url 'Auth:login' %}">
{% csrf_token %}
<div class="mb-4">
{{ form.email.label_tag }}
{{ form.email }}
</div>
<div class="mb-6">
{{ form.password.label_tag }}
{{ form.password }}
</div>
<div class="flex items-center justify-between">
<div class="flex items-center gap-1">
{{ form.remember_me }}
{{ form.remember_me.label_tag }}
</div>
<div class="text-sm">
<a href="{% url 'Auth:forgot_password' %}" class="font-medium text-indigo-600 hover:text-indigo-500">Forgot your password?</a>
</div>
</div>
<div class="mt-6">
<button type="submit" class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Sign in</button>
</div>
</form>
<p class="mt-4 text-sm text-center text-gray-600">Don't have an account? <a href="{% url 'Auth:signup' %}" class="font-medium text-indigo-600 hover:text-indigo-500">Sign up</a></p>
<h2 class="text-2xl font-bold text-gray-800 mb-6">Welcome Back</h2>
<form method="post" action="{% url 'Auth:login' %}">
{% csrf_token %}
<div class="mb-4">
<label for="{{ form.email.id_for_label }}" class="block text-sm font-medium text-gray-700">
{{ form.email.label }}{% if form.email.field.required %}<span class="text-red-500">*</span>{% endif %}
</label>
{{ form.email }}
</div>
<div class="mb-6">
<label for="{{ form.password.id_for_label }}" class="block text-sm font-medium text-gray-700">
{{ form.password.label }}{% if form.password.field.required %}<span class="text-red-500">*</span>{% endif %}
</label>
{{ form.password }}
</div>
<div class="flex items-center justify-between">
<div class="flex items-center gap-1">
{{ form.remember_me }}
{{ form.remember_me.label_tag }}
</div>
<div class="text-sm">
<a href="{% url 'Auth:forgot_password' %}" class="font-medium text-indigo-600 hover:text-indigo-500">Forgot
your password?</a>
</div>
</div>
<div class="mt-6">
<button type="submit"
class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Sign
in</button>
</div>
</form>
<p class="mt-4 text-sm text-center text-gray-600">Don't have an account? <a href="{% url 'Auth:signup' %}"
class="font-medium text-indigo-600 hover:text-indigo-500">Sign up</a></p>
{% endblock %}
52 changes: 38 additions & 14 deletions Auth/templates/Auth/reset_password.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,44 @@
{% block title %}GreenCart | Reset Password{% endblock %}

{% block content %}
<h2 class="text-2xl font-bold text-gray-800 mb-6">Reset Password</h2>
<form method="post">
{% csrf_token %}
{{ form.email }}
<div class="mb-4">
{{ form.password1.label_tag }}
{{ form.password1 }}
<h2 class="text-2xl font-bold text-gray-800 mb-6">Reset Password</h2>
<form method="post">
{% csrf_token %}
{{ form.email }}
<div class="mb-4">
<label for="{{ form.password1.id_for_label }}" class="block text-sm font-medium text-gray-700">
{{ form.password1.label }}{% if form.password1.field.required %}<span class="text-red-500">*</span>{% endif %}
</label>
{{ form.password1 }}
{% if form.password1.errors %}
<div class="text-red-700 mt-2">
<ul class="list-disc pl-5 space-y-1">
{% for error in form.password1.errors %}
<li>{{ error|escape }}</li>
{% endfor %}
</ul>
</div>
<div class="mb-4">
{{ form.password2.label_tag }}
{{ form.password2 }}
</div>
<div class="mt-6">
<button type="submit" class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Submit</button>
{% endif %}

</div>
<div class="mb-4">
<label for="{{ form.password2.id_for_label }}" class="block text-sm font-medium text-gray-700">
{{ form.password2.label }}{% if form.password2.field.required %}<span class="text-red-500">*</span>{% endif %}
</label>
{{ form.password2 }}
{% if form.password2.errors %}
<div class="text-red-700 mt-2">
<ul class="list-disc pl-5 space-y-1">
{% for error in form.password2.errors %}
<li>{{ error|escape }}</li>
{% endfor %}
</ul>
</div>
</form>
{% endif %}
</div>
<div class="mt-6">
<button type="submit"
class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Submit</button>
</div>
</form>
{% endblock %}
108 changes: 84 additions & 24 deletions Auth/templates/Auth/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,92 @@
{% block title %}GreenCart | Signup{% endblock %}

{% block content %}
<h2 class="text-2xl font-bold text-gray-800 mb-6">Create Your Account</h2>
<form method="POST">
{% csrf_token %}
<div class="mb-4">
{{ form.first_name.label_tag }}
{{ form.first_name }}
<h2 class="text-2xl font-bold text-gray-800 mb-6">Create Your Account</h2>
<form method="POST">
{% csrf_token %}
<div class="mb-4">
<label for="{{ form.first_name.id_for_label }}" class="block text-sm font-medium text-gray-700">
{{ form.first_name.label }}{% if form.first_name.field.required %}<span class="text-red-500">*</span>{% endif %}
</label>
{{ form.first_name }}
{% if form.first_name.errors %}
<div class="text-red-700 mt-2">
<ul class="list-disc pl-5 space-y-1">
{% for error in form.first_name.errors %}
<li>{{ error|escape }}</li>
{% endfor %}
</ul>
</div>
<div class="mb-4">
{{ form.last_name.label_tag }}
{{ form.last_name }}
{% endif %}
</div>
<div class="mb-4">
<label for="{{ form.last_name.id_for_label }}" class="block text-sm font-medium text-gray-700">
{{ form.last_name.label }}{% if form.last_name.field.required %}<span class="text-red-500">*</span>{% endif %}
</label>
{{ form.last_name }}
{% if form.last_name.errors %}
<div class="text-red-700 mt-2">
<ul class="list-disc pl-5 space-y-1">
{% for error in form.last_name.errors %}
<li>{{ error|escape }}</li>
{% endfor %}
</ul>
</div>
<div class="mb-4">
{{ form.email.label_tag }}
{{ form.email }}
{% endif %}
</div>
<div class="mb-4">
<label for="{{ form.email.id_for_label }}" class="block text-sm font-medium text-gray-700">
{{ form.email.label }}{% if form.email.field.required %}<span class="text-red-500">*</span>{% endif %}
</label>
{{ form.email }}
{% if form.email.errors %}
<div class="text-red-700 mt-2">
<ul class="list-disc pl-5 space-y-1">
{% for error in form.email.errors %}
<li>{{ error|escape }}</li>
{% endfor %}
</ul>
</div>
<div class="mb-6">
{{ form.password1.label_tag }}
{{ form.password1 }}
</div>
<div class="mb-6">
{{ form.password2.label_tag }}
{{ form.password2 }}
{% endif %}
</div>
<div class="mb-6">
<label for="{{ form.password1.id_for_label }}" class="block text-sm font-medium text-gray-700">
{{ form.password1.label }}{% if form.password1.field.required %}<span class="text-red-500">*</span>{% endif %}
</label>

{{ form.password1 }}
{% if form.password1.errors %}
<div class="text-red-700 mt-2">
<ul class="list-disc pl-5 space-y-1">
{% for error in form.password1.errors %}
<li>{{ error|escape }}</li>
{% endfor %}
</ul>
</div>
<div class="mt-6">
<button type="submit" class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Sign up</button>
{% endif %}
</div>
<div class="mb-6">
<label for="{{ form.password2.id_for_label }}" class="block text-sm font-medium text-gray-700">
{{ form.password2.label }}{% if form.password2.field.required %}<span class="text-red-500">*</span>{% endif %}
</label>
{{ form.password2 }}
{% if form.password2.errors %}
<div class="text-red-700 mt-2">
<ul class="list-disc pl-5 space-y-1">
{% for error in form.password2.errors %}
<li>{{ error|escape }}</li>
{% endfor %}
</ul>
</div>
</form>
<p class="mt-4 text-sm text-center text-gray-600">Already have an account? <a href="{% url 'Auth:login' %}" class="font-medium text-indigo-600 hover:text-indigo-500">Sign in</a></p>
{% endblock %}
{% endif %}
</div>

<div class="mt-6">
<button type="submit"
class="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Sign
up</button>
</div>
</form>
<p class="mt-4 text-sm text-center text-gray-600">Already have an account? <a href="{% url 'Auth:login' %}"
class="font-medium text-indigo-600 hover:text-indigo-500">Sign in</a></p>
{% endblock %}
13 changes: 7 additions & 6 deletions Auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from .backend import getSecondsOfOneYear
from .models import User
from django.urls import reverse
from django.http import HttpResponse




Expand Down Expand Up @@ -48,9 +50,10 @@ def post(self, request):
messages.success(request, str(form.cleaned_data.get('first_name'))+' account has been created successfully. Please login to continue.')
return redirect('Auth:login')
else:
messages.error(request, 'Please check your inputs')
return redirect('Auth:signup')

response = HttpResponse()
response['Location'] = '/auth/signup/'
response = render(request, 'Auth/signup.html', {'form': form},status=400)
return response

def forgot_password(request):
form = ForgotPasswordForm()
Expand All @@ -66,6 +69,7 @@ def forgot_password(request):

def reset_password(request):
email = request.GET.get('email')
form = ResetPasswordForm(email=email)
if not email:
messages.error(request, 'Invalid password reset link.')
return redirect('forgot_password')
Expand All @@ -78,9 +82,6 @@ def reset_password(request):
user.save()
messages.success(request, 'Your password has been successfully reset.')
return redirect(reverse('Auth:login'))
else:
form = ResetPasswordForm(email=email)

return render(request, 'Auth/reset_password.html', {'form': form})


Expand Down
Loading

0 comments on commit e493a2c

Please sign in to comment.