-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.py
116 lines (91 loc) · 3.09 KB
/
routes.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from flask import Flask, render_template, redirect, request, url_for
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField
from wtforms.validators import InputRequired, Email, Length
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
import new_user_credentials as nuc
from werkzeug.security import generate_password_hash, check_password_hash
login_manager = LoginManager()
login_manager.init_app(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
app.config['SECRET_KEY'] = "secret key"
db = SQLAlchemy(app)
db.create_all()
SQLALCHEMY_TRACK_MODIFICATIONS = False
@login_manager.user_loader
def load_user(user_id):
return individual.query.get(user_id)
@app.route('/')
def home():
return render_template('dummy home.html')
@app.route('/individual_register')
def individual_register():
return render_template('individual_register.html')
@app.route('/labs_register')
def hello_worl():
return render_template('labs_register.html')
@app.route('/doctor_register')
def hello_world():
return render_template('doctor_register.html')
@app.route('/login')
def login():
return render_template('login.html')
@app.route('/dashboard', methods = ['GET', 'POST'])
def login_submit():
if request.method == 'POST':
try:
username = request.form['username']
password = request.form['password']
temp = individual.query.filter_by(id = username).first()
if temp:
if (check_password_hash(temp.pasw ,password)):
login_user(temp)
msg = "Login successful"
else:
msg = "Incorrect Password"
else:
msg = "User not registered!"
except Exception as e:
msg = e
#msg = "Error in insert operation"
finally:
return render_template('dummy_dashboard_2.html')
@app.route('/logout')
@login_required
def logout():
logout_user()
msg = "You are logged out!"
return render_template('thank.html', namee=msg)
@app.route('/individual_form_submit', methods = ['GET' , 'POST'])
def sub():
if request.method == 'POST':
try:
fname = request.form['fname']
lname = request.form['lname']
email = request.form['email']
mob = request.form['mob']
dob = str(request.form['dob'])
gender = request.form['gender']
aadhaar = request.form['aadhaar']
blood = request.form['blood']
state = request.form['state']
city = request.form['city']
district = request.form['district']
pin = request.form['pincode']
addr1=request.form['add1']
addr2=request.form['add2']
nu = nuc.New_user(city, dob)
h_id, pasw = nu.create_user()
temp = individual(id=h_id, pasw=generate_password_hash(pasw) ,
fname=fname, lname =lname, email=email, mob =mob, dob=dob,gender=gender,aadhaar=aadhaar, blood=blood,
state=state, city=city, district=district, pin=pin, addr1=addr1, addr2=addr2 )
db.session.add(temp)
db.session.commit()
msg = "Record successfully added"
except Exception as e:
msg = e
#msg = "Error in insert operation"
finally:
return render_template('thank.html', namee=msg)