mirror of
https://github.com/TrentSPalmer/flask_photo_scaling_app.git
synced 2025-02-18 13:40:55 -08:00
fix style app/auth/auth.py
This commit is contained in:
parent
cec0716bc3
commit
c8d06abbe2
@ -20,15 +20,25 @@ def two_factor_input():
|
|||||||
return redirect(url_for('proute.index'))
|
return redirect(url_for('proute.index'))
|
||||||
form = GetTotp()
|
form = GetTotp()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
if TOTP(contributor.totp_key).verify(int(form.totp_code.data), valid_window=5):
|
if TOTP(
|
||||||
|
contributor.totp_key,
|
||||||
|
).verify(int(form.totp_code.data), valid_window=5):
|
||||||
login_user(contributor, remember=session['remember_me'])
|
login_user(contributor, remember=session['remember_me'])
|
||||||
flash("Congratulations, you are now logged in!")
|
flash("Congratulations, you are now logged in!")
|
||||||
return redirect(url_for('proute.index'))
|
return redirect(url_for('proute.index'))
|
||||||
else:
|
else:
|
||||||
flash("Oops, the pin was wrong")
|
flash("Oops, the pin was wrong")
|
||||||
form.totp_code.data = None
|
form.totp_code.data = None
|
||||||
return render_template('two_factor_input.html', form=form, inst="Code was wrong, try again?")
|
return render_template(
|
||||||
return render_template('two_factor_input.html', form=form, inst="Enter Auth Code")
|
'two_factor_input.html',
|
||||||
|
form=form,
|
||||||
|
inst="Code was wrong, try again?",
|
||||||
|
)
|
||||||
|
return render_template(
|
||||||
|
'two_factor_input.html',
|
||||||
|
form=form,
|
||||||
|
inst="Enter Auth Code",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@auths.route("/login", methods=["GET", "POST"])
|
@auths.route("/login", methods=["GET", "POST"])
|
||||||
@ -37,9 +47,14 @@ def login():
|
|||||||
return redirect(url_for('proute.index'))
|
return redirect(url_for('proute.index'))
|
||||||
form = LoginForm()
|
form = LoginForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
contributor_by_name = Contributor.query.filter_by(name=form.username.data).first()
|
contributor_by_name = Contributor.query.filter_by(
|
||||||
contributor_by_email = Contributor.query.filter_by(email=form.email.data).first()
|
name=form.username.data,
|
||||||
if contributor_by_name is not None and contributor_by_name.check_password(form.password.data):
|
).first()
|
||||||
|
contributor_by_email = Contributor.query.filter_by(
|
||||||
|
email=form.email.data,
|
||||||
|
).first()
|
||||||
|
cbn, cbe = contributor_by_name, contributor_by_email
|
||||||
|
if cbn is not None and cbn.check_password(form.password.data):
|
||||||
if contributor_by_name.use_totp:
|
if contributor_by_name.use_totp:
|
||||||
session['id'] = contributor_by_name.id
|
session['id'] = contributor_by_name.id
|
||||||
session['remember_me'] = form.remember_me.data
|
session['remember_me'] = form.remember_me.data
|
||||||
@ -48,13 +63,16 @@ def login():
|
|||||||
login_user(contributor_by_name, remember=form.remember_me.data)
|
login_user(contributor_by_name, remember=form.remember_me.data)
|
||||||
flash("Congratulations, you are now logged in!")
|
flash("Congratulations, you are now logged in!")
|
||||||
return redirect(url_for('proute.index'))
|
return redirect(url_for('proute.index'))
|
||||||
elif contributor_by_email is not None and contributor_by_email.check_password(form.password.data):
|
elif cbe is not None and cbe.check_password(form.password.data):
|
||||||
if contributor_by_email.use_totp:
|
if contributor_by_email.use_totp:
|
||||||
session['id'] = contributor_by_email.id
|
session['id'] = contributor_by_email.id
|
||||||
session['remember_me'] = form.remember_me.data
|
session['remember_me'] = form.remember_me.data
|
||||||
return redirect(url_for('auths.two_factor_input'))
|
return redirect(url_for('auths.two_factor_input'))
|
||||||
else:
|
else:
|
||||||
login_user(contributor_by_email, remember=form.remember_me.data)
|
login_user(
|
||||||
|
contributor_by_email,
|
||||||
|
remember=form.remember_me.data,
|
||||||
|
)
|
||||||
flash("Congratulations, you are now logged in!")
|
flash("Congratulations, you are now logged in!")
|
||||||
return redirect(url_for('proute.index'))
|
return redirect(url_for('proute.index'))
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user