Commits

offline committed 202f511

bugfixes

  • Participants
  • Parent commits 2bd7cc7

Comments (0)

Files changed (9)

File auth/__init__.py

-"""
-Django application
-"""
+from auth import settings

File auth/forms.py

 from annoying.functions import get_object_or_None
 from annoying.decorators import autostrip
 
+import auth
 from auth.models import Confirmation
 
 
         if not auth.settings.USERNAME_REGEX.match(value):
             raise forms.ValidationError(_(u'Login contains restricted symbols'))
 
-        try:
-            User.objects.get(username__exact=value)
-        except User.DoesNotExist:
-            return value
-        else:
+        if auth.settings.UNIQUE_USERNAME and get_object_or_None(User, username=value):
             raise forms.ValidationError(_(u'This login already registered'))
+        return value
 
 
 class PasswordField(forms.CharField):
 
     def __init__(self, *args, **kwargs):
         super(PasswordField, self).__init__(*args, **kwargs)
-        self.widget = forms.PasswordInput(attrs=auth.settings.PASSWORD_FIELD_ATTRIBUTES)
+        self.widget = forms.PasswordInput()
         self.help_text = ''
 
 
 
 
 class RegistrationForm(forms.Form):
-    username = forms.CharField(label=_('Nickname'), max_length=30)
+    username = UsernameField()
     email = forms.EmailField(label=_('Email'))
     password = PasswordField(label=_('Password'))
     password_dup = PasswordField(label=_('Password (confirmation)'))

File auth/models.py

 import auth
 from auth.utils import unicode_urlencode, generate_hash
 
-User.username = models.CharField(max_length=30)
+User.username = models.CharField(max_length=30, unique=auth.settings.UNIQUE_USERNAME)
 
 
 class Profile(models.Model):

File auth/settings.py

+import re
+
 from annoying.functions import get_config
 
 
 MESSAGE_TYPE = get_config("MESSAGE_TYPE", "flash")
 CUSTOM_CONFIRMATION = get_config("CUSTOM_CONFIRMATION", None) # custom confirmation function
-REGISTRATION_ALOWED = get_config("REGISTRATION_ALLOWED", True)
+REGISTRATION_ALLOWED = get_config("REGISTRATION_ALLOWED", True)
 REGISTRATION_FORM = get_config("REGISTRATION_FORM", "auth.forms.RegistrationForm")
+UNIQUE_USERNAME = get_config("UNIQUE_USERNAME", True)
 
 GRAVATAR_URL = get_config("GRAVATAR_URL", "http://www.gravatar.com/avatar.php?")
 GRAVATAR_SIZE = get_config("GRAVATAR_SIZE", (25, 25))
 GRAVATAR_TYPE = get_config("GRAVATAR_TYPE", "identicon")
 
 ACTIVATION_REQUIRED = get_config("ACTIVATION_REQUIRED", True)
-ACTIVATION_AUTOLOGIN = get_config("ACTIVATION_AUTOLOGIN", True)
+ACTIVATION_AUTO_LOGIN = get_config("ACTIVATION_AUTO_LOGIN", True)
 
 ACTIVATION_CONFIRMATION_TYPE = get_config("ACTIVATION_CONFIRMATION_TYPE", 1)
 PASSWORD_RESET_CONFIRMATION_TYPE = get_config("PASSWORD_RESET_CONFIRMATION_TYPE", 2)

File auth/templates/auth/mail/registration.txt

+{% load i18n %}{% blocktrans %}Registration on {{ domain }}{% endblocktrans %}
+{% blocktrans %}Thanks for registration on {{ domain }}{% endblocktrans %}.
+{% blocktrans %}Please use following link to activate your account: {{ url }}{% endblocktrans %}

File auth/templates/auth/registration.html

+{% extends 'base.html' %}
+{% block content %}
+<form action='.' method='post'>
+{{ form.as_table }}
+<input type='submit' value='submit' />
+</form>
+{% endblock %}

