-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
70 lines (66 loc) · 2.34 KB
/
server.py
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
# Importing flask and neccesary items
from flask import Flask, session, redirect, render_template, request, url_for
import UserManager as UM
# Constructing app
app = Flask(__name__)
# Secret Key setup
app.secret_key='AAAAB3NzaC1yc2EAAAABJQAAAQEAvI+0heuc2jKKSiaUEMTay7xsOhEOwapBsosHgo8jFbiELcXB1gwtELKmiLdkFRoowBb2Ga1VRJVtgeLtetM4FYu7xbRtoQB/E3tbnAJbiMy4pUCGMeI2lIFTFL0vWHGsqH/5qdoXu0dFijfdyxqvj/F5SZH7vpIXNZJu9Nvsr4UEnDWl16ndcVHsel1aMdW93I2OGLpEf8yvMR+Lq7ugVldUu2dC3FJMbZ4OkQiafDqA4ulLKk1SFRC0SsFlhIm/7XZVua4ckxEYdFRAn5NIC76ARyQUBANhIHhGkdApHm4m6ykhtozEPVagjIsNtuaZKFqOESL3ltIotHIHar/HL4Q'
# Creating an instance of UserManager
userManager = UM.UserManager()
# Setting variables
userInfo = None
userName = None
# Index
@app.route('/')
def index():
if 'UserId' in session:
userId = session['UserId']
return render_template('home.html', userId=userId)
else:
userId= ''
return render_template('home.html', userId=userId)
# Login/Logout/Signup/Profiles
@app.route('/login')
@app.route('/auth/login')
def login():
return render_template('login.html')
@app.route('/logout')
@app.route('/auth/logout')
def logout():
userInfo=None
session.pop('UserId', None)
return render_template('logout.html')
@app.route('/service/auth', methods=['POST'])
def auth_service():
UserId = request.form['uname']
Pwd = request.form['psw']
print(UserId,Pwd)
res = userManager.Auth(UserId, Pwd)
userInfo = res['user']
if userInfo != None:
userName=UserId
session['UserId'] = UserId
userData = userManager.getDetails(UserId)
session['role'] = userData[2]
return redirect(url_for('index'))
else:
return redirect(url_for('login'))
@app.route('/auth/signup')
def signup():
return render_template('signup.html')
@app.route('/service/signup', methods=['POST'])
def signup_service():
userName=request.form['userName']
password=request.form['pwd']
userManager.Signup(userName, password,'teacher')
return redirect('/auth/login')
@app.route('/service/auth/password',methods=['POST'])
def change_password():
newpassword=request.form['psw']
userManager.change_password(session['UserId'] ,newpassword)
return redirect('/')
@app.route('/profile')
def profile():
return render_template('editPwd.html')
if __name__ == "__main__":
app.run(debug=True)