This commit is contained in:
Mateusz779 2023-04-13 12:25:01 +02:00
parent b52296b42e
commit ec0441d621
2 changed files with 7 additions and 10 deletions

15
app.py
View File

@ -25,11 +25,11 @@ def main():
@app.route('/login') @app.route('/login')
def login(): def login():
try: auth_token = request.cookies.get('auth_token')
if request.get_data()["incorrect"]: if auth_token != "" or auth_token is not None:
return render_template('login.html', incorrect="Incorrect username or password!") if db.get_user_bytoken(auth_token) is not None:
except: return render_template('index.html')
pass
return render_template('login.html') return render_template('login.html')
@app.route('/api/login', methods=['POST']) @app.route('/api/login', methods=['POST'])
@ -39,13 +39,10 @@ def login_api():
auth_token = db.login(username, password) auth_token = db.login(username, password)
if auth_token is None: if auth_token is None:
response = make_response(redirect("/login")) return render_template('login.html', incorrect="Incorrect username or password!")
response.set_data({"incorrect":"Incorrect username or password!"})
return response
response = make_response(render_template('index.html')) response = make_response(render_template('index.html'))
response.set_cookie('auth_token', auth_token) response.set_cookie('auth_token', auth_token)
return response return response

View File

@ -49,7 +49,7 @@
<body> <body>
<div id="login-box"> <div id="login-box">
<h1>Logowanie</h1> <h1>Logowanie</h1>
<form method="POST" action="api/login"> <form method="POST" action="/api/login">
<label for="username">Nazwa użytkownika:</label> <label for="username">Nazwa użytkownika:</label>
<input type="text" id="username" name="username" placeholder="Wprowadź nazwę użytkownika"> <input type="text" id="username" name="username" placeholder="Wprowadź nazwę użytkownika">