Commit 0df063b2d5393469e3710cf82016b09dbf1e5c4e
Committed by
Sergio Oliveira
1 parent
442161fd
Exists in
master
and in
39 other branches
Created middleware to redirect user
Redirecting user to complete its profile with the main data(first/last name and username) through every page till (s)he updates it. Signed-off-by: Carlos Oliveira <carlospecter@gmail.com> Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Showing
3 changed files
with
40 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +from django.core.urlresolvers import resolve | |
| 2 | +from django.shortcuts import redirect | |
| 3 | + | |
| 4 | + | |
| 5 | +class UserRegisterMiddleware(object): | |
| 6 | + | |
| 7 | + def process_view(self, request, view_func, view_args, view_kwargs): | |
| 8 | + if not request.user.is_authenticated(): | |
| 9 | + return | |
| 10 | + | |
| 11 | + if not request.user.needs_update: | |
| 12 | + return | |
| 13 | + | |
| 14 | + current_url = resolve(request.path_info).url_name | |
| 15 | + | |
| 16 | + if current_url not in ['signup']: | |
| 17 | + return redirect('signup') | |
| 18 | + | |
| 19 | + return None | ... | ... |
| ... | ... | @@ -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 | + ] | ... | ... |
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. | ... | ... |