Skip to content

Commit

Permalink
Fix an issue where user is not able to change the password when SMTP …
Browse files Browse the repository at this point in the history
…is not configured. #6274.

Fix an issue where changing the password shows success but the new password is not working. #6730.
  • Loading branch information
adityatoshniwal authored Sep 12, 2023
1 parent cfc338c commit 2f5fb6a
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions web/pgadmin/browser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
from flask_gravatar import Gravatar
from flask_login import current_user, login_required
from flask_login.utils import login_url
from flask_security.changeable import change_user_password
from flask_security.changeable import change_user_password, \
send_password_changed_notice
from flask_security.decorators import anonymous_user_required
from flask_security.recoverable import reset_password_token_status, \
generate_reset_password_token, update_password
Expand Down Expand Up @@ -1071,44 +1072,39 @@ def change_password():
}
elif req_json:
form = form_class(MultiDict(req_json))
if form.validate_on_submit():
if form.validate():
errormsg = None
try:
change_user_password(current_user._get_current_object(),
form.new_password.data,
autologin=False)
except SOCKETErrorException as e:
# Handle socket errors which are not covered by
# SMTPExceptions.
logging.exception(str(e), exc_info=True)
errormsg = gettext(SMTP_SOCKET_ERROR).format(e)
except (SMTPConnectError, SMTPResponseException,
SMTPServerDisconnected, SMTPDataError, SMTPHeloError,
SMTPException, SMTPAuthenticationError,
SMTPSenderRefused, SMTPRecipientsRefused) as ex:
# Handle smtp specific exceptions.
logging.exception(str(ex), exc_info=True)
errormsg = gettext(SMTP_ERROR).format(ex)
notify=False,
autologin=True)
try:
send_password_changed_notice(
current_user._get_current_object())
except Exception as _:
# No need to throw error if failed in sending email
pass
except Exception as e:
# Handle other exceptions.
logging.exception(str(e), exc_info=True)
errormsg = gettext(PASS_ERROR).format(e)

if request.get_json(silent=True) is None and errormsg is None:
if request.get_json(silent=True) is not None and \
errormsg is None:
after_this_request(view_commit)
old_key = get_crypt_key()[1]
set_crypt_key(form.new_password.data, False)

from pgadmin.browser.server_groups.servers.utils \
import reencrpyt_server_passwords
reencrpyt_server_passwords(
current_user.id, old_key, form.new_password.data)

return redirect(get_url(_security.post_change_view) or
get_url(_security.post_login_view))
elif errormsg is not None:
return internal_server_error(errormsg)
else:
return bad_request(list(form.errors.values())[0][0])

return make_json_response(
success=1,
info=gettext('pgAdmin user password changed successfully')
Expand Down

0 comments on commit 2f5fb6a

Please sign in to comment.