Commit 80b68d86a46f8437300d622be5b142b4c881d5fc
Committed by
Sergio Oliveira
1 parent
eff7a486
Exists in
master
and in
13 other branches
Handling user creation with(out) browserid
Signed-off-by: Alexandre Barbosa <alexandreab@live.com> Signed-off-by: Carlos Oliveira <carlospecter@gmail.com> Signed-off-by: Lucas Kanashiro <kanashiroduarte@gmail.com>
Showing
1 changed file
with
22 additions
and
16 deletions
Show diff stats
colab/accounts/views.py
... | ... | @@ -22,7 +22,6 @@ from haystack.query import SearchQuerySet |
22 | 22 | |
23 | 23 | from colab.super_archives.models import EmailAddress, Message, EmailAddressValidation |
24 | 24 | from colab.search.utils import trans |
25 | -from colab.settings import BROWSERID_ENABLED | |
26 | 25 | # from proxy.trac.models import WikiCollabCount, TicketCollabCount |
27 | 26 | from .forms import (UserCreationForm, ListsForm, UserUpdateForm, |
28 | 27 | ChangeXMPPPasswordForm) |
... | ... | @@ -129,19 +128,21 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): |
129 | 128 | |
130 | 129 | |
131 | 130 | def signup(request): |
132 | - # TODO: Refactor | |
133 | - | |
134 | 131 | user = request.user |
135 | - # If the user is not authenticated in Persona, and try to access url | |
136 | - # /account/register/ then he will be redirected to login page. | |
137 | - if not user.is_authenticated(): | |
138 | - return redirect('login') | |
139 | - | |
140 | - # If the user is authenticated in Persona, already register in Colab | |
141 | - # and try to access directly "/account/register/", then he will be redirect | |
142 | - # to user profile. | |
143 | - if not user.needs_update: | |
144 | - return redirect('user_profile', username=user.username) | |
132 | + BROWSERID_ENABLED = getattr(settings, 'BROWSERID_ENABLED', False) | |
133 | + | |
134 | + if BROWSERID_ENABLED: | |
135 | + # If the user is not authenticated, redirect to login | |
136 | + if not request.user.is_authenticated(): | |
137 | + return redirect('login') | |
138 | + | |
139 | + if request.user.is_authenticated(): | |
140 | + # If the user doesn't need to update its main data, | |
141 | + # redirect to its profile | |
142 | + # It happens when user is created by browserid | |
143 | + # and didn't set his/her main data | |
144 | + if not request.user.needs_update: | |
145 | + return redirect('user_profile', username=request.user.username) | |
145 | 146 | |
146 | 147 | # If the user is authenticated in Persona, but not in the Colab then he |
147 | 148 | # will be redirected to the register form. |
... | ... | @@ -152,7 +153,10 @@ def signup(request): |
152 | 153 | return render(request, 'accounts/user_create_form.html', |
153 | 154 | {'user_form': user_form, 'lists_form': lists_form}) |
154 | 155 | |
155 | - user_form = UserCreationForm(request.POST, instance=user) | |
156 | + if BROWSERID_ENABLED: | |
157 | + user_form = UserCreationForm(request.POST, instance=request.user) | |
158 | + else: | |
159 | + user_form = UserCreationFormNoBrowserId(request.POST) | |
156 | 160 | lists_form = ListsForm(request.POST) |
157 | 161 | |
158 | 162 | if not user_form.is_valid() or not lists_form.is_valid(): |
... | ... | @@ -161,11 +165,13 @@ def signup(request): |
161 | 165 | |
162 | 166 | user = user_form.save(commit=False) |
163 | 167 | user.needs_update = False |
168 | + | |
164 | 169 | if not BROWSERID_ENABLED: |
165 | 170 | user.is_active = False |
171 | + user.save() | |
166 | 172 | EmailAddressValidation.create(user.email, user) |
167 | - | |
168 | - user.save() | |
173 | + else: | |
174 | + user.save() | |
169 | 175 | |
170 | 176 | # Check if the user's email have been used previously |
171 | 177 | # in the mainling lists to link the user to old messages | ... | ... |