This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add registration, login and user profile changes (#16)
* 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
1 parent
e9ed2fb
commit a06b4af
Showing
23 changed files
with
712 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"[python]": { | ||
"editor.defaultFormatter": "ms-python.autopep8", | ||
"editor.formatOnSave": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.