+Fix On user in login not there it makes an error. +Added On user or pass incorect make indicator.
This commit is contained in:
parent
321923b056
commit
cffe60b109
4 changed files with 64 additions and 6 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1 +1,3 @@
|
||||||
.venv
|
.venv
|
||||||
|
db.sqlite
|
||||||
|
**/__pycache__/
|
||||||
|
|
@ -12,9 +12,13 @@ config.read('Options.ini')
|
||||||
|
|
||||||
|
|
||||||
class compare:
|
class compare:
|
||||||
|
|
||||||
def is_user_pass_valid(username, password):
|
def is_user_pass_valid(username, password):
|
||||||
|
try: #check if username in db
|
||||||
session_username = session.query(User).filter(User.username == username).one()
|
session_username = session.query(User).filter(User.username == username).one()
|
||||||
session.commit()
|
session.commit()
|
||||||
|
except:
|
||||||
|
return False
|
||||||
print(session_username.hashed_password)
|
print(session_username.hashed_password)
|
||||||
if bcrypt.hashpw(password.encode('utf-8'), session_username.salt) == session_username.hashed_password.encode('utf-8'):
|
if bcrypt.hashpw(password.encode('utf-8'), session_username.salt) == session_username.hashed_password.encode('utf-8'):
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,7 @@ def login():
|
||||||
form = LoginForm()
|
form = LoginForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
user = user_loader(form.username.data)
|
user = user_loader(form.username.data)
|
||||||
#TODO if username not in User:
|
|
||||||
#TODO return if username or pass wrong a red textbox in ui...
|
|
||||||
if user and compare.is_user_pass_valid(form.username.data, form.password.data):
|
if user and compare.is_user_pass_valid(form.username.data, form.password.data):
|
||||||
login_user(user) # store user id in session
|
login_user(user) # store user id in session
|
||||||
|
|
||||||
|
|
@ -82,8 +81,9 @@ def login():
|
||||||
#next = request.args.get('next') is written in documentaion FLASK
|
#next = request.args.get('next') is written in documentaion FLASK
|
||||||
#return redirect(next, url_for('orders')) # redirect to orders page
|
#return redirect(next, url_for('orders')) # redirect to orders page
|
||||||
return redirect(url_for('orders')) # redirect to orders page
|
return redirect(url_for('orders')) # redirect to orders page
|
||||||
|
#return wrong_user_pass.html a indexer for wrong pass or username
|
||||||
|
return render_template('partials/_wrong_user_pass.html', form=form)
|
||||||
return render_template('login.html', form=form)
|
return render_template('login.html', form=form)
|
||||||
|
|
||||||
@app.route("/logout") #TODO make a button
|
@app.route("/logout") #TODO make a button
|
||||||
@login_required
|
@login_required
|
||||||
def logout():
|
def logout():
|
||||||
|
|
|
||||||
52
Server/Host/templates/partials/_wrong_user_pass.html
Normal file
52
Server/Host/templates/partials/_wrong_user_pass.html
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Login Page</title>
|
||||||
|
</head>
|
||||||
|
<style>
|
||||||
|
/* Grundstil der Textbox */
|
||||||
|
div {
|
||||||
|
border: 2px solid gray;
|
||||||
|
width: 17vw;
|
||||||
|
margin-top: 5px;
|
||||||
|
height: 30px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 1rem;
|
||||||
|
outline: none;
|
||||||
|
transition: border-color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Schüttel-Animation definieren */
|
||||||
|
@keyframes shake {
|
||||||
|
0% { transform: translateX(0); }
|
||||||
|
25% { transform: translateX(5px); }
|
||||||
|
50% { transform: translateX(-5px); }
|
||||||
|
75% { transform: translateX(5px); }
|
||||||
|
100% { transform: translateX(0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Animation bei ungültigem Zustand oder wenn Klasse "shake" gesetzt wird */
|
||||||
|
div.shake {
|
||||||
|
border-color: red;
|
||||||
|
animation: shake 0.3s ease-in-out 0s 3;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<body>
|
||||||
|
<h1>Login Page</h1>
|
||||||
|
<div type="text" class="shake" placeholder="Invalid">Invalid User or Password</div>
|
||||||
|
<form method="POST" action="{{ url_for('login') }}">
|
||||||
|
{{ form.csrf_token }}
|
||||||
|
{{ form.username.label }}
|
||||||
|
{{ form.username }}
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
{{ form.password.label }}
|
||||||
|
{{ form.password }}
|
||||||
|
<br>
|
||||||
|
<p>{{ form.remember_me }} {{ form.remember_me.label }}</p>
|
||||||
|
<br>
|
||||||
|
{{ form.submit }}
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue