From 73d9aca46dec3d1b2130a3fd7a148386adc301b8 Mon Sep 17 00:00:00 2001 From: Serghei MIHAI Date: Wed, 17 Dec 2014 11:13:48 +0100 Subject: [PATCH 2/2] on user multiple accounts propose to log in with one of them or create a new account --- authentic2/registration_backend/forms.py | 12 ---------- authentic2/registration_backend/urls.py | 5 ++++- authentic2/registration_backend/views.py | 26 +++++++++------------- .../templates/registration/login_choices.html | 7 ++++++ 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/authentic2/registration_backend/forms.py b/authentic2/registration_backend/forms.py index e1df4d6..1fdac90 100644 --- a/authentic2/registration_backend/forms.py +++ b/authentic2/registration_backend/forms.py @@ -175,18 +175,6 @@ class RegistrationCompletionForm(forms.UserAttributeFormMixin, Form): new_user.set_password(kwargs['password1']) new_user.save() - registration_id, created = models.Attribute.objects.get_or_create(label=registration_id_name, - name=registration_id_name, - kind='string', - asked_on_registration=False, - user_visible=False) - registration_id.set_value(new_user, kwargs[registration_id_name]) - - attributes = models.Attribute.objects.filter( - asked_on_registration=True) - if attributes: - for attribute in attributes: - attribute.set_value(new_user, kwargs[attribute.name]) if app_settings.A2_REGISTRATION_GROUPS: groups = [] for name in app_settings.A2_REGISTRATION_GROUPS: diff --git a/authentic2/registration_backend/urls.py b/authentic2/registration_backend/urls.py index 49ae5c9..93fafd1 100644 --- a/authentic2/registration_backend/urls.py +++ b/authentic2/registration_backend/urls.py @@ -5,7 +5,7 @@ from django.views.generic.base import TemplateView from django.contrib.auth.decorators import login_required from .views import RegistrationView, RegistrationCompletionView, DeleteView,\ - LoginView + LoginView, RegistrationCreateView urlpatterns = patterns('', url(r'^activate/expired/$', @@ -14,6 +14,9 @@ urlpatterns = patterns('', url(r'^activate/(?P[\w:-]+)/$', RegistrationCompletionView.as_view(), name='registration_activate'), + url(r'^create/(?P[\w:-]+)/$', + RegistrationCreateView.as_view(), + name='registration_create'), url(r'^activate/(?P[\w:-]+)/(?P\w+)$', LoginView.as_view(), name='registration_login'), diff --git a/authentic2/registration_backend/views.py b/authentic2/registration_backend/views.py index d81ac9a..ae657fe 100644 --- a/authentic2/registration_backend/views.py +++ b/authentic2/registration_backend/views.py @@ -65,7 +65,6 @@ class RegistrationCompletionView(FormView): @valid_token def get(self, request, *args, **kwargs): if app_settings.A2_REGISTRATION_EMAIL_IS_UNIQUE: - print "UNIQUE???" try: user = User.objects.get(email__iexact=kwargs['email']) except User.DoesNotExist: @@ -74,20 +73,11 @@ class RegistrationCompletionView(FormView): else: user_accounts = User.objects.filter(email__iexact=kwargs['email']) if user_accounts: - has_active_account = False - for user in user_accounts: - registration_id = kwargs[registration_id_name] - if models.AttributeValue.objects.with_owner(user).filter(attribute__label=registration_id_name, - content='"%s"' % registration_id).exists(): - has_active_account = True - if has_active_account: - logout(request) - context = kwargs.copy() - context.update({'accounts': user_accounts}) - self.template_name = 'registration/login_choices.html' - return self.render_to_response(context) - else: - return super(RegistrationCompletionView, self).get(request, *args, **kwargs) + logout(request) + context = kwargs.copy() + context.update({'accounts': user_accounts}) + self.template_name = 'registration/login_choices.html' + return self.render_to_response(context) else: return super(RegistrationCompletionView, self).get(request, *args, **kwargs) @@ -104,6 +94,12 @@ class RegistrationCompletionView(FormView): else: return self.form_invalid(form) +class RegistrationCreateView(RegistrationCompletionView): + + @valid_token + def get(self, request, *args, **kwargs): + return super(RegistrationCompletionView, self).get(request, *args, **kwargs) + class DeleteView(TemplateView): def get(self, request, *args, **kwargs): next_url = request.build_absolute_uri(request.META.get('HTTP_REFERER')\ diff --git a/authentic2/templates/registration/login_choices.html b/authentic2/templates/registration/login_choices.html index a0cf643..e52243f 100644 --- a/authentic2/templates/registration/login_choices.html +++ b/authentic2/templates/registration/login_choices.html @@ -25,4 +25,11 @@ {% endfor %} +

+ {% trans "or" %} + + {% trans "create a new account" %} + +

+ {% endblock %} -- 2.1.4