MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / reset_password

Function reset_password

web/pgadmin/browser/__init__.py:1064–1131  ·  view source on GitHub ↗

View function that handles a reset password request.

(token)

Source from the content-addressed store, hash-verified

1062 @pgCSRFProtect.exempt
1063 @anonymous_user_required
1064 def reset_password(token):
1065 """View function that handles a reset password request."""
1066 expired, invalid, user = reset_password_token_status(token)
1067
1068 if invalid:
1069 do_flash(*get_message('INVALID_RESET_PASSWORD_TOKEN'))
1070 if expired:
1071 do_flash(*get_message('PASSWORD_RESET_EXPIRED', email=user.email,
1072 within=_security.reset_password_within))
1073 if invalid or expired:
1074 return redirect(url_for('browser.forgot_password'))
1075 has_error = False
1076 form_class = _security.forms.get('reset_password_form').cls
1077 form = form_class(request.form) if request.form else form_class()
1078
1079 form.user = user
1080
1081 if form.validate_on_submit():
1082 try:
1083 update_password(user, form.password.data)
1084 except SOCKETErrorException as e:
1085 # Handle socket errors which are not covered by SMTPExceptions.
1086 logging.exception(str(e), exc_info=True)
1087 flash(gettext(SMTP_SOCKET_ERROR).format(e),
1088 MessageType.ERROR)
1089 has_error = True
1090 except (SMTPConnectError, SMTPResponseException,
1091 SMTPServerDisconnected, SMTPDataError, SMTPHeloError,
1092 SMTPException, SMTPAuthenticationError, SMTPSenderRefused,
1093 SMTPRecipientsRefused) as e:
1094
1095 # Handle smtp specific exceptions.
1096 logging.exception(str(e), exc_info=True)
1097 flash(gettext(SMTP_ERROR).format(e),
1098 MessageType.ERROR)
1099 has_error = True
1100 except Exception as e:
1101 # Handle other exceptions.
1102 logging.exception(str(e), exc_info=True)
1103 flash(gettext(PASS_ERROR).format(e),
1104 MessageType.ERROR)
1105 has_error = True
1106
1107 if not has_error:
1108 view_commit()
1109 auth_obj = AuthSourceManager(form, [INTERNAL])
1110 session['_auth_source_manager_obj'] = auth_obj.as_dict()
1111
1112 if user.login_attempts >= config.MAX_LOGIN_ATTEMPTS > 0:
1113 flash(gettext('You successfully reset your password but'
1114 ' your account is locked. Please contact '
1115 'the Administrator.'),
1116 MessageType.WARNING)
1117 return redirect(get_post_logout_redirect())
1118 do_flash(*get_message('PASSWORD_RESET'))
1119 login_user(user)
1120 auth_obj = AuthSourceManager(form, [INTERNAL])
1121 session['auth_source_manager'] = auth_obj.as_dict()

Callers

nothing calls this directly

Calls 4

as_dictMethod · 0.95
AuthSourceManagerClass · 0.90
gettextFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected