0002-on-user-multiple-accounts-propose-to-log-in-with-one.patch
authentic2/registration_backend/forms.py | ||
---|---|---|
175 | 175 |
new_user.set_password(kwargs['password1']) |
176 | 176 |
new_user.save() |
177 | 177 | |
178 |
registration_id, created = models.Attribute.objects.get_or_create(label=registration_id_name, |
|
179 |
name=registration_id_name, |
|
180 |
kind='string', |
|
181 |
asked_on_registration=False, |
|
182 |
user_visible=False) |
|
183 |
registration_id.set_value(new_user, kwargs[registration_id_name]) |
|
184 | ||
185 |
attributes = models.Attribute.objects.filter( |
|
186 |
asked_on_registration=True) |
|
187 |
if attributes: |
|
188 |
for attribute in attributes: |
|
189 |
attribute.set_value(new_user, kwargs[attribute.name]) |
|
190 | 178 |
if app_settings.A2_REGISTRATION_GROUPS: |
191 | 179 |
groups = [] |
192 | 180 |
for name in app_settings.A2_REGISTRATION_GROUPS: |
authentic2/registration_backend/urls.py | ||
---|---|---|
5 | 5 |
from django.contrib.auth.decorators import login_required |
6 | 6 | |
7 | 7 |
from .views import RegistrationView, RegistrationCompletionView, DeleteView,\ |
8 |
LoginView |
|
8 |
LoginView, RegistrationCreateView
|
|
9 | 9 | |
10 | 10 |
urlpatterns = patterns('', |
11 | 11 |
url(r'^activate/expired/$', |
... | ... | |
14 | 14 |
url(r'^activate/(?P<registration_token>[\w:-]+)/$', |
15 | 15 |
RegistrationCompletionView.as_view(), |
16 | 16 |
name='registration_activate'), |
17 |
url(r'^create/(?P<registration_token>[\w:-]+)/$', |
|
18 |
RegistrationCreateView.as_view(), |
|
19 |
name='registration_create'), |
|
17 | 20 |
url(r'^activate/(?P<registration_token>[\w:-]+)/(?P<username>\w+)$', |
18 | 21 |
LoginView.as_view(), |
19 | 22 |
name='registration_login'), |
authentic2/registration_backend/views.py | ||
---|---|---|
65 | 65 |
@valid_token |
66 | 66 |
def get(self, request, *args, **kwargs): |
67 | 67 |
if app_settings.A2_REGISTRATION_EMAIL_IS_UNIQUE: |
68 |
print "UNIQUE???" |
|
69 | 68 |
try: |
70 | 69 |
user = User.objects.get(email__iexact=kwargs['email']) |
71 | 70 |
except User.DoesNotExist: |
... | ... | |
74 | 73 |
else: |
75 | 74 |
user_accounts = User.objects.filter(email__iexact=kwargs['email']) |
76 | 75 |
if user_accounts: |
77 |
has_active_account = False |
|
78 |
for user in user_accounts: |
|
79 |
registration_id = kwargs[registration_id_name] |
|
80 |
if models.AttributeValue.objects.with_owner(user).filter(attribute__label=registration_id_name, |
|
81 |
content='"%s"' % registration_id).exists(): |
|
82 |
has_active_account = True |
|
83 |
if has_active_account: |
|
84 |
logout(request) |
|
85 |
context = kwargs.copy() |
|
86 |
context.update({'accounts': user_accounts}) |
|
87 |
self.template_name = 'registration/login_choices.html' |
|
88 |
return self.render_to_response(context) |
|
89 |
else: |
|
90 |
return super(RegistrationCompletionView, self).get(request, *args, **kwargs) |
|
76 |
logout(request) |
|
77 |
context = kwargs.copy() |
|
78 |
context.update({'accounts': user_accounts}) |
|
79 |
self.template_name = 'registration/login_choices.html' |
|
80 |
return self.render_to_response(context) |
|
91 | 81 |
else: |
92 | 82 |
return super(RegistrationCompletionView, self).get(request, *args, **kwargs) |
93 | 83 | |
... | ... | |
104 | 94 |
else: |
105 | 95 |
return self.form_invalid(form) |
106 | 96 | |
97 |
class RegistrationCreateView(RegistrationCompletionView): |
|
98 | ||
99 |
@valid_token |
|
100 |
def get(self, request, *args, **kwargs): |
|
101 |
return super(RegistrationCompletionView, self).get(request, *args, **kwargs) |
|
102 | ||
107 | 103 |
class DeleteView(TemplateView): |
108 | 104 |
def get(self, request, *args, **kwargs): |
109 | 105 |
next_url = request.build_absolute_uri(request.META.get('HTTP_REFERER')\ |
authentic2/templates/registration/login_choices.html | ||
---|---|---|
25 | 25 |
{% endfor %} |
26 | 26 |
</ul> |
27 | 27 | |
28 |
<p> |
|
29 |
{% trans "or" %} |
|
30 |
<a href="{% url "registration_create" registration_token %}"> |
|
31 |
{% trans "create a new account" %} |
|
32 |
</a> |
|
33 |
</p> |
|
34 | ||
28 | 35 |
{% endblock %} |
29 |
- |