Skip to content
This repository was archived by the owner on Sep 11, 2021. It is now read-only.

Commit 4d924ec

Browse files
committed
Uploaded css and js
1 parent 75211b0 commit 4d924ec

File tree

918 files changed

+245066
-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.

918 files changed

+245066
-0
lines changed

webproject/Report.pdf

966 KB
Binary file not shown.

webproject/src/accounts/__init__.py

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

webproject/src/accounts/admin.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from django.contrib import admin
2+
from django.contrib.auth.models import Group
3+
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
4+
5+
from .forms import UserCreationForm, UserChangeForm
6+
from accounts.models import User
7+
8+
class UserAdmin(BaseUserAdmin):
9+
# forms for adding and changing users
10+
model = User
11+
form = UserChangeForm
12+
add_form = UserCreationForm
13+
14+
# fields to display on the user model
15+
list_display = ('username', 'email', 'is_admin')
16+
list_filter = ('is_admin',)
17+
fieldsets = (
18+
(None, {'fields': ('email', 'password')}),
19+
('Personal info', {'fields': ('username',)}),
20+
('Permissions', {'fields': ('is_admin',)}),
21+
)
22+
23+
add_fieldsets = (
24+
(None, {
25+
'classes': ('wide',),
26+
'fields': ('username', 'email', 'password1', 'password2')}
27+
),
28+
)
29+
30+
search_fields = ('username', 'email')
31+
ordering = ('email',)
32+
filter_horizontal = ()
33+
34+
admin.site.register(User, UserAdmin)
35+
admin.site.unregister(Group)
36+
37+
38+
39+
40+
41+
42+
43+
44+

webproject/src/accounts/apps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AccountsConfig(AppConfig):
5+
name = 'accounts'

webproject/src/accounts/forms.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
from django import forms
2+
from django.contrib.auth.forms import ReadOnlyPasswordHashField
3+
from .models import User, Role
4+
5+
class UserCreationForm(forms.ModelForm):
6+
"""
7+
A form for registering new users with all required field
8+
"""
9+
password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
10+
password2 = forms.CharField(label='Confirm Password', widget=forms.PasswordInput)
11+
is_admin = forms.BooleanField(label='Is Admin', required=False, widget=forms.CheckboxInput)
12+
13+
class Meta:
14+
model = User
15+
fields = ('username', 'email', 'is_admin')
16+
17+
def clean_password2(self):
18+
"""
19+
Check to ensure passwords are the same
20+
"""
21+
password1 = self.cleaned_data.get('password1')
22+
password2 = self.cleaned_data.get('password2')
23+
24+
if password1 and password2:
25+
if password1 != password2:
26+
raise forms.ValidationError("Passwords are n't the same")
27+
else:
28+
raise forms.ValidationError("Passwords can't be empty")
29+
30+
return password2
31+
32+
def save(self, commit=True):
33+
"""
34+
Save password in hashed form
35+
"""
36+
user = super(UserCreationForm, self).save(commit=False)
37+
user.set_password(self.cleaned_data['password1'])
38+
admin = self.cleaned_data.get('is_admin')
39+
if admin:
40+
user.is_admin=True
41+
if commit:
42+
user.save()
43+
return user
44+
45+
class UserChangeForm(forms.ModelForm):
46+
"""
47+
A form for updating users with all fields while replacing password
48+
field with admin's password hash display field
49+
"""
50+
password = ReadOnlyPasswordHashField()
51+
52+
class Meta:
53+
model = User
54+
fields = ('email', 'username', 'is_active', 'is_admin')
55+
56+
def clean_password(self):
57+
return self.initial['password']
58+
59+
class UserRegisterForm(UserCreationForm):
60+
email = forms.EmailField()
61+
62+
class Meta:
63+
model = User
64+
fields = ['username', 'email', 'password1', 'password2']
65+
66+
class EditProfileForm(UserChangeForm):
67+
68+
class Meta:
69+
model = User
70+
fields = ['username', 'email', 'password']
71+
72+
class RoleCreationForm(forms.ModelForm):
73+
74+
class Meta:
75+
model = Role
76+
fields = ('name', 'description')
77+
78+
class EditRoleForm(forms.ModelForm):
79+
80+
class Meta:
81+
model = Role
82+
fields = ['name', 'description']
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Generated by Django 2.2.2 on 2019-07-03 15:12
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = [
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='User',
16+
fields=[
17+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('password', models.CharField(max_length=128, verbose_name='password')),
19+
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
20+
('username', models.CharField(max_length=255, unique=True)),
21+
('email', models.EmailField(max_length=255, unique=True, verbose_name='email address')),
22+
('is_active', models.BooleanField(default=True)),
23+
('is_admin', models.BooleanField(default=False)),
24+
('created_at', models.DateTimeField(auto_now_add=True)),
25+
('updated_at', models.DateTimeField(auto_now=True)),
26+
],
27+
options={
28+
'abstract': False,
29+
},
30+
),
31+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.2.2 on 2019-07-18 16:39
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('accounts', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='user',
15+
name='deleted',
16+
field=models.DateTimeField(editable=False, null=True),
17+
),
18+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 2.2.2 on 2019-07-18 17:21
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('accounts', '0002_user_deleted'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='user',
15+
name='deleted',
16+
),
17+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 2.2.2 on 2019-07-22 20:14
2+
3+
import django.contrib.auth.models
4+
from django.db import migrations, models
5+
import django.db.models.deletion
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('auth', '0011_update_proxy_permissions'),
12+
('accounts', '0003_remove_user_deleted'),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='Role',
18+
fields=[
19+
('group_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='auth.Group')),
20+
('description', models.TextField(max_length=255, unique=True)),
21+
],
22+
bases=('auth.group',),
23+
managers=[
24+
('objects', django.contrib.auth.models.GroupManager()),
25+
],
26+
),
27+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.2.2 on 2019-07-23 12:33
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('accounts', '0004_role'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='role',
15+
name='description',
16+
field=models.TextField(max_length=100, unique=True),
17+
),
18+
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 2.2.2 on 2019-07-31 17:57
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('auth', '0011_update_proxy_permissions'),
10+
('accounts', '0005_auto_20190723_1233'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='user',
16+
name='groups',
17+
field=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'),
18+
),
19+
migrations.AddField(
20+
model_name='user',
21+
name='is_superuser',
22+
field=models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status'),
23+
),
24+
migrations.AddField(
25+
model_name='user',
26+
name='user_permissions',
27+
field=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'),
28+
),
29+
]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Generated by Django 2.2.2 on 2019-08-09 12:50
2+
3+
from django.db import migrations
4+
from django.contrib.auth.hashers import make_password
5+
6+
7+
def load_setup_data(apps,schema_editor):
8+
"""
9+
These creates the initial role and admin user. Use the details to login
10+
then change the email and password immediately once logged in.
11+
"""
12+
DefaultRole = apps.get_model("accounts", "Role")
13+
DefaultUser = apps.get_model("accounts", "User")
14+
15+
role = DefaultRole.objects.create(name="Admin", description="This is a system administrator role.")
16+
user = DefaultUser.objects.create(
17+
username="admin",
18+
19+
password=make_password("1234@admin"),
20+
is_admin=True
21+
)
22+
role.save()
23+
user.save()
24+
user.groups.add(role)
25+
26+
27+
class Migration(migrations.Migration):
28+
29+
dependencies = [
30+
('accounts', '0006_auto_20190731_1757'),
31+
]
32+
33+
operations = [
34+
migrations.RunPython(load_setup_data)
35+
]

webproject/src/accounts/migrations/__init__.py

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

0 commit comments

Comments
 (0)