Skip to content

Commit a964e79

Browse files
author
rifadul
committed
PeaceLife website develop completed
0 parents  commit a964e79

File tree

628 files changed

+150436
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

628 files changed

+150436
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"# PeaceLife--web-based-Doctor-Appointment-System"

account/__init__.py

Whitespace-only changes.
156 Bytes
Binary file not shown.
1.16 KB
Binary file not shown.
435 Bytes
Binary file not shown.
3.52 KB
Binary file not shown.
1.49 KB
Binary file not shown.
2.51 KB
Binary file not shown.
1.41 KB
Binary file not shown.
2.33 KB
Binary file not shown.

account/admin.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from django.contrib import admin
2+
from .models import User
3+
from django.contrib.auth.admin import UserAdmin
4+
from django.contrib.auth import urls
5+
# Register your models here.
6+
7+
# @admin.register(User)
8+
# class UserAdmin(admin.ModelAdmin):
9+
# '''Admin View for User'''
10+
11+
# list_display = ('username','email','first_name','last_name','phone','user_type','is_staff', 'is_active',)
12+
13+
14+
@admin.register(User)
15+
class CustomUserAdmin(UserAdmin):
16+
model = User
17+
list_display = ('username','email','first_name','last_name','phone','user_type','is_staff', 'is_active',)
18+
list_filter = ('username','email','first_name','last_name','user_type', 'is_staff', 'is_active',)
19+
fieldsets = (
20+
("Account info", {'fields': ('username','email', 'user_type', 'password')}),
21+
("Personal info", {'fields': ('first_name','last_name', 'phone')}),
22+
('Permissions', {'fields': ('is_staff', 'is_active', 'is_superuser','groups','user_permissions')}), #'is_customer' , 'is_seller'
23+
('Important dates', {'fields': ('last_login',)}), #'is_customer' , 'is_seller'
24+
)
25+
add_fieldsets = (
26+
('Account info', {
27+
'classes': ('wide',),
28+
'fields': ('username', 'email', 'user_type', 'password1', 'password2', 'is_staff', 'is_active')}
29+
),
30+
('User Info', {
31+
'classes': ('wide',),
32+
'fields': ('first_name','last_name','phone','profile_image',)}
33+
),
34+
)
35+
search_fields = ('email','first_name','last_name','user_type')
36+
ordering = ('email',)

account/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AccountConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'account'

