diff --git a/passbook/core/forms/authentication.py b/passbook/core/forms/authentication.py index b10c9c837..0e614a0a0 100644 --- a/passbook/core/forms/authentication.py +++ b/passbook/core/forms/authentication.py @@ -8,6 +8,7 @@ from django.utils.translation import gettext_lazy as _ from passbook.core.models import User from passbook.lib.config import CONFIG +from passbook.lib.utils.ui import human_list LOGGER = getLogger(__name__) @@ -15,13 +16,16 @@ class LoginForm(forms.Form): """Allow users to login""" title = _('Log in to your account') - uid_field = forms.CharField(widget=forms.TextInput(attrs={'placeholder': _('UID')})) + uid_field = forms.CharField() remember_me = forms.BooleanField(required=False) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - if CONFIG.y('passbook.uid_fields') == ['email']: + if CONFIG.y('passbook.uid_fields') == ['e-mail']: self.fields['uid_field'] = forms.EmailField() + self.fields['uid_field'].widget.attrs = { + 'placeholder': _(human_list([x.title() for x in CONFIG.y('passbook.uid_fields')])) + } def clean_uid_field(self): """Validate uid_field after EmailValidator if 'email' is the only selected uid_fields""" diff --git a/passbook/core/views/authentication.py b/passbook/core/views/authentication.py index 8ab2c39c8..0a0c3265b 100644 --- a/passbook/core/views/authentication.py +++ b/passbook/core/views/authentication.py @@ -52,6 +52,9 @@ class LoginView(UserPassesTestMixin, FormView): def get_user(self, uid_value) -> User: """Find user instance. Returns None if no user was found.""" for search_field in CONFIG.y('passbook.uid_fields'): + # Workaround for E-Mail -> email + if search_field == 'e-mail': + search_field = 'email' users = User.objects.filter(**{search_field: uid_value}) if users.exists(): LOGGER.debug("Found user %s with uid_field %s", users.first(), search_field) diff --git a/passbook/lib/default.yml b/passbook/lib/default.yml index cf2cb833b..d2bdb31cd 100644 --- a/passbook/lib/default.yml +++ b/passbook/lib/default.yml @@ -61,7 +61,7 @@ passbook: # Specify which fields can be used to authenticate. Can be any combination of `username` and `email` uid_fields: - username - - email + - e-mail # Factors to load factors: - passbook.core.auth.factors.backend diff --git a/passbook/lib/utils/ui.py b/passbook/lib/utils/ui.py new file mode 100644 index 000000000..0c7d1b710 --- /dev/null +++ b/passbook/lib/utils/ui.py @@ -0,0 +1,7 @@ +"""passbook UI utils""" + +def human_list(_list) -> str: + """Convert a list of items into 'a, b or c'""" + last_item = _list.pop() + result = ', '.join(_list) + return '%s or %s' % (result, last_item)