From 2b6fab9461ce51ce630f8d7f6fbfe9a5460f0b66 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Thu, 9 Jun 2022 13:06:20 -0400 Subject: [PATCH] It's happening! Seems to work. I do think we need some mechanism to throttle the speed of attempts to prevent brute force. This would be a separate PR. modified: models/user.py modified: templates/join-or-log-in.j2 modified: templates/verification-challenge.j2 modified: views/authentication.py --- make_post_sell/models/user.py | 3 +- make_post_sell/templates/join-or-log-in.j2 | 2 +- .../templates/verification-challenge.j2 | 12 ++--- make_post_sell/views/authentication.py | 52 +++++++++---------- 4 files changed, 34 insertions(+), 35 deletions(-) diff --git a/make_post_sell/models/user.py b/make_post_sell/models/user.py index 18a5816..a8cfbba 100644 --- a/make_post_sell/models/user.py +++ b/make_post_sell/models/user.py @@ -128,8 +128,7 @@ class User(RBase, Base): stored_hash.encode("utf-8"), ).decode("utf-8") - log.info("new_hash={} stored_hash={}".format(new_hash, stored_hash)) - print("blah") + #log.info("new_hash={} stored_hash={}".format(new_hash, stored_hash)) if new_hash == stored_hash: return True diff --git a/make_post_sell/templates/join-or-log-in.j2 b/make_post_sell/templates/join-or-log-in.j2 index e025610..5b26aa5 100644 --- a/make_post_sell/templates/join-or-log-in.j2 +++ b/make_post_sell/templates/join-or-log-in.j2 @@ -30,7 +30,7 @@

- + {% if return_to %} diff --git a/make_post_sell/templates/verification-challenge.j2 b/make_post_sell/templates/verification-challenge.j2 index 26ad92e..30e20c2 100644 --- a/make_post_sell/templates/verification-challenge.j2 +++ b/make_post_sell/templates/verification-challenge.j2 @@ -3,11 +3,10 @@
diff --git a/make_post_sell/views/authentication.py b/make_post_sell/views/authentication.py index 08b59af..eeb8146 100644 --- a/make_post_sell/views/authentication.py +++ b/make_post_sell/views/authentication.py @@ -107,38 +107,38 @@ def verification_challenge(request): # get or create a User object from the posted email. user = get_or_create_user_by_email(request.dbsession, email) - print("blah33") - print(raw_otp) + print(request.params) - if raw_otp and user.check_password(raw_otp): - # success: the user was verified. - user.verified = True - name = "" - if user.full_name: - name = user.name - msg = ("Welcome {}".format(name), "success") - request.session["authenticated_user_id"] = str(user.id) - request.session.flash(msg) + if "submit" in request.params: + if raw_otp and user.check_password(raw_otp): + # success: the user was verified. + user.verified = True + name = "" + if user.full_name: + name = user.name + msg = ("Welcome {}".format(name), "success") + request.session["authenticated_user_id"] = str(user.id) + request.session.flash(msg) - # merge any products in the session cart - # into user's main active cart. - user.active_cart.merge_in_cart(request.active_cart) + # merge any products in the session cart + # into user's main active cart. + user.active_cart.merge_in_cart(request.active_cart) - # make session cart match user's active cart. - request.session["active_cart_id"] = str(user.active_cart.id) + # make session cart match user's active cart. + request.session["active_cart_id"] = str(user.active_cart.id) - # delete old session only cart. - request.dbsession.delete(request.active_cart) + # delete old session only cart. + request.dbsession.delete(request.active_cart) - # save user and user's active cart. - request.dbsession.add(user) - request.dbsession.add(user.active_cart) - request.dbsession.flush() - return HTTPFound(return_to) + # save user and user's active cart. + request.dbsession.add(user) + request.dbsession.add(user.active_cart) + request.dbsession.flush() + return HTTPFound(return_to) - else: - msg = ("Invalid Verification Code", "error") - request.session.flash(msg) + else: + msg = ("Invalid Verification Code", "error") + request.session.flash(msg) return { "title": "Please Enter Verification Code",