Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Add registration, login and user profile changes (#16)
Browse files Browse the repository at this point in the history
* added user profile login/reg

* Edited and saved with updates (login/ref)

* Format Python and HTML files as per PEP 8 style guideline

* Modify add user UI

* fixed user profile error issue

* fix default image issue

* Cleanup Python files and HTML templates

* User profile management, update and view

* Resolve merge conflicts and code styling

* Resolve merge conflicts in base.html

* Add missing CSS class to Sign Out button

* Remove extra files in user template

* user differentiation, user restrictions, user profile management updated

* add profile image removal code

* fixed- registration confirmation, duplicate email registration

---------

Co-authored-by: Afrar Malakooth <[email protected]>
Co-authored-by: Naqibullah Sediqi <[email protected]>
  • Loading branch information
3 people authored May 24, 2024
1 parent e9ed2fb commit a06b4af
Show file tree
Hide file tree
Showing 23 changed files with 712 additions and 132 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
*.iml

/media
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8",
"editor.formatOnSave": true
}
}
89 changes: 49 additions & 40 deletions dashboard/views.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,64 @@
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.views import View



class ViewDashboardView(View):

def get(self,request):
return render(request,"dashboard.html")


def get(self, request):
if request.user.is_authenticated and self.request.user.is_superuser:
return render(request, "dashboard.html")
return redirect('users:login')


class ViewAdminMenu(View):

def get(self,request):
return render(request,"menu/admin-menu.html")


def get(self, request):
return render(request, "menu/admin-menu.html")


class ViewAddMenuView(View):

def get(self,request):
return render(request,"menu/add-menu.html")

def get(self, request):
return render(request, "menu/add-menu.html")


class ViewUpdateMenuView(View):

def get(self,request,pk):
return render(request,"menu/update-menu.html")


def get(self, request, pk):
return render(request, "menu/update-menu.html")


class ViewAdminBranchs(View):

def get(self,request):
return render(request,"branch/admin-branch.html")


def get(self, request):
return render(request, "branch/admin-branch.html")


class ViewAddBranchView(View):

def get(self,request):
return render(request,"branch/add-branch.html")

def get(self, request):
return render(request, "branch/add-branch.html")


class ViewUpdateBranchView(View):

def get(self,request,pk):
return render(request,"branch/update-branch.html")


def get(self, request, pk):
return render(request, "branch/update-branch.html")


class ViewOrder(View):

def get(self,request):
return render(request,"order/order-management.html")


def get(self, request):
return render(request, "order/order-management.html")


class ViewOrderDetails(View):

def get(self,request):
return render(request,"order/order-details.html")


def get(self, request):
return render(request, "order/order-details.html")


class ViewOrderAfterStatus(View):

def get(self,request,pk):
return render(request,"order/order-after-status.html")


def get(self, request, pk):
return render(request, "order/order-after-status.html")
Binary file added media/users/default.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ psycopg==3.1.18
psycopg-binary==3.1.18
sqlparse==0.4.4
typing_extensions==4.11.0
tzdata==2024.1
whitenoise==6.6.0
5 changes: 4 additions & 1 deletion templates/base-dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ <h1 class="logo me-auto me-lg-0"><a href="{% url 'dashboard:view-dashboard' %}">
<i class="bi bi-list mobile-nav-toggle"></i>
</nav>
<!-- .navbar -->
<a href="#book-a-table" class="book-a-table-btn scrollto d-none d-lg-flex">Sign out</a>
<form id="logoutform" action="{% url 'users:logout' %}" method="post">
{% csrf_token %}
<button type="submit" class="nav-link book-a-table-btn scrollto d-none d-lg-flex">Sign Out</button>
</form>
</div>
</header>
<!-- End Header -->
Expand Down
14 changes: 11 additions & 3 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ <h1 class="logo me-auto me-lg-0"><a href="{% url 'index' %}">Yummy</a></h1>
<li><a class="nav-link scrollto" href="{% url 'restaurants:view-resturant' %}">Branches</a></li>
<li><a class="nav-link scrollto" href="{% url 'contacts:view-about' %}">About</a></li>
<li><a class="nav-link scrollto" href="{% url 'contacts:view-contact' %}">Contact</a></li>
{% if user.is_authenticated %}
<li><a class="nav-link scrollto" href="{% url 'users:view-profile' %}">My Profile</a></li>
{% endif %}
</ul>
<i class="bi bi-list mobile-nav-toggle"></i>
</nav>
<!-- .navbar -->
<a href="#book-a-table" class="book-a-table-btn scrollto d-none d-lg-flex">Sign In</a>

