Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2020-101
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sachith Fernando
2020-101
Commits
745c0fb3
Commit
745c0fb3
authored
Oct 20, 2020
by
I.K Seneviratne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Committing the implementations of creating an admin user.
parent
3a6301d8
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
375 additions
and
66 deletions
+375
-66
FirstApp/MongoModels.py
FirstApp/MongoModels.py
+15
-0
FirstApp/admin.py
FirstApp/admin.py
+3
-1
FirstApp/forms.py
FirstApp/forms.py
+48
-1
FirstApp/migrations/0015_auto_20201020_2157.py
FirstApp/migrations/0015_auto_20201020_2157.py
+34
-0
FirstApp/templates/FirstApp/activity.html
FirstApp/templates/FirstApp/activity.html
+0
-60
FirstApp/templates/FirstApp/admin_login.html
FirstApp/templates/FirstApp/admin_login.html
+100
-0
FirstApp/templates/FirstApp/user_direct.html
FirstApp/templates/FirstApp/user_direct.html
+101
-0
FirstApp/urls.py
FirstApp/urls.py
+16
-2
FirstApp/views.py
FirstApp/views.py
+58
-2
No files found.
FirstApp/MongoModels.py
View file @
745c0fb3
...
@@ -40,6 +40,15 @@ class Lecturer(models.Model):
...
@@ -40,6 +40,15 @@ class Lecturer(models.Model):
return
self
.
lecturer_id
return
self
.
lecturer_id
# admin model
class
Admin
(
models
.
Model
):
admin_id
=
models
.
CharField
(
max_length
=
10
)
name
=
models
.
CharField
(
max_length
=
20
)
email
=
models
.
EmailField
()
def
__str__
(
self
):
return
self
.
admin_id
# Lecturer_subject model
# Lecturer_subject model
class
LecturerSubject
(
models
.
Model
):
class
LecturerSubject
(
models
.
Model
):
lec_subject_id
=
models
.
CharField
(
max_length
=
10
)
lec_subject_id
=
models
.
CharField
(
max_length
=
10
)
...
@@ -56,6 +65,12 @@ class LecturerCredentials(models.Model):
...
@@ -56,6 +65,12 @@ class LecturerCredentials(models.Model):
password
=
models
.
CharField
(
max_length
=
15
)
password
=
models
.
CharField
(
max_length
=
15
)
# admin credential details
class
AdminCredentialDetails
(
models
.
Model
):
username
=
models
.
ForeignKey
(
Admin
,
on_delete
=
models
.
CASCADE
)
password
=
models
.
CharField
(
max_length
=
15
)
# timetable based on daily basis
# timetable based on daily basis
class
DailyTimeTable
(
models
.
Model
):
class
DailyTimeTable
(
models
.
Model
):
slot_id
=
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
)
slot_id
=
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
)
...
...
FirstApp/admin.py
View file @
745c0fb3
...
@@ -13,3 +13,5 @@ admin.site.register(FacultyTimetable)
...
@@ -13,3 +13,5 @@ admin.site.register(FacultyTimetable)
admin
.
site
.
register
(
LectureVideo
)
admin
.
site
.
register
(
LectureVideo
)
admin
.
site
.
register
(
LectureActivity
)
admin
.
site
.
register
(
LectureActivity
)
admin
.
site
.
register
(
LectureGazeEstimation
)
admin
.
site
.
register
(
LectureGazeEstimation
)
admin
.
site
.
register
(
Admin
)
admin
.
site
.
register
(
AdminCredentialDetails
)
\ No newline at end of file
FirstApp/forms.py
View file @
745c0fb3
...
@@ -58,3 +58,50 @@ class LecturerCredentialsForm(forms.ModelForm):
...
@@ -58,3 +58,50 @@ class LecturerCredentialsForm(forms.ModelForm):
widgets
=
{
widgets
=
{
'password'
:
forms
.
PasswordInput
()
'password'
:
forms
.
PasswordInput
()
}
}
# admin login form
class
AdminLoginForm
(
forms
.
Form
):
# username = forms.CharField(max_length=100)
email
=
forms
.
EmailField
()
password
=
forms
.
CharField
(
widget
=
forms
.
PasswordInput
())
def
clean
(
self
):
# cleaned_username = self.cleaned_data.get('username')
cleaned_email
=
self
.
cleaned_data
.
get
(
'email'
)
cleaned_password
=
self
.
cleaned_data
.
get
(
'password'
)
admin
=
Admin
.
objects
.
get
(
email
=
cleaned_email
)
# if an admin is already in the system
if
(
admin
):
# retrieve the User object
user
=
User
.
objects
.
get
(
email
=
cleaned_email
)
is_user
=
user
.
check_password
(
cleaned_password
)
# if the password is correct
if
(
is_user
):
# lec_credentials = LecturerCredentials.objects.filter(username_id=lecturer.id)
admin_credentials
=
AdminCredentialDetails
.
objects
.
get
(
username_id
=
admin
.
id
)
print
(
'credentials: '
,
admin_credentials
)
# if lecture credentials are already created
if
(
admin_credentials
):
admin_credentials
.
password
=
user
.
password
admin_credentials
.
save
(
force_update
=
True
)
else
:
LecturerCredentials
(
username_id
=
admin
.
id
,
password
=
user
.
password
)
.
save
()
else
:
raise
forms
.
ValidationError
(
"Username or password is incorrect"
)
else
:
print
(
'the admin does not exist'
)
raise
forms
.
ValidationError
(
"The admin does not exist"
)
return
super
(
AdminLoginForm
,
self
)
.
clean
()
FirstApp/migrations/0015_auto_20201020_2157.py
0 → 100644
View file @
745c0fb3
# Generated by Django 2.2.11 on 2020-10-20 16:27
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'FirstApp'
,
'0014_lecturegazeframerecognitions'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Admin'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'admin_id'
,
models
.
CharField
(
max_length
=
10
)),
(
'name'
,
models
.
CharField
(
max_length
=
20
)),
(
'email'
,
models
.
EmailField
(
max_length
=
254
)),
],
),
migrations
.
CreateModel
(
name
=
'AdminCredentialDetails'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'password'
,
models
.
CharField
(
max_length
=
15
)),
(
'username'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'FirstApp.Admin'
)),
],
),
migrations
.
DeleteModel
(
name
=
'LecturePoseEstimation'
,
),
]
FirstApp/templates/FirstApp/activity.html
View file @
745c0fb3
...
@@ -1215,66 +1215,6 @@
...
@@ -1215,66 +1215,6 @@
</div>
</div>
<!--2nd column -->
{#
<div
class=
"col-lg-6"
>
#}
{#
<!--card content -->
#}
{#
<div
class=
"card shadow mb-4"
>
#}
{#
<!--card header -->
#}
{#
<div
class=
"card-header py-3"
>
#}
{#
<h5
class=
"m-0 font-weight-bold text-primary"
>
Frame Detections
</h5>
#}
{#
</div>
#}
{##}
{#
<!--card body -->
#}
{#
<div
class=
"text-center p-4"
id=
"detection_frames"
>
#}
{##}
{#
<!--no content message-->
#}
{#
<div
class=
"text-center p-2"
id=
"no_detection_message_content"
>
#}
{#
<span
class=
"font-italic"
>
No frame is selected
</span>
#}
{#
</div>
#}
{##}
{#
<div
class=
"text-left m-3"
id=
"detection_number_area"
hidden
>
#}
{#
<p>
No of detections:
<span
id=
"no_of_detections"
></span></p>
#}
{#
</div>
#}
{#
<!--the detection loader -->
#}
{#
<div
class=
"text-center p-2"
id=
"detection_loader"
hidden
>
#}
{#
<img
src=
"{% static 'FirstApp/images/ajax-loader.gif' %}"
#
}
{
#
alt=
"Loader"
>
#}
{#
</div>
#}
{#
</div>
#}
{#
</div>
#}
<!--detection person card -->
{#
<div
class=
"card shadow mb-4"
>
#}
{#
<!--card header -->
#}
{#
<div
class=
"card-header py-3"
>
#}
{#
<h5
class=
"m-0 font-weight-bold text-primary"
>
Detected Students (by activity#}
{# type)
</h5>
#}
{#
</div>
#}
{##}
{#
<!--card body -->
#}
{#
<div
class=
"text-center p-4"
id=
"detection_students"
>
#}
{#
<!--activity type line -->
#}
{#
<div
class=
"text-center p-2"
id=
"activity_type"
hidden
>
#}
{#
<p>
Activity Type:
<span
class=
"font-weight-bold"
id=
"activity_type_text"
></span>
#}
{#
</p>
#}
{#
</div>
#}
{##}
{#
<!--no content message-->
#}
{#
<div
class=
"text-center p-2"
id=
"no_detection_student_content"
>
#}
{#
<span
class=
"font-italic"
>
No activity type is selected
</span>
#}
{#
</div>
#}
{##}
{#
<!--the detection student loader -->
#}
{#
<div
class=
"text-center p-2"
id=
"detection_student_loader"
hidden
>
#}
{#
<img
src=
"{% static 'FirstApp/images/ajax-loader.gif' %}"
#
}
{
#
alt=
"Loader"
>
#}
{#
</div>
#}
{##}
{#
</div>
#}
{#
</div>
#}
{#
</div>
#}
<!--2nd column -->
<!--2nd column -->
<div
class=
"col-lg-6"
>
<div
class=
"col-lg-6"
>
<!--card -->
<!--card -->
...
...
FirstApp/templates/FirstApp/admin_login.html
0 → 100644
View file @
745c0fb3
{% load static %}
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"utf-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, shrink-to-fit=no"
>
<meta
name=
"description"
content=
""
>
<meta
name=
"author"
content=
""
>
<title>
SLPES
</title>
<!-- Custom fonts for this template-->
<link
href=
"{% static 'FirstApp/vendor/fontawesome-free/css/all.min.css' %}"
rel=
"stylesheet"
type=
"text/css"
>
<link
href=
"https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
rel=
"stylesheet"
>
<!-- Custom styles for this template-->
<link
href=
"{% static 'FirstApp/css/sb-admin-2.min.css' %}"
rel=
"stylesheet"
>
</head>
<body
class=
"bg-gradient-primary"
>
<div
class=
"container"
>
<!-- Outer Row -->
<div
class=
"row justify-content-center"
>
<div
class=
"col-xl-10 col-lg-12 col-md-9"
>
<div
class=
"card o-hidden border-0 shadow-lg my-5"
>
<div
class=
"card-body p-0"
>
<!-- Nested Row within Card Body -->
<div
class=
"row"
>
<div
class=
"col-lg-6 d-none d-lg-block"
>
<img
src=
"{% static 'FirstApp/images/admin.jpg' %}"
width=
"400"
height=
"600"
alt=
"No image"
>
</div>
<div
class=
"col-lg-6"
>
<div
class=
"p-5"
>
<div
class=
"text-center"
>
<h1
class=
"h4 text-gray-900 mb-4"
>
Welcome Back!
</h1>
</div>
<!--form -->
<form
action=
"/process-admin-login"
method=
"POST"
name=
"loginForm"
class=
"user"
>
{% csrf_token %}
<div
class=
"form-group"
>
<input
type=
"email"
name=
"email"
class=
"form-control form-control-user"
id=
"exampleInputEmail"
aria-describedby=
"emailHelp"
placeholder=
"Enter Email Address..."
>
</div>
<div
class=
"form-group"
>
<input
type=
"password"
name=
"password"
class=
"form-control form-control-user"
id=
"exampleInputPassword"
placeholder=
"Password"
>
<div
class=
"alert alert-danger m-4"
>
{{ message }}
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"custom-control custom-checkbox small"
>
<input
type=
"checkbox"
class=
"custom-control-input"
id=
"customCheck"
>
<label
class=
"custom-control-label"
for=
"customCheck"
>
Remember Me
</label>
</div>
</div>
<button
type=
"submit"
class=
"btn btn-primary btn-user btn-block"
>
Login
</button>
<hr>
</form>
<hr>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript-->
<script
src=
"{% static 'FirstApp/vendor/jquery/jquery.min.js' %}"
></script>
<script
src=
"{% static 'FirstApp/vendor/bootstrap/js/bootstrap.bundle.min.js' %}"
></script>
<!-- Core plugin JavaScript-->
<script
src=
"{% static 'FirstApp/vendor/jquery-easing/jquery.easing.min.js' %}"
></script>
<!-- Custom scripts for all pages-->
<script
src=
"{% static 'FirstApp/js/sb-admin-2.min.js' %}"
></script>
</body>
</html>
FirstApp/templates/FirstApp/user_direct.html
0 → 100644
View file @
745c0fb3
{% load static %}
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"utf-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, shrink-to-fit=no"
>
<meta
name=
"description"
content=
""
>
<meta
name=
"author"
content=
""
>
<title>
SLPES
</title>
<!-- Custom fonts for this template-->
<link
href=
"{% static 'FirstApp/vendor/fontawesome-free/css/all.min.css' %}"
rel=
"stylesheet"
type=
"text/css"
>
<link
href=
"https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
rel=
"stylesheet"
>
<!-- Custom styles for this template-->
<link
href=
"{% static 'FirstApp/css/sb-admin-2.min.css' %}"
rel=
"stylesheet"
>
</head>
<body
class=
"bg-gradient-primary"
>
<div
class=
"container"
>
<!-- Outer Row -->
<div
class=
"row justify-content-center"
>
<div
class=
"col-xl-10 col-lg-12 col-md-9"
>
<div
class=
"card o-hidden border-0 shadow-lg my-5"
>
<div
class=
"card-body p-0"
>
<!-- Nested Row within Card Body -->
<div
class=
"row"
>
<div
class=
"col-lg-6 d-none d-lg-block"
>
<img
src=
"{% static 'FirstApp/images/user_redirect.png' %}"
width=
"400"
height=
"500"
alt=
"No image"
>
</div>
<div
class=
"col-lg-6"
>
<div
class=
"p-5"
>
<div
class=
"text-center"
>
<h1
class=
"h4 text-gray-900 mb-4"
>
Select the user type
</h1>
</div>
<!--form -->
<form
action=
"/process-user-redirect"
method=
"POST"
name=
"loginForm"
class=
"user"
>
{% csrf_token %}
<div
class=
"form-check mx-3"
>
<input
class=
"form-check-input"
type=
"radio"
name=
"user_type"
id=
"admin"
value=
"admin"
checked
>
<label
class=
"form-check-label"
for=
"admin"
>
Admin
</label>
</div>
<div
style=
"padding-top: 20px"
>
<div
class=
"form-check mx-3"
>
<input
class=
"form-check-input"
type=
"radio"
name=
"user_type"
id=
"lecturer"
value=
"lecturer"
>
<label
class=
"form-check-label"
for=
"lecturer"
>
Lecturer
</label>
</div>
<div
style=
"padding-top: 20px"
>
<button
type=
"submit"
class=
"btn btn-primary btn-user btn-block"
>
Proceed
</button>
<hr>
</form>
<hr>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript-->
<script
src=
"{% static 'FirstApp/vendor/jquery/jquery.min.js' %}"
></script>
<script
src=
"{% static 'FirstApp/vendor/bootstrap/js/bootstrap.bundle.min.js' %}"
></script>
<!-- Core plugin JavaScript-->
<script
src=
"{% static 'FirstApp/vendor/jquery-easing/jquery.easing.min.js' %}"
></script>
<!-- Custom scripts for all pages-->
<script
src=
"{% static 'FirstApp/js/sb-admin-2.min.js' %}"
></script>
</body>
</html>
FirstApp/urls.py
View file @
745c0fb3
...
@@ -32,10 +32,20 @@ urlpatterns = [
...
@@ -32,10 +32,20 @@ urlpatterns = [
# video results
# video results
path
(
'video_result'
,
views
.
video_result
),
path
(
'video_result'
,
views
.
video_result
),
# this is used
for
login
# this is used
to process
login
path
(
'process-login'
,
views
.
loggedInView
),
path
(
'process-login'
,
views
.
loggedInView
),
# this is used for login
# this is used to process admin login
path
(
'process-admin-login'
,
views
.
processAdminLogin
),
# this is used for user-redirect processing
path
(
'process-user-redirect'
,
views
.
processUserRedirect
),
# this is used for admin login page
path
(
'admin-login'
,
views
.
adminLogin
),
# this is used for activity
path
(
'activity'
,
views
.
activity
),
path
(
'activity'
,
views
.
activity
),
# tables view
# tables view
...
@@ -44,6 +54,10 @@ urlpatterns = [
...
@@ -44,6 +54,10 @@ urlpatterns = [
# test view (delete later)
# test view (delete later)
path
(
'test'
,
views
.
test
),
path
(
'test'
,
views
.
test
),
# user direct view
path
(
'user-direct'
,
views
.
userDirect
),
url
(
r'^register'
,
views
.
RegisterViewSet
),
url
(
r'^register'
,
views
.
RegisterViewSet
),
# re_path('video/?video_name<str:video_name>', views.video),
# re_path('video/?video_name<str:video_name>', views.video),
url
(
r'^teachers/'
,
views
.
teachersList
.
as_view
()),
url
(
r'^teachers/'
,
views
.
teachersList
.
as_view
()),
...
...
FirstApp/views.py
View file @
745c0fb3
...
@@ -506,7 +506,7 @@ def logoutView(request):
...
@@ -506,7 +506,7 @@ def logoutView(request):
logout
(
request
)
logout
(
request
)
return
redirect
(
'/
login
'
)
return
redirect
(
'/
user-direct
'
)
# 500 error page
# 500 error page
...
@@ -546,3 +546,59 @@ def activity(request):
...
@@ -546,3 +546,59 @@ def activity(request):
def
test
(
request
):
def
test
(
request
):
return
render
(
request
,
"FirstApp/pdf_template.html"
)
return
render
(
request
,
"FirstApp/pdf_template.html"
)
# this method will handle user directing function
def
userDirect
(
request
):
return
render
(
request
,
"FirstApp/user_direct.html"
)
# this method will handle user redirection process
def
processUserRedirect
(
request
):
if
request
.
POST
:
user_type
=
request
.
POST
.
get
(
'user_type'
)
if
user_type
==
'admin'
:
return
redirect
(
'/admin-login'
)
elif
user_type
==
'lecturer'
:
return
redirect
(
'/login'
)
return
redirect
(
'/500'
)
# admin login page
def
adminLogin
(
request
):
return
render
(
request
,
"FirstApp/admin_login.html"
)
# this method will process admin login
def
processAdminLogin
(
request
):
username
=
"not logged in"
message
=
"Invalid Username or Password"
adminLoginForm
=
AdminLoginForm
(
request
.
POST
)
print
(
'message: '
,
message
)
try
:
# if the details are valid, let the user log in
if
adminLoginForm
.
is_valid
():
email
=
adminLoginForm
.
cleaned_data
.
get
(
'email'
)
user
=
User
.
objects
.
get
(
email
=
email
)
admin
=
Admin
.
objects
.
get
(
email
=
email
)
login
(
request
,
user
)
# setting up the session
request
.
session
[
'admin'
]
=
admin
.
id
return
redirect
(
'/summary/lecture'
)
else
:
message
=
"Please provide correct credntials"
except
Exception
as
exc
:
print
(
'exception: '
,
exc
)
return
render
(
request
,
'FirstApp/admin_login.html'
,
{
'message'
:
message
})
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment