mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
ensure user details are always in the session after entering password
We signal that we're mid-way through the sign-in flow by adding a `user_details` dict to the session. previously, we'd only put a user's details in the session in `User.sign_in`, just before sending any 2fa prompt and redirecting to the two factor pages. However, we found a bug where a user with no session (eg, using a fresh browser) tried to log in, but they had never clicked the link to validate their email address when registering. Their user's state was still in "pending", so we redirected to `main.resend_email_verification` as intended - however, they didn't have anything in the session and the resend page expected to get the email address to resend to out of that. To be safe, as soon as we've confirmed the user has entered their password correctly, lets save the session data at that point. That way any redirects will be fine.
This commit is contained in:
@@ -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