{% comment %} <a href="#book-a-table" class="book-a-table-btn scrollto d-none d-lg-flex">Sign Out</a> {% endcomment %}
{% if user.is_authenticated %}
<form id="logoutform" action="{% url 'users:logout' %}" method="post">
{% csrf_token %}
<button type="submit" class="nav-link book-a-table-btn scrollto d-none d-lg-flex">Sign Out</button>
</form>
{% else %}
<a href="{% url 'users:login' %}" class="book-a-table-btn scrollto d-none d-lg-flex">Sign In</a>
{% endif %}

</div>
</header><!-- End Header -->
Expand Down Expand Up @@ -145,4 +153,4 @@ <h4>Our Resturant</h4>

</body>

</html>
</html>
3 changes: 2 additions & 1 deletion users/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.contrib import admin
from .models import Profile

# Register your models here.
admin.site.register(Profile)
156 changes: 156 additions & 0 deletions users/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.core.exceptions import ValidationError
from .models import Profile


class RegisterForm(UserCreationForm):
# fields we want to include and customize in our form
first_name = forms.CharField(
max_length=100,
required=True,
widget=forms.TextInput(
attrs={
"placeholder": "First Name",
}
),
)
last_name = forms.CharField(
max_length=100,
required=True,
widget=forms.TextInput(
attrs={
"placeholder": "Last Name",
}
),
)
username = forms.CharField(
max_length=100,
required=True,
widget=forms.TextInput(
attrs={
"placeholder": "Username",
}
),
)
email = forms.EmailField(
required=True,
widget=forms.TextInput(
attrs={
"placeholder": "Email",
}
),
)
password1 = forms.CharField(
max_length=50,
required=True,
widget=forms.PasswordInput(
attrs={
"placeholder": "Password",
"data-toggle": "password",
"id": "password",
}
),
)
password2 = forms.CharField(
max_length=50,
required=True,
widget=forms.PasswordInput(
attrs={
"placeholder": "Confirm Password",
"data-toggle": "password",
"id": "password",
}
),
)

def clean_email(self):
email = self.cleaned_data.get('email')
if User.objects.filter(email=email).exists():
raise ValidationError("This email is already registered.")
return email

class Meta:
model = User
fields = [
"first_name",
"last_name",
"username",
"email",
"password1",
"password2",
]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['username'].widget.attrs.update({'autofocus': False})


class LoginForm(AuthenticationForm):
username = forms.CharField(
max_length=100,
required=True,
widget=forms.TextInput(attrs={"placeholder": "Username"}),
)
password = forms.CharField(
max_length=50,
required=True,
widget=forms.PasswordInput(
attrs={
"placeholder": "Password",
"data-toggle": "password",
"id": "password",
"name": "password",
}
),
)
remember_me = forms.BooleanField(required=False)

class Meta:
model = User
fields = ["username", "password"]


class UserUpdateForm(forms.ModelForm):
email = forms.EmailField(
required=True, widget=forms.TextInput(attrs={"class": "form-control"})
)

first_name = forms.CharField(
max_length=100,
required=True,
widget=forms.TextInput(
attrs={
"placeholder": "First Name",
"class": "form-control",
}
),
)
last_name = forms.CharField(
max_length=100,
required=False,
widget=forms.TextInput(
attrs={
"placeholder": "Last Name",
"class": "form-control",
}
),
)

class Meta:
model = User
fields = ['first_name', 'last_name', 'email']


class UpdateProfileForm(forms.ModelForm):
avatar = forms.ImageField(
widget=forms.FileInput(attrs={"class": "form-control-file"})
)
address = forms.CharField(
widget=forms.Textarea(attrs={"class": "form-control", "rows": 5})
)

class Meta:
model = Profile
fields = ["avatar", "address"]
26 changes: 26 additions & 0 deletions users/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 5.0.4 on 2024-05-12 05:27

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


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Profile',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('avatar', models.ImageField(default='users/default.jpg', upload_to='users')),
('address', models.TextField()),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
18 changes: 17 additions & 1 deletion users/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
from django.db import models
from django.contrib.auth.models import User

# Create your models here.

# Extending User Model Using a One-To-One Link
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)

avatar = models.ImageField(
default='users/default.jpg', upload_to='users')

address = models.TextField()

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

# resizing images
def save(self, *args, **kwargs):
super().save()
16 changes: 16 additions & 0 deletions users/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.dispatch import receiver

from .models import Profile


@receiver(post_save, sender=User)
def create_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)


@receiver(post_save, sender=User)
def save_profile(sender, instance, **kwargs):
instance.profile.save()
Loading

0 comments on commit a06b4af

Please sign in to comment.