-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
47 lines (38 loc) · 1.39 KB
/
app.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
from flask import Flask, redirect, render_template, request, session, url_for
from flask_sqlalchemy import SQLAlchemy
from passlib.hash import sha256_crypt
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
app.config['SECRET_KEY'] = 'vyuvbyubugYUVKFVKUFV7678vk'
db = SQLAlchemy(app)
class Main(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True)
password = db.Column(db.String(120))
ph = db.Column(db.Float)
hardness = db.Column(db.Float)
cost = db.Column(db.Integer)
with app.app_context():
db.create_all()
@app.route('/', methods=['GET', 'POST'])
def login():
session.clear()
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
row = Main.query.filter_by(username=username).first()
if row and sha256_crypt.verify(password, row.password):
session['username'] = username
return redirect("/home_stud")
else:
return render_template('login.html')
else:
return render_template('login.html')
@app.route('/details')
def details():
if 'username' in session:
# Fetch all rows from the Main table
all_rows = Main.query.all()
return render_template('details.html', rows=all_rows)
else:
return redirect(url_for('login'))