Skip to content

Commit bba3809

Browse files
author
Masaharu Hayashi
committed
fix
1 parent c883f2a commit bba3809

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

modules/invenio-accounts/invenio_accounts/forms.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,15 @@ def __init__(self, *args, **kwargs):
6565
"""
6666
super(LoginForm, self).__init__(*args, **kwargs)
6767
self.remember.data = False
68+
69+
def validate(self):
70+
"""Validate the form after trimming email and password fields."""
71+
if self.email.data:
72+
self.email.data = self.email.data.strip()
73+
self.email.data = self.email.data.strip('\u200b') # remove zero-width spaces
74+
if self.password.data:
75+
self.password.data = self.password.data.strip()
76+
self.password.data = self.password.data.strip('\u200b') # remove zero-width spaces
77+
return super(LoginForm, self).validate()
6878

6979
return LoginForm

modules/weko-accounts/weko_accounts/rest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ def post_v1(self, **kwargs):
116116
data = request.get_json()
117117
email = data['email']
118118
password = data['password']
119+
if email:
120+
email = email.strip()
121+
email = email.strip('\u200b') # remove zero-width spaces
122+
if password:
123+
password = password.strip()
124+
password = password.strip('\u200b') # remove zero-width spaces
119125

120126
# Check if user is already logged in
121127
if current_user.is_authenticated:

modules/weko-accounts/weko_accounts/views.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,12 @@ def confirm_user():
340340
shib_user = ShibUser(cache_val)
341341
account = request.form.get('WEKO_ATTR_ACCOUNT', None)
342342
password = request.form.get('WEKO_ATTR_PWD', None)
343+
if account:
344+
account = account.strip()
345+
account = account.strip('\u200b') # remove zero-width spaces
346+
if password:
347+
password = password.strip()
348+
password = password.strip('\u200b') # remove zero-width spaces
343349
if not shib_user.check_weko_user(account, password):
344350
if ams_login:
345351
return _redirect_method(True, ams_error=_('There is no user information.'))

0 commit comments

Comments
 (0)