account/forms.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
from django import forms
2+
from .models import User
3+
from django.utils.translation import gettext, gettext_lazy as _
4+
from django.contrib.auth.forms import AuthenticationForm, UsernameField, UserCreationForm,PasswordChangeForm,PasswordResetForm,SetPasswordForm
5+
from django.contrib.auth import password_validation
6+
7+
class LoginForm(forms.ModelForm):
8+
email = forms.EmailField(
9+
required=True,
10+
widget= forms.EmailInput(attrs={'class': 'input-box','placeholder': 'Email'})
11+
)
12+
13+
password = forms.CharField(
14+
required=True,
15+
widget= forms.PasswordInput(attrs={'class': 'input-box','placeholder': 'Password'})
16+
)
17+
class Meta:
18+
model = User
19+
fields = ['email','password']
20+
21+
class SignupForm(UserCreationForm):
22+
USER_TYPE = {
23+
('Patient', 'Patient'),
24+
('Doctor', 'Doctor'),
25+
}
26+
first_name = forms.CharField(
27+
label=_("First Name"),
28+
required=True,
29+
widget= forms.TextInput(attrs={'class': 'form-control','placeholder': 'First Name'})
30+
)
31+
last_name = forms.CharField(
32+
label=_("Last Name"),
33+
required=True,
34+
widget= forms.TextInput(attrs={'class': 'form-control','placeholder': 'Last Name'})
35+
)
36+
37+
username = forms.CharField(
38+
label=_("Username"),
39+
required=True,
40+
widget= forms.TextInput(attrs={'class': 'form-control','placeholder': 'Username'})
41+
)
42+
43+
email = forms.EmailField(
44+
label=_("Email"),
45+
required=True,
46+
widget= forms.EmailInput(attrs={'class': 'form-control','placeholder': 'Email'})
47+
)
48+
49+
phone = forms.CharField(
50+
label=_("Phone Number"),
51+
required=True,
52+
widget= forms.TextInput(attrs={'class': 'form-control','placeholder': 'Contact Number'})
53+
)
54+
55+
56+
password1 = forms.CharField(
57+
label=_("Password"),
58+
required=True,
59+
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password','class': 'form-control','placeholder': 'Password'}),
60+
)
61+
password2 = forms.CharField(
62+
label=_("Password Confirmation"),
63+
required=True,
64+
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password','class': 'form-control','placeholder': 'Confirm Password'}),
65+
help_text=_("Enter the same password as before, for verification."),
66+
)
67+
68+
69+
user_type = forms.ChoiceField(
70+
label=_("Are You"),
71+
choices=USER_TYPE,
72+
required=True,
73+
widget= forms.RadioSelect()
74+
)
75+
class Meta:
76+
model = User
77+
fields = ['first_name','last_name','username','email','phone','password1', 'password2', 'user_type']
78+
79+
80+
class AccountPasswordchangeForm(PasswordChangeForm):
81+
old_password = forms.CharField(
82+
label=_("Current Password"),
83+
strip=False,
84+
widget=forms.PasswordInput(attrs={'autocomplete': 'current-password', 'autofocus': True,'class': 'form-control','placeholder': 'Old password'}),
85+
)
86+
new_password1 = forms.CharField(
87+
label=_("New password"),
88+
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password','class': 'form-control','placeholder': 'New password'}),
89+
strip=False,
90+
help_text=password_validation.password_validators_help_text_html(),
91+
)
92+
new_password2 = forms.CharField(
93+
label=_("Re-enter New Password"),
94+
strip=False,
95+
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password','class': 'form-control','placeholder': 'New confirmation password'}),
96+
)
97+
98+
99+
class AccountPasswordResetForm(PasswordResetForm):
100+
email = forms.EmailField(
101+
label=_("Email"),
102+
max_length=254,
103+
widget=forms.EmailInput(attrs={'autocomplete': 'email','class': 'form-control'})
104+
)
105+
106+
107+
class AccountsetPasswordForm(SetPasswordForm):
108+
new_password1 = forms.CharField(label=_("New password"),strip=False,
109+
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password','class':'input-box','placeholder': 'Password'}),help_text=password_validation.password_validators_help_text_html())
110+
new_password2 = forms.CharField(label=_("Confirm New Password"),strip=False,
111+
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password','class':'input-box','placeholder': 'Confirm Password'})
112+
)

account/managers.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from django.contrib.auth.base_user import BaseUserManager
2+
from django.utils.translation import ugettext_lazy as _
3+
4+
5+
class CustomUserManager(BaseUserManager):
6+
"""
7+
Custom user model manager where email is the unique identifiers
8+
for authentication instead of usernames.
9+
10+
"""
11+
def create_user(self, email, username,password, **extra_fields):
12+
"""
13+
Create and save a User with the given email and password.
14+
"""
15+
if not email:
16+
raise ValueError(_('The Email must be set'))
17+
email = self.normalize_email(email) #self.normalize_email(email).lower
18+
user = self.model(email=email,username=username ,**extra_fields)
19+
user.set_password(password)
20+
user.save()
21+
return user
22+
23+
def create_superuser(self, email,username, password, **extra_fields):
24+
"""
25+
Create and save a SuperUser with the given email and password.
26+
"""
27+
extra_fields.setdefault('is_staff', True)
28+
extra_fields.setdefault('is_superuser', True)
29+
extra_fields.setdefault('is_active', True)
30+
31+
if extra_fields.get('is_staff') is not True:
32+
raise ValueError(_('Superuser must have is_staff=True.'))
33+
if extra_fields.get('is_superuser') is not True:
34+
raise ValueError(_('Superuser must have is_superuser=True.'))
35+
return self.create_user(email,username, password, **extra_fields)

account/migrations/0001_initial.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Generated by Django 3.2.7 on 2021-12-02 14:26
2+
3+
import account.models
4+
import django.core.validators
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
initial = True
11+
12+
dependencies = [
13+
('auth', '0012_alter_user_first_name_max_length'),
14+
]
15+
16+
operations = [
17+
migrations.CreateModel(
18+
name='User',
19+
fields=[
20+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
21+
('password', models.CharField(max_length=128, verbose_name='password')),
22+
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
23+
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
24+
('email', account.models.LowercaseEmailField(max_length=254, unique=True, verbose_name='email address')),
25+
('username', models.CharField(max_length=150, unique=True, verbose_name='username')),
26+
('first_name', models.CharField(blank=True, max_length=255)),
27+
('last_name', models.CharField(blank=True, max_length=255)),
28+
('phone', models.CharField(blank=True, max_length=255, null=True, validators=[django.core.validators.RegexValidator(message='phone number should exactly be in 11 digits', regex='^\\d{11}$')])),
29+
('profile_image', models.ImageField(blank=True, null=True, upload_to='media/user_profile_pic')),
30+
('user_type', models.CharField(choices=[('Patient', 'Patient'), ('Doctor', 'Doctor')], max_length=255)),
31+
('is_staff', models.BooleanField(default=False)),
32+
('is_active', models.BooleanField(default=True)),
33+
('date_joined', models.DateTimeField(auto_now_add=True)),
34+
('updated', models.DateTimeField(auto_now=True)),
35+
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
36+
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
37+
],
38+
options={
39+
'verbose_name': 'Accounts',
40+
'verbose_name_plural': 'Accounts',
41+
},
42+
),
43+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.2.7 on 2021-12-02 16:48
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('account', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='user',
15+
name='profile_image',
16+
field=models.ImageField(blank=True, null=True, upload_to='user_profile_pic'),
17+
),
18+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.2.7 on 2021-12-02 16:51
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('account', '0002_alter_user_profile_image'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='user',
15+
name='profile_image',
16+
field=models.ImageField(default='user_profile_pic/avatar.png', upload_to='user_profile_pic'),
17+
),
18+
]

account/migrations/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

account/models.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from django.db import models
2+
from django.contrib.auth.models import AbstractBaseUser,PermissionsMixin,AbstractUser
3+
from django.utils.translation import ugettext_lazy as _
4+
from django.core.validators import RegexValidator
5+
from .managers import CustomUserManager
6+
7+
# Create your models here.
8+
9+
class LowercaseEmailField(models.EmailField):
10+
"""
11+
Override EmailField to convert emails to lowercase before saving.
12+
"""
13+
def to_python(self, value):
14+
"""
15+
Convert email to lowercase.
16+
"""
17+
value = super(LowercaseEmailField, self).to_python(value)
18+
# Value can be None so check that it's a string before lowercasing.
19+
if isinstance(value, str):
20+
return value.lower()
21+
return value
22+
23+
24+
class User(AbstractBaseUser,PermissionsMixin):
25+
userType = (
26+
('Patient','Patient'),
27+
('Doctor','Doctor'),
28+
)
29+
30+
email = LowercaseEmailField(_('email address'), unique=True)
31+
username = models.CharField(_('username'), max_length=150,unique=True)
32+
first_name = models.CharField(max_length=255, blank = True)
33+
last_name = models.CharField(max_length=255, blank = True)
34+
# if you require phone number field in your project
35+
phone_regex = RegexValidator( regex = r'^\d{11}$',message = "phone number should exactly be in 11 digits")
36+
phone = models.CharField(max_length=255, validators=[phone_regex], blank = True, null=True) # you can set it unique = True
37+
profile_image = models.ImageField(upload_to='user_profile_pic',default='user_profile_pic/avatar.png')
38+
user_type = models.CharField(max_length=255,choices=userType)
39+
is_staff = models.BooleanField(default=False)
40+
is_active = models.BooleanField(default=True)
41+
date_joined = models.DateTimeField(auto_now_add=True)
42+
updated = models.DateTimeField(auto_now=True)
43+
44+
objects = CustomUserManager()
45+
USERNAME_FIELD = 'email'
46+
REQUIRED_FIELDS = ['username','phone']
47+
48+
class Meta:
49+
verbose_name = "Accounts"
50+
verbose_name_plural ="Accounts"
51+
52+
def __str__(self):
53+
return self.username
54+
55+
def full_name(self):
56+
"""
57+
Return the first_name plus the last_name, with a space in between.
58+
"""
59+
full_name = '%s %s' % (self.first_name, self.last_name)
60+
return full_name.strip()
61+
62+

account/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

account/urls.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
from django.urls import path,include
3+
from .views import *
4+
# ----------- import for Login,Logout authentication and render template ----------------- #
5+
from django.contrib.auth import views as auth_views
6+
from django.contrib.auth.decorators import login_required
7+
from .forms import *
8+
9+
urlpatterns = [
10+
path('login', LoginView.as_view(),name='login'),
11+
path('logout', logoutView.as_view(),name='logout'),
12+
path('signup', signupView, name='signup'),
13+
14+
# password setup url
15+
path('passwordchange/',auth_views.PasswordChangeView.as_view(template_name='account/passwordchange.html',form_class=AccountPasswordchangeForm,success_url='/account/passwordchangedone/'),name='passwordchange'),
16+
17+
path('passwordchangedone/',auth_views.PasswordChangeDoneView.as_view(template_name='account/passwordchangedone.html'),name='passwordchangedone'),
18+
19+
# ----------- for password reset url ----------------- #
20+
21+
path('password-reset/',auth_views.PasswordResetView.as_view(template_name='account/password_reset.html',form_class=AccountPasswordResetForm), name='password_reset'),
22+
23+
path('password-reset/done/',auth_views.PasswordResetDoneView.as_view(template_name='account/password_reset_done.html'),name='password_reset_done'),
24+
25+
path('password-reset-confirm/<uidb64>/<token>/',auth_views.PasswordResetConfirmView.as_view(template_name='account/password_reset_confirm.html',form_class=AccountsetPasswordForm),name='password_reset_confirm'),
26+
27+
path('password-reset-complete',auth_views.PasswordResetCompleteView.as_view(template_name='account/password_reset_complete.html'),name='password_reset_complete'),
28+
]

0 commit comments

Comments
 (0)