-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController_Auth.py
More file actions
executable file
·80 lines (65 loc) · 2.59 KB
/
Copy pathController_Auth.py
File metadata and controls
executable file
·80 lines (65 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#flask component
from flask import render_template as view
from flask import request,session,url_for,redirect
#import app config file
import config
#modal
import Modal_Student
def adminLoginForm():
#there is no form error in get req
formError = ''
return view('adminLogin.html',formError=formError)
def adminLoginFormHandler():
#get user name and pwd from form data
userName = request.form['username']
password = request.form['password']
#validating form
formError = {}
if(userName and password == ''):
formError = {'password':'please input password'}
formError = {'username' : 'please input username'}
elif(userName == ''):
formError = {'username' : 'please input username'}
elif(password == ''):
formError = {'password':'please input password'}
elif(userName and password != ''):
#check if username and pwd is correct
appAdminUserName = config.APP_ADMIN_USERNAME
appAdminPwd = config.APP_ADMIN_PASSWORD
#on form submistion success
if(userName == appAdminUserName and password == appAdminPwd):
session['APP_ADMIN_USERNAME'] = userName
else:
formError = {'usernameOrPwdError':'username or password is incorrect'}
if(len(formError) > 0):
return view('adminLogin.html',formError=formError)
else:
#redirecting on success to admin page
return redirect(url_for('adminDashboard'))
def stdLoginForm():
#there is no form error in get req
formError = {'id':'','fullName':''}
return view('studentLogin.html',formError=formError)
def stdLoginFormHandler():
formError = {'id':'','fullName':''}
id = request.form['id']
fullName = request.form['fullName']
if(id == ''):
formError['id'] = 'please input ur id'
elif(fullName == ''):
formError['fullName'] = 'please input ur fullName'
elif(id and fullName != ''):
stdData = Modal_Student.getStudent(id)
if(len(stdData) == 0):
formError['id'] = 'please input correct id'
else:
stdId = stdData[0][0]
stdName = stdData[0][1]
stdName = stdName.lower().replace(" ", "").lstrip()
fullName = fullName.lower().replace(" ","").lstrip()
if(stdName == fullName):
session['STD_ID'] = stdId
return redirect(url_for('studentDashboard'))
else:
formError['fullName'] = 'please input correct fullName'
return view('studentLogin.html',formError=formError)