mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Merge pull request #3926 from alphagov/sign-in-bug
ensure user details are always in the session after entering password
This commit is contained in:
@@ -33,24 +33,31 @@ def sign_in():
|
||||
form.email_address.data, form.password.data
|
||||
)
|
||||
|
||||
if user and user.state == 'pending':
|
||||
return redirect(url_for('main.resend_email_verification', next=redirect_url))
|
||||
if user:
|
||||
# add user to session to mark us as in the process of signing the user in
|
||||
session['user_details'] = {"email": user.email_address, "id": user.id}
|
||||
|
||||
if user and session.get('invited_user_id'):
|
||||
invited_user = InvitedUser.from_session()
|
||||
if user.email_address.lower() != invited_user.email_address.lower():
|
||||
flash("You cannot accept an invite for another person.")
|
||||
session.pop('invited_user_id', None)
|
||||
abort(403)
|
||||
else:
|
||||
invited_user.accept_invite()
|
||||
if user and user.sign_in():
|
||||
if user.sms_auth:
|
||||
return redirect(url_for('.two_factor_sms', next=redirect_url))
|
||||
if user.email_auth:
|
||||
return redirect(url_for('.two_factor_email_sent', next=redirect_url))
|
||||
if user.webauthn_auth:
|
||||
return redirect(url_for('.two_factor_webauthn', next=redirect_url))
|
||||
if user.state == 'pending':
|
||||
return redirect(url_for('main.resend_email_verification', next=redirect_url))
|
||||
|
||||
if user.is_active:
|
||||
if session.get('invited_user_id'):
|
||||
invited_user = InvitedUser.from_session()
|
||||
if user.email_address.lower() != invited_user.email_address.lower():
|
||||
flash("You cannot accept an invite for another person.")
|
||||
session.pop('invited_user_id', None)
|
||||
abort(403)
|
||||
else:
|
||||
invited_user.accept_invite()
|
||||
|
||||
user.send_login_code()
|
||||
|
||||
if user.sms_auth:
|
||||
return redirect(url_for('.two_factor_sms', next=redirect_url))
|
||||
if user.email_auth:
|
||||
return redirect(url_for('.two_factor_email_sent', next=redirect_url))
|
||||
if user.webauthn_auth:
|
||||
return redirect(url_for('.two_factor_webauthn', next=redirect_url))
|
||||
|
||||
# Vague error message for login in case of user not known, locked, inactive or password not verified
|
||||
flash(Markup(
|
||||
|
||||
@@ -142,20 +142,12 @@ class User(JSONModel, UserMixin):
|
||||
login_user(self)
|
||||
session['user_id'] = self.id
|
||||
|
||||
def sign_in(self):
|
||||
|
||||
session['user_details'] = {"email": self.email_address, "id": self.id}
|
||||
|
||||
if not self.is_active:
|
||||
return False
|
||||
|
||||
def send_login_code(self):
|
||||
if self.email_auth:
|
||||
user_api_client.send_verify_code(self.id, 'email', None, request.args.get('next'))
|
||||
if self.sms_auth:
|
||||
user_api_client.send_verify_code(self.id, 'sms', self.mobile_number)
|
||||
|
||||
return True
|
||||
|
||||
def sign_out(self):
|
||||
session.clear()
|
||||
# Update the db so the server also knows the user is logged out.
|
||||
|
||||
Reference in New Issue
Block a user