From ac5be70c60f7812fca86e3dc8fdac42cc3e120a4 Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Tue, 11 Jul 2023 18:12:06 +0530 Subject: [PATCH] Fix issues found while testing login pages. #6295 --- .../mfa/templates/mfa/register.html | 1 - .../mfa/templates/mfa/validate.html | 1 - web/pgadmin/browser/__init__.py | 17 +++++++++++++---- web/pgadmin/static/js/Dialogs/index.jsx | 4 +++- .../static/js/SecurityPages/LoginPage.jsx | 2 +- .../templates/security/forgot_password.html | 1 - web/pgadmin/templates/security/login_user.html | 1 - web/pgadmin/templates/security/render_page.html | 1 + .../templates/security/reset_password.html | 1 - 9 files changed, 18 insertions(+), 11 deletions(-) diff --git a/web/pgadmin/authenticate/mfa/templates/mfa/register.html b/web/pgadmin/authenticate/mfa/templates/mfa/register.html index 7be69472e..78cef22c8 100644 --- a/web/pgadmin/authenticate/mfa/templates/mfa/register.html +++ b/web/pgadmin/authenticate/mfa/templates/mfa/register.html @@ -7,4 +7,3 @@ 'errorMessage': error_message, } %} {% extends "security/render_page.html" %} -{% block title %}{{ _('Authentication Registration') }}{% endblock %} diff --git a/web/pgadmin/authenticate/mfa/templates/mfa/validate.html b/web/pgadmin/authenticate/mfa/templates/mfa/validate.html index 49361104f..3108063bf 100644 --- a/web/pgadmin/authenticate/mfa/templates/mfa/validate.html +++ b/web/pgadmin/authenticate/mfa/templates/mfa/validate.html @@ -8,4 +8,3 @@ 'csrfToken': csrf_token() } %} {% extends "security/render_page.html" %} -{% block title %}{{ _('Authentication') }}{% endblock %} diff --git a/web/pgadmin/browser/__init__.py b/web/pgadmin/browser/__init__.py index 6df1e1c93..d3e489e56 100644 --- a/web/pgadmin/browser/__init__.py +++ b/web/pgadmin/browser/__init__.py @@ -18,7 +18,8 @@ from smtplib import SMTPConnectError, SMTPResponseException, \ from socket import error as SOCKETErrorException from urllib.request import urlopen from pgadmin.utils.constants import KEY_RING_SERVICE_NAME, \ - KEY_RING_USERNAME_FORMAT, KEY_RING_DESKTOP_USER, KEY_RING_TUNNEL_FORMAT + KEY_RING_USERNAME_FORMAT, KEY_RING_DESKTOP_USER, KEY_RING_TUNNEL_FORMAT, \ + MessageType import time @@ -46,7 +47,8 @@ from pgadmin.authenticate import get_logout_url from pgadmin.authenticate.mfa.utils import mfa_required, is_mfa_enabled from pgadmin.settings import get_setting, store_setting from pgadmin.utils import PgAdminModule -from pgadmin.utils.ajax import make_json_response +from pgadmin.utils.ajax import make_json_response, internal_server_error, \ + bad_request from pgadmin.utils.csrf import pgCSRFProtect from pgadmin.utils.preferences import Preferences from pgadmin.utils.menu import MenuItem @@ -1103,11 +1105,14 @@ if hasattr(config, 'SECURITY_CHANGEABLE') and config.SECURITY_CHANGEABLE: return redirect(get_url(_security.post_change_view) or get_url(_security.post_login_view)) - else: + 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') + ) # Only register route if SECURITY_RECOVERABLE is set to True if hasattr(config, 'SECURITY_RECOVERABLE') and config.SECURITY_RECOVERABLE: @@ -1194,6 +1199,10 @@ if hasattr(config, 'SECURITY_RECOVERABLE') and config.SECURITY_RECOVERABLE: if request.get_json(silent=True) and not has_error: return default_render_json(form, include_user=False) + for errors in form.errors.values(): + for error in errors: + flash(error, MessageType.WARNING) + return _security.render_template( config_value('FORGOT_PASSWORD_TEMPLATE'), forgot_password_form=form, diff --git a/web/pgadmin/static/js/Dialogs/index.jsx b/web/pgadmin/static/js/Dialogs/index.jsx index b74c4101c..70b98d506 100644 --- a/web/pgadmin/static/js/Dialogs/index.jsx +++ b/web/pgadmin/static/js/Dialogs/index.jsx @@ -325,7 +325,9 @@ export function showChangeUserPassword(url) { url: url, data: formData, }).then((res)=>{ - resolve(res); + resolve(res.data.info); + onClose(); + Notify.success(res.data.info); }).catch((err)=>{ reject(err); }); diff --git a/web/pgadmin/static/js/SecurityPages/LoginPage.jsx b/web/pgadmin/static/js/SecurityPages/LoginPage.jsx index 240421243..d286f7410 100644 --- a/web/pgadmin/static/js/SecurityPages/LoginPage.jsx +++ b/web/pgadmin/static/js/SecurityPages/LoginPage.jsx @@ -36,7 +36,7 @@ export default function LoginPage({userLanguage, langOptions, forgotPassUrl, csr {gettext('Forgotten your password?')} onTextChange('language', v.target.value)} /> - {gettext('Login')} + {gettext('Login')} } {authSources?.includes?.(authSourcesEnum.OAUTH2) && diff --git a/web/pgadmin/templates/security/forgot_password.html b/web/pgadmin/templates/security/forgot_password.html index 79dc4b9d3..59ebe4e1f 100644 --- a/web/pgadmin/templates/security/forgot_password.html +++ b/web/pgadmin/templates/security/forgot_password.html @@ -4,5 +4,4 @@ 'csrfToken': csrf_token(), } %} {% extends "security/render_page.html" %} -{% block title %}{{ _('Recover Password') }}{% endblock %} diff --git a/web/pgadmin/templates/security/login_user.html b/web/pgadmin/templates/security/login_user.html index 36ec3407f..f3d716d10 100644 --- a/web/pgadmin/templates/security/login_user.html +++ b/web/pgadmin/templates/security/login_user.html @@ -19,4 +19,3 @@ 'loginBanner': config.LOGIN_BANNER|safe } %} {% extends "security/render_page.html" %} -{% block title %}{{ _('Login') }}{% endblock %} diff --git a/web/pgadmin/templates/security/render_page.html b/web/pgadmin/templates/security/render_page.html index 0689ef63d..43d6cc38e 100644 --- a/web/pgadmin/templates/security/render_page.html +++ b/web/pgadmin/templates/security/render_page.html @@ -1,4 +1,5 @@ {% extends "base.html" %} +{% block title %}{{ config.APP_NAME }}{% endblock %} {% set other_props = { 'messages': get_flashed_messages(with_categories=true) } %} diff --git a/web/pgadmin/templates/security/reset_password.html b/web/pgadmin/templates/security/reset_password.html index ba135225d..ba448feeb 100644 --- a/web/pgadmin/templates/security/reset_password.html +++ b/web/pgadmin/templates/security/reset_password.html @@ -4,5 +4,4 @@ 'csrfToken': csrf_token(), } %} {% extends "security/render_page.html" %} -{% block title %}{{ _('Reset Password') }}{% endblock %}