-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
41 lines (32 loc) · 1.3 KB
/
app.py
File metadata and controls
41 lines (32 loc) · 1.3 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
import requests
from flask import Flask, render_template, request
import psycopg2
app = Flask(__name__)
conn = psycopg2.connect(database="fl_db",
user="postgres",
password="123456",
host="localhost",
port="5432")
cursor = conn.cursor()
@app.route('/', methods=['GET'])
def index():
return render_template('login.html')
@app.route('/', methods=['POST'])
def login():
username = request.form.get('username')
password = request.form.get('password')
cursor.execute("SELECT * FROM users WHERE login=%s AND password=%s", (str(username), str(password)))
records = list(cursor.fetchall())
# не введено имя пользователя
if not username:
not_field = 'Заполните поле "Username".'
return render_template('login.html', not_field=not_field)
# не введён пароль
if not password:
not_field = 'Заполните поле "Password".'
return render_template('login.html', not_field=not_field)
# пользователь не найден
if not records:
return render_template('error_form.html')
else:
return render_template('account.html', full_name=records[0][1], login=username, password=password)