Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (42 loc) · 1.71 KB
/
Copy pathapp.py
File metadata and controls
50 lines (42 loc) · 1.71 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
import os
from flask import Flask, session, render_template, request,redirect, url_for
from flask_session import Session
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
app = Flask(__name__)
DATABASE_URL="postgres://xecvnfwmxrcxsh:23af39a6155c42d18cdc1e44565b7ad5826c793736458e8b70c04ac2e3f6ff61@ec2-23-21-70-39.compute-1.amazonaws.com:5432/db6gh7v6itdlja"
# Set up database
engine = create_engine(DATABASE_URL)
db = scoped_session(sessionmaker(bind=engine))
@app.route("/")
def index():
return render_template("signup.html")
@app.route("/login")
def login():
return render_template("login.html")
@app.route("/profile",methods=["POST"])
def profile():
return render_template("profile.html")
@app.route("/signupv",methods=["POST"])
def signupv():
username=request.form.get("username")
email=request.form.get("email")
password=request.form.get("password")
db.execute("INSERT INTO customer(username,email,password) VALUES(:username,:email,:password)",
{"username": username, "email": email, "password": password})
db.commit()
db.close()
return render_template("login.html")
@app.route("/loginvalid",methods=["POST"])
def loginvalid():
username=request.form.get("username")
password=request.form.get("password")
query=db.execute("SELECT * FROM customer WHERE username=:username AND password=:password",
{"username": username,"password": password}).fetchall()
if query == []:
return render_template("error.html")
else:
# this function will do get request
return redirect(url_for("profile"))
if __name__ == "__main__":
app.run()