Commits

Sergey Maranchuk committed 9d127ff

fix

Comments (0)

Files changed (3)

openauth/templates/openauth/login.html

 {% extends 'base.html' %}
 {% block content %}
 <form method='post' action='.'>
+    <table>
     {{ form.as_table }}
+    </table>
     <input type='submit' value='submit' />
 </form>
 {% endblock content %}
 
 from django.shortcuts import redirect
 from django.utils.translation import ugettext as _
+from django.core.urlresolvers import reverse
 from django.conf import settings
 
 import openauth
 
 def activation_required(view_func):
     """
-    Decorator for views that checks is registration allowed and
-    is user olready authenticated
+    Decorator for views that checks is user activated and authenticated
     """
     @wraps(view_func)
     def wrapper(request, *args, **kwargs):
         if request.user.is_authenticated():
-            return message(request, _('You have to logout before registration'), 'notice', '/')
-        if not openauth.settings.REGISTRATION_ALLOWED:
-            request.flash['notice'] = _('Sorry. Registration is disabled.')
-            return message(request, _('We are sorry, but registration is disabled. Come back later'), 'notice', '/')
+            if openauth.settings.ACTIVATION_REQUIRED and not request.user.is_active:
+                return message(request, _('You account is not activated! Check your email please.'), 'notice', '/')
+        else:
+            next_data = { 'next':request.path }
+            next = reverse('openauth-login')
+            joiner = ('?' in next) and '&' or '?'
+            next += joiner + unicode_urlencode(next_data) 
+            return redirect(next)
         return view_func(request, *args, **kwargs)
-    return wrapper
+    return wrapper
 from django.core.urlresolvers import reverse
 from django.contrib.auth.decorators import login_required
 from django.contrib import auth 
-from django.shortcuts import get_object_or_404
+from django.shortcuts import get_object_or_404, redirect
 from django.utils.translation import ugettext as _
 from django.http import HttpResponseRedirect
 from django.db.models import Q
     Check confirmation key, proccess confirmation and delete key.
     """
     key = request.GET.get("key")
-    confirmation_type = int(request.GET.get("type", 1))
+    try:
+        confirmation_type = int(request.GET.get("type", 1))
+    except ValueError:
+        return message(request, _("Confirmation error: incorrect type"), "error", "/")
     confirmation = get_object_or_404(Confirmation, key=key, confirmation_type=confirmation_type)
     if confirmation_type == openauth.settings.ACTIVATION_CONFIRMATION_TYPE:
         user = confirmation.user
         confirmation.delete()
         return message(request, _('Your account successfully activated'), 'success', 'show-user', args=[user.id])
     elif confiramtion_type == openauth.settings.PASSWORD_RESET_CONFIRMATION_TYPE:
-        confirmation.user.backend = 'django.contrib.auth.backends.ModelBackend'                                                                                  
+        confirmation.user.backend = 'django.contrib.auth.backends.ModelBackend'
         auth.login(request, confirmation.user)      
         confirmation.delete()
         return message(request, _("Now you can change your password"), "notice", "openauth-reset-form")
 
 
 @render_to('openauth/registration.html')
-@activation_required
 def registration(request):
     """
     Only anonymous users can view this page
     Registration should be allowed in REGISTRATION_ALLOWED setting
     """
-
+    if request.user.is_authenticated():
+            return message(request, _('You have to logout before registration'), 'notice', '/')
+    if not openauth.settings.REGISTRATION_ALLOWED:
+        request.flash['notice'] = _('Sorry. Registration is disabled.')
+        return message(request, _('We are sorry, but registration is disabled. Come back later'), 'notice', '/')
     if request.POST:
         form = str_to_class(openauth.settings.REGISTRATION_FORM)(request.POST)
         if form.is_valid():
     return {'form': form}
 
 
+@activation_required
 @render_to('openauth/reset_password.html')
 def reset_password(request):
     if request.POST:
 
 @render_to('openauth/login.html')
 def login(request):
+    #TODO correct next url redirect
     if request.user.is_authenticated():
         return message(request, _('You are already authenticated'), 'notice', '/')
-
     if request.POST:
         form = LoginForm(request, request.POST)
         request.session['login_redirect_url'] = request.GET.get('next')
     return {'form': form}
 
 
-@login_required
+@activation_required
 @render_to('account/new_password.html')
 def change_password(request):
     if 'POST' == request.method:
     return {'form': form, 'user': user}
 
 
-
 @render_to('openauth/profile.html')
 def show_user(request, user_id):
     """