-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
62 lines (51 loc) · 1.6 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from flask import Flask, request, redirect, url_for, render_template
import psycopg2
import logging
app = Flask(__name__)
# Configure logging
logging.basicConfig(level=logging.DEBUG)
# RDS database configuration
db_host = 'microservice.caywlfxrbtml.eu-central-1.rds.amazonaws.com'
db_port = '5432'
db_user = 'postgres'
db_password = '8nDzLEzeyBXqyODaJa3j'
db_name = 'microservice'
table_name = 'users'
# Database Connection
def get_db_connection():
try:
conn = psycopg2.connect(
dbname=db_name,
user=db_user,
password=db_password,
host=db_host
)
logging.debug("Database connection successful.")
return conn
except Exception as e:
logging.debug(f"Database connection failed: {e}")
return None
# Routes
@app.route('/')
def login():
return render_template('login.html')
@app.route('/login', methods=['POST'])
def login_post():
email = request.form['email']
password = request.form['password']
conn = get_db_connection()
if conn:
cursor = conn.cursor()
cursor.execute("SELECT * FROM users WHERE email = %s AND password = %s", (email, password))
user = cursor.fetchone()
cursor.close()
conn.close()
if user:
return redirect(url_for('product'))
return redirect(url_for('login'))
@app.route('/product')
def product():
return redirect("http://crypto-app-882103207.eu-central-1.elb.amazonaws.com:5000/welcomepage")
#return "Hello, this is the product page."
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)