diff --git a/cfp/forms.py b/cfp/forms.py index ab15e33..364102f 100644 --- a/cfp/forms.py +++ b/cfp/forms.py @@ -52,7 +52,7 @@ class CreateUserForm(forms.ModelForm): user = User(first_name=self.cleaned_data.get('first_name'), last_name=self.cleaned_data.get('last_name')) username = slugify(user.get_full_name()) if User.objects.filter(username=username).exists(): - raise forms.ValidationError(_('An user with that firstname and lastname already exists.')) + raise forms.ValidationError(_('An user with that firstname and that lastname already exists.')) def clean_email(self): email = self.cleaned_data.get('email') diff --git a/locale/fr/LC_MESSAGES/django.mo b/locale/fr/LC_MESSAGES/django.mo index f2a230b..111f7dc 100644 Binary files a/locale/fr/LC_MESSAGES/django.mo and b/locale/fr/LC_MESSAGES/django.mo differ diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index a8e55ba..294880a 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-07-30 19:44+0000\n" +"POT-Creation-Date: 2017-07-31 21:38+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -288,7 +288,11 @@ msgstr "%(name)s a été ajouté aux participants" msgid "%(name)s is already a participant" msgstr "%(name)s est déjà participant" -#: cfp/forms.py:47 +#: cfp/forms.py:55 +msgid "An user with that firstname and that lastname already exists." +msgstr "Un utilisateur avec ce prénom et ce nom existe déjà." + +#: cfp/forms.py:60 msgid "A user with that email already exists." msgstr "Un utilisateur avec cet email existe déjà." @@ -448,7 +452,7 @@ msgid "An email has been sent to you with those URLs" msgstr "Un mail vous a été envoyé avec toutes les URLs" #: cfp/templates/cfp/propose.html:22 cfp/templates/cfp/speaker.html:21 -#: cfp/templates/cfp/staff/conference.html:13 +#: cfp/templates/cfp/staff/conference.html:14 #: cfp/templates/cfp/staff/create_user.html:13 msgid "Save" msgstr "Envoyer" @@ -462,6 +466,7 @@ msgstr "Conférence" msgid "Please select a category." msgstr "Veuillez sélectionner une catégorie." +#: cfp/templates/cfp/staff/conference.html:13 #: cfp/templates/cfp/staff/create_user.html:8 msgid "Add a new user" msgstr "Ajouter un nouvel utilisateur" @@ -745,11 +750,11 @@ msgstr "Vote mis à jour" msgid "Decision taken in account" msgstr "Décision enregistrée" -#: cfp/views.py:208 +#: cfp/views.py:214 msgid "Modifications successfully saved." msgstr "Modification enregistrée avec succès." -#: cfp/views.py:222 +#: cfp/views.py:228 msgid "User created successfully." msgstr "Utilisateur créé avec succès." @@ -830,11 +835,11 @@ msgstr "Certains exposés ne sont pas encore planifiés." msgid "No rooms." msgstr "Aucune salle." -#: ponyconf/settings.py:145 +#: ponyconf/settings.py:147 msgid "English" msgstr "Anglais" -#: ponyconf/settings.py:146 +#: ponyconf/settings.py:148 msgid "French" msgstr "Français" @@ -852,6 +857,7 @@ msgstr "Staff" #: ponyconf/templates/base.html:50 #: ponyconf/templates/registration/login.html:10 +#: ponyconf/templates/registration/login.html:23 msgid "Login" msgstr "Se connecter" @@ -859,10 +865,18 @@ msgstr "Se connecter" msgid "Powered by" msgstr "Propulsé par" +#: ponyconf/templates/registration/login.html:24 +msgid "Forgot password?" +msgstr "Mot de passe oublié ?" + #: ponyconf/templates/registration/password_change_form.html:9 msgid "Password Change" msgstr "Changement de mot de passe" +#: ponyconf/urls.py:27 +msgid "Email address" +msgstr "" + #: proposals/forms.py:46 msgid "Should be less than 255 characters" msgstr "Texte court, moins de 255 caractères" diff --git a/ponyconf/backends.py b/ponyconf/backends.py new file mode 100644 index 0000000..29d3dea --- /dev/null +++ b/ponyconf/backends.py @@ -0,0 +1,16 @@ +from django.contrib.auth import get_user_model +from django.contrib.auth.backends import ModelBackend + + +class EmailBackend(ModelBackend): + def authenticate(self, request, username=None, password=None, **kwargs): + if not username: + return None + UserModel = get_user_model() + try: + user = UserModel._default_manager.get(email__iexact=username) + except UserModel.DoesNotExist: + UserModel().set_password(password) # https://code.djangoproject.com/ticket/20760 + else: + if user.check_password(password) and self.user_can_authenticate(user): + return user diff --git a/ponyconf/settings.py b/ponyconf/settings.py index 9f546e3..ce22f05 100644 --- a/ponyconf/settings.py +++ b/ponyconf/settings.py @@ -210,7 +210,10 @@ SELECT2_JS = 'select2/dist/js/select2.min.js' SELECT2_CSS = 'select2/dist/css/select2.min.css' SELECT2_I18N_PATH = 'select2/dist/js/i18n' -#AUTHENTICATION_BACKENDS = ['yeouia.backends.YummyEmailOrUsernameInsensitiveAuth'] +AUTHENTICATION_BACKENDS = [ + 'django.contrib.auth.backends.ModelBackend', + 'ponyconf.backends.EmailBackend', +] LOGOUT_REDIRECT_URL = 'home' CRISPY_TEMPLATE_PACK='bootstrap3' diff --git a/ponyconf/templates/registration/login.html b/ponyconf/templates/registration/login.html index 2293b3e..33a3bde 100644 --- a/ponyconf/templates/registration/login.html +++ b/ponyconf/templates/registration/login.html @@ -17,11 +17,11 @@ {% bootstrap_form_errors form layout="horizontal" %}
{% csrf_token %} - {% bootstrap_field form.username layout="horizontal" placeholder="Nom d’utilisateur, e-mail ou numéro d’adhérent" %} + {% bootstrap_field form.username layout="horizontal" %} {% bootstrap_field form.password layout="horizontal" %} {% buttons layout="horizontal" %} - - Mot de passe oublié ? + + {% trans "Forgot password?" %} {% endbuttons %}
diff --git a/ponyconf/urls.py b/ponyconf/urls.py index a17e402..12018a8 100644 --- a/ponyconf/urls.py +++ b/ponyconf/urls.py @@ -15,10 +15,24 @@ Including another URLconf """ from django.conf.urls import include, url from django.contrib import admin +from django.contrib.auth.views import LoginView +from django.contrib.auth.forms import AuthenticationForm +from django.utils.translation import ugettext_lazy as _ + + +class EmailAuthenticationForm(AuthenticationForm): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['username'].label = _('Email address') + + +class EmailLoginView(LoginView): + authentication_form = EmailAuthenticationForm urlpatterns = [ url(r'^admin/', admin.site.urls), + url(r'accounts/login/', EmailLoginView.as_view()), url(r'accounts/', include('django.contrib.auth.urls')), url(r'^', include('cfp.urls')), ]