File auth/urls.py

+from django.conf.urls.defaults import *
+from django.views.generic.simple import direct_to_template
+
+from auth import views
+
+
+urlpatterns = patterns('',
+    url(r'^registration/$', views.registration, name='auth-registration'),
+    url(r'^login/$', views.login, name='auth-login'),
+    url(r'^logout/$', views.logout, name='auth-logout'),
+    url(r'^reset_password/$', views.reset_password, name='auth-reset-password'),
+    url(r'^change_password/$', views.change_password, name='auth-change-password'),
+    url(r'^confirm/$', views.confirm, name='auth-confirm'),
+    url(r'^user/(\d+)/$', views.show_user, name='show-user'),
+    #url(r'^edit/(\d+)/$', views.edit_user, name='edit-user'),
+    #url(r'^email_changed/$', views.email_changed, name='auth_email_changed'),
+)

File auth/utils.py

                       [rcpt], fail_silently=True)
     return bool(count)
 
+def str_to_class(str):
+    mod_str, cls_str = str.rsplit('.', 1)
+    mod = __import__(mod_str, globals(), locals(), ['foobar'])
+    cls = getattr(mod, cls_str)
+    return cls

File auth/views.py

 from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
 from django.contrib.auth.decorators import login_required
-from django.contrib.auth import proccess_login
+from django.contrib.auth import login as proccess_login
 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
 
-from annoying.decorators import ajax_request
+from annoying.decorators import ajax_request, render_to
 from ninjapaginator.util import NinjaPaginator
 
 
+import auth                          
 from auth.forms import RestorePasswordForm, NewPasswordForm, LoginForm, NewEmailForm, EditUserForm
-                          
-from auth.util import email_template, build_redirect_url
+from auth.utils import email_template, build_redirect_url, str_to_class, generate_hash
 from auth.models import Confirmation
 
 
             confirmation.user.backend = 'django.contrib.auth.backends.ModelBackend'
             proccess_login(request, user)
 
-        activation.delete()
+        confirmation.delete()
         return message(request, _('Your account successfully activated'), 'success', 'show-user', args=[user.id])
     elif confiramtion_type == auth.settings.PASSWORD_RESET_CONFIRMATION_TYPE:
         confirmation.user.backend = 'django.contrib.auth.backends.ModelBackend'                                                                                  
         return message(request, _('We are sorry, but registration is disabled. Come back later'), 'notice', '/')
 
     if request.POST:
-        form = auth.settings.REGISTRATION_FORM(request.POST)
+        form = str_to_class(auth.settings.REGISTRATION_FORM)(request.POST)
         if form.is_valid():
             user = form.save()
             if auth.settings.ACTIVATION_REQUIRED:
             user.save()
 
             if auth.settings.ACTIVATION_REQUIRED:
-                confirmation = Confirmation(user=user, key=generate_hash(), auth.settings.ACTIVATION_CONFIRMATION_TYPE)
+                confirmation = Confirmation(user=user, key=generate_hash(), confirmation_type=auth.settings.ACTIVATION_CONFIRMATION_TYPE)
                 confirmation.save()
-                url = request.build_absolute_uri(reverse('confirmation'))
+                url = request.build_absolute_uri(reverse('auth-confirm'))
                 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, 'account/mail/registration.txt', **params):
+                if email_template(user.email, 'auth/mail/registration.txt', **params):
                     return message(request, _("You have successfully registered. Check your inbox for email with activation link."), "success", "/")
                 else:
                     user.delete()
                 return message(request, _("You have successfully registered. You can login now"), "success", "login")
 
     else:
-        form = auth.settings.REGISTRATION_FORM()
+        form = str_to_class(auth.settings.REGISTRATION_FORM)()
     return {'form': form}
 
 
 
 @login_required
 @render_to('account/new_password.html')
-def new_password(request):
+def change_password(request):
     if 'POST' == request.method:
         form = NewPasswordForm(request.POST)
     else: