Commit d733629f29588ca2f60691f696a7b76be33fd898
Exists in
master
and in
39 other branches
Merge branch 'incomplete_register_redirect' into 'master'
Incomplete register redirect Let browserid handle the new users registration.
Showing
12 changed files
with
96 additions
and
56 deletions
Show diff stats
colab/accounts/auth.py
colab/accounts/forms.py
... | ... | @@ -32,7 +32,7 @@ class UserForm(forms.ModelForm): |
32 | 32 | # Forces username to be lowercase always |
33 | 33 | widget=forms.TextInput(attrs={'style' : 'text-transform: lowercase;'}), |
34 | 34 | ) |
35 | - required = ('first_name', 'last_name', 'email', 'username') | |
35 | + required = ('first_name', 'last_name', 'username') | |
36 | 36 | |
37 | 37 | class Meta: |
38 | 38 | model = User |
... | ... | @@ -49,9 +49,17 @@ class UserForm(forms.ModelForm): |
49 | 49 | |
50 | 50 | |
51 | 51 | class UserCreationForm(UserForm): |
52 | + | |
53 | + def clean_username(self): | |
54 | + username = self.cleaned_data['username'] | |
55 | + username = username.strip() | |
56 | + if not username: | |
57 | + raise forms.ValidationError(_('This field cannot be blank.')) | |
58 | + return username | |
59 | + | |
52 | 60 | class Meta: |
53 | 61 | model = User |
54 | - fields = ('first_name', 'last_name', 'email', 'username') | |
62 | + fields = ('first_name', 'last_name', 'username') | |
55 | 63 | |
56 | 64 | |
57 | 65 | class UserUpdateForm(UserForm): | ... | ... |
colab/accounts/management/__init__.py
colab/accounts/management/commands/__init__.py
colab/accounts/management/commands/delete_invalid.py
... | ... | @@ -1,42 +0,0 @@ |
1 | - | |
2 | - | |
3 | -from django.db.models import F | |
4 | -from django.utils import timezone | |
5 | -from django.utils.translation import ugettext as _ | |
6 | -from django.core.management.base import BaseCommand, CommandError | |
7 | - | |
8 | - | |
9 | -from ...models import User | |
10 | - | |
11 | - | |
12 | -class Command(BaseCommand): | |
13 | - """Delete user accounts that have never logged in. | |
14 | - | |
15 | - Delete from database user accounts that have never logged in | |
16 | - and are at least 24h older. | |
17 | - | |
18 | - """ | |
19 | - | |
20 | - help = __doc__ | |
21 | - | |
22 | - def handle(self, *args, **kwargs): | |
23 | - seconds = timezone.timedelta(seconds=1) | |
24 | - now = timezone.now() | |
25 | - one_day_ago = timezone.timedelta(days=1) | |
26 | - | |
27 | - # Query for users that have NEVER logged in | |
28 | - # | |
29 | - # By default django sets the last_login as auto_now and then | |
30 | - # last_login is pretty much the same than date_joined | |
31 | - # (instead of null as I expected). Because of that we query | |
32 | - # for users which last_login is between date_joined - N and | |
33 | - # date_joined + N, where N is a small constant in seconds. | |
34 | - users = User.objects.filter(last_login__gt=(F('date_joined') - seconds), | |
35 | - last_login__lt=(F('date_joined') + seconds), | |
36 | - date_joined__lt=now-one_day_ago) | |
37 | - count = 0 | |
38 | - for user in users: | |
39 | - count += 1 | |
40 | - user.delete() | |
41 | - | |
42 | - print _(u'%(count)s users deleted.') % {'count': count} |
... | ... | @@ -0,0 +1,21 @@ |
1 | + | |
2 | +from django.shortcuts import redirect | |
3 | + | |
4 | +VIEW_NAMES_ALLOWED = ('signup', 'Logout') | |
5 | + | |
6 | + | |
7 | +class UserRegisterMiddleware(object): | |
8 | + | |
9 | + def process_view(self, request, view_func, view_args, view_kwargs): | |
10 | + | |
11 | + if request.is_ajax(): | |
12 | + return | |
13 | + | |
14 | + if not request.user.is_authenticated(): | |
15 | + return | |
16 | + | |
17 | + if not request.user.needs_update: | |
18 | + return | |
19 | + | |
20 | + if view_func.__name__ not in VIEW_NAMES_ALLOWED: | |
21 | + return redirect('signup') | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +from __future__ import unicode_literals | |
3 | + | |
4 | +from django.db import models, migrations | |
5 | + | |
6 | + | |
7 | +class Migration(migrations.Migration): | |
8 | + | |
9 | + dependencies = [ | |
10 | + ('accounts', '0001_initial'), | |
11 | + ] | |
12 | + | |
13 | + operations = [ | |
14 | + migrations.AddField( | |
15 | + model_name='user', | |
16 | + name='needs_update', | |
17 | + field=models.BooleanField(default=False), | |
18 | + preserve_default=True, | |
19 | + ), | |
20 | + ] | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +from __future__ import unicode_literals | |
3 | + | |
4 | +from django.db import models, migrations | |
5 | + | |
6 | + | |
7 | +class Migration(migrations.Migration): | |
8 | + | |
9 | + dependencies = [ | |
10 | + ('accounts', '0002_user_needs_update'), | |
11 | + ] | |
12 | + | |
13 | + operations = [ | |
14 | + migrations.AlterField( | |
15 | + model_name='user', | |
16 | + name='needs_update', | |
17 | + field=models.BooleanField(default=True), | |
18 | + preserve_default=True, | |
19 | + ), | |
20 | + ] | ... | ... |
colab/accounts/models.py
... | ... | @@ -26,6 +26,7 @@ class User(AbstractUser): |
26 | 26 | verification_hash = models.CharField(max_length=32, null=True, blank=True) |
27 | 27 | modified = models.DateTimeField(auto_now=True) |
28 | 28 | bio = models.CharField(max_length=200, null=True, blank=True) |
29 | + needs_update = models.BooleanField(default=True) | |
29 | 30 | |
30 | 31 | def check_password(self, raw_password): |
31 | 32 | ... | ... |
colab/accounts/views.py
... | ... | @@ -123,21 +123,34 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): |
123 | 123 | |
124 | 124 | |
125 | 125 | def signup(request): |
126 | + user = request.user | |
127 | + | |
128 | + # If the user is not authenticated, redirect to login | |
129 | + if not user.is_authenticated(): | |
130 | + return redirect('login') | |
131 | + | |
132 | + # If the user doesn't need to update its main data, redirect to its profile | |
133 | + if not user.needs_update: | |
134 | + return redirect('user_profile', username=user.username) | |
135 | + | |
126 | 136 | # If the request method is GET just return the form |
127 | 137 | if request.method == 'GET': |
128 | 138 | user_form = UserCreationForm() |
129 | 139 | lists_form = ListsForm() |
140 | + | |
130 | 141 | return render(request, 'accounts/user_create_form.html', |
131 | 142 | {'user_form': user_form, 'lists_form': lists_form}) |
132 | 143 | |
133 | - user_form = UserCreationForm(request.POST) | |
144 | + user_form = UserCreationForm(request.POST, instance=user) | |
134 | 145 | lists_form = ListsForm(request.POST) |
135 | 146 | |
136 | 147 | if not user_form.is_valid() or not lists_form.is_valid(): |
137 | 148 | return render(request, 'accounts/user_create_form.html', |
138 | 149 | {'user_form': user_form, 'lists_form': lists_form}) |
139 | 150 | |
140 | - user = user_form.save() | |
151 | + user = user_form.save(commit=False) | |
152 | + user.needs_update = False | |
153 | + user.save() | |
141 | 154 | |
142 | 155 | # Check if the user's email have been used previously |
143 | 156 | # in the mainling lists to link the user to old messages |
... | ... | @@ -152,8 +165,6 @@ def signup(request): |
152 | 165 | mailman.update_subscription(user.email, mailing_lists) |
153 | 166 | |
154 | 167 | messages.success(request, _('Your profile has been created!')) |
155 | - messages.warning(request, _('You must login to validated your profile. ' | |
156 | - 'Profiles not validated are deleted in 24h.')) | |
157 | 168 | |
158 | 169 | return redirect('user_profile', username=user.username) |
159 | 170 | ... | ... |
colab/settings.py
... | ... | @@ -214,6 +214,7 @@ MIDDLEWARE_CLASSES = ( |
214 | 214 | 'django_mobile.middleware.MobileDetectionMiddleware', |
215 | 215 | 'django_mobile.middleware.SetFlavourMiddleware', |
216 | 216 | 'colab.tz.middleware.TimezoneMiddleware', |
217 | + 'colab.accounts.middleware.UserRegisterMiddleware', | |
217 | 218 | ) |
218 | 219 | |
219 | 220 | # Add the django_browserid authentication backend. |
... | ... | @@ -272,12 +273,13 @@ LOGIN_URL = '/user/login' |
272 | 273 | LOGIN_REDIRECT_URL = '/' |
273 | 274 | LOGIN_REDIRECT_URL_FAILURE = '/?bid_login_failed=true' |
274 | 275 | LOGOUT_REDIRECT_URL = '/' |
275 | -BROWSERID_CREATE_USER = False | |
276 | +BROWSERID_CREATE_USER = True | |
276 | 277 | |
277 | 278 | REVPROXY_ADD_REMOTE_USER = True |
278 | 279 | |
279 | 280 | # Converse.js settings |
280 | 281 | # This URL must use SSL in order to keep chat sessions secure |
282 | +CONVERSEJS_ENABLED = False | |
281 | 283 | CONVERSEJS_BOSH_SERVICE_URL = SITE_URL + '/http-bind' |
282 | 284 | |
283 | 285 | CONVERSEJS_ALLOW_CONTACT_REQUESTS = False | ... | ... |
colab/templates/base.html
... | ... | @@ -119,28 +119,28 @@ |
119 | 119 | {% if proxy.noosfero %} |
120 | 120 | <li class="dropdown"> |
121 | 121 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"> |
122 | - {% trans "Social" %} <b class="caret"></b> | |
122 | + {% trans "Social" %} <b class="caret"></b> | |
123 | 123 | </a> |
124 | 124 | <ul class="dropdown-menu"> |
125 | 125 | <li> |
126 | 126 | <a href="/social/search/people"> |
127 | - {% trans "Users" %} | |
127 | + {% trans "Users" %} | |
128 | 128 | </a> |
129 | 129 | </li> |
130 | 130 | <li> |
131 | 131 | <a href="/social/search/communities"> |
132 | - {% trans "Communities" %} | |
132 | + {% trans "Communities" %} | |
133 | 133 | </a> |
134 | 134 | </li> |
135 | 135 | {% if user.is_active %} |
136 | 136 | <li> |
137 | 137 | <a href="/social/profile/{{ user.username }}"> |
138 | - {% trans "Profile" %} | |
138 | + {% trans "Profile" %} | |
139 | 139 | </a> |
140 | 140 | </li> |
141 | 141 | <li> |
142 | 142 | <a href="/social/myprofile/{{ user.username }}"> |
143 | - {% trans "Control panel" %} | |
143 | + {% trans "Control panel" %} | |
144 | 144 | </a> |
145 | 145 | </li> |
146 | 146 | {% endif %} |
... | ... | @@ -180,12 +180,10 @@ |
180 | 180 | <li class="dropdown hidden-xs hidden-lg"> |
181 | 181 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Acesso <b class="caret"></b></a> |
182 | 182 | <ul class="dropdown-menu"> |
183 | - <li><a href="{% url 'signup' %}">{% trans "Register" %}</a></li> | |
184 | 183 | {% trans 'Login' as login_text %} |
185 | 184 | <li>{% browserid_login text=login_text %}</li> |
186 | 185 | </ul> |
187 | 186 | </li> |
188 | - <li class="visible-xs hidden-sm hidden-md"><a href="{% url 'signup' %}">{% trans "Register" %}</a></li> | |
189 | 187 | {% trans 'Login' as login_text %} |
190 | 188 | <li class="visible-xs hidden-sm hidden-md">{% browserid_login text=login_text %}</li> |
191 | 189 | {% else %} | ... | ... |