Commits

offline committed 4a1cca6

messages moved to seperate file, registration function now show messages with django-notify

Comments (0)

Files changed (3)

openauth/__init__.py

 from openauth import signals
 from openauth import settings
+from openauth import lang
+from django.utils.translation import ugettext as _
+
+LOGOUT_BEFORE_REGISTRATION = _('You have to logout before new account registration')
+REGISTRATION_DISABLED = _('We are sorry, but registration is disabled. Come back later')
+PLEASE_ACTIVATE = _("You have successfully registered. Check your inbox for email with activation link.")
+ERROR_SENDING_MAIL = _('Unfortunately we could not send you email in current time. Please, try later')
+LOGIN_NOW = _("You have successfully registered. You can login now")

openauth/views.py

 
 from annoying.decorators import render_to
 from confirmation.models import Confirmation
+from notify import Notify
 
 import openauth
 from openauth.forms import ResetPasswordForm, NewPasswordForm, LoginForm, \
     Registration should be allowed in REGISTRATION_ALLOWED setting
     """
     if request.user.is_authenticated():
-        return message(request, _('You have to logout before new account registration'), 'notice', '/')
+        msg = Notify(openauth.lang.LOGOUT_BEFORE_REGISTRATION)
+        return msg.notice(request, '/')
     if not openauth.settings.REGISTRATION_ALLOWED:
-        return message(request, _('We are sorry, but registration is disabled. Come back later'), 'notice', '/')
+        msg = Notify(openauth.lang.REGISTRATION_DISABLED)
+        msg.notice(request, '/')
     if request.POST:
         form = str_to_class(openauth.settings.REGISTRATION_FORM)(request.POST)
         if form.is_valid():
             user.save()
 
             if openauth.settings.ACTIVATION_REQUIRED:
-                confirmation = Confirmation.objects.create(user, confirmation_type=openauth.settings.ACTIVATION_CONFIRMATION_TYPE)
+                confirmation = Confirmation.objects.create(user, 
+                                                           openauth.settings.ACTIVATION_CONFIRMATION_TYPE)
                 url = request.build_absolute_uri(reverse('confirmation'))
                 url += '?key=%s&type=%s' % (confirmation.key, confirmation.confirmation_type)
                 params = {'domain': request.get_host(), 'email': user.email, 'url': url}
                 if email_template(user.email, 'openauth/mail/registration.txt', **params):
-                    return message(request, _("You have successfully registered. Check your inbox for email with activation link."), "success", "/")
+                    msg = Notify(openauth.lang.PLEASE_ACTIVATE)
+                    return msg.success(request, "/")
                 else:
                     user.delete()
-                    return message(request, _('The error was occuried while sending email with activation code. Account was not created. Please, try later.'), "error", "/")
+                    return message(request, openauth.lang.ERROR_SENDING_MAIL, "error", "/")
             else:
-                return message(request, _("You have successfully registered. You can login now"), "success", "openauth-login")
+                return message(request, openauth.lang.LOGIN_NOW, "success", "openauth-login")
 
     else:
         form = str_to_class(openauth.settings.REGISTRATION_FORM)()
         form = ResetPasswordForm(request.POST)
         if form.is_valid():
             user = User.objects.get(email=form.cleaned_data['email'].lower())
-            confirmation = Confirmation(user=user, key=generate_hash(), confirmation_type=openauth.settings.PASSWORD_RESET_CONFIRMATION_TYPE)
-            confirmation.save()
+            confirmation = Confirmation.objects.create(user, 
+                                                       openauth.settings.PASSWORD_RESET_CONFIRMATION_TYPE)
             url = request.build_absolute_uri(reverse('openauth-confirm'))
             url += '?key=%s&type=%s' % (confirmation.key, openauth.settings.PASSWORD_RESET_CONFIRMATION_TYPE)
             args = {'domain': request.get_host(), 'url': url}
             if email_template(user.email, 'openauth/mail/reset_password.txt', **args):
                 return message(request, _('Check your email please'), 'notice', '/')
             else:
-                return message(request, _('Unfortunately we could not send you email in current time. Please, try later'), 'error', '/')
+                return message(request, openauth.lang.ERROR_SENDING_MAIL, 'error', '/')
     else:
         form = ResetPasswordForm()
     return {'form': form}