Commits

Peter Sanchez committed 06b2ea5

Working on baseacct. Added password_change support

Comments (0)

Files changed (4)

webutils/baseacct/__init__.py

 from django.conf import settings
-from forms import LoginForm, ResetForm
+from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm
+from django.core.exceptions import ImproperlyConfigured
+from forms import ResetForm
 from webutils.djtools.easyconfig import EasyConfig
-from django.core.exceptions import ImproperlyConfigured
 
 
 class Config(object):
     ''' Base config class to easily pass forms, etc. to 
         baseacct views.
     '''
-    config = EasyConfig('baseacct.Config', 'BASEACCT_CONFIG')
+    config = EasyConfig('webutils.baseacct.Config', 'BASEACCT_CONFIG')
     
     def get_login_form(self):
-        return self.config.get_object('get_login_form', LoginForm)
+        return self.config.get_object('get_login_form', AuthenticationForm)
     
     def get_login_url(self):
         # Defaults to /accounts/login/ - Ugly!
                 'The "AUTH_PROFILE_MODULE" setting MUST be set to use ' + \
                 'this method. Please add it to your projects settings.py'
             )
-        return self.config.get_object('get_profile_model', None)
+        return self.config.get_object('get_profile_model', None)
+    
+    def get_post_change_redirect(self):
+        return self.config.get_object('get_post_change_redirect', None)
+    
+    def get_password_change_form(self):
+        return self.config.get_object('get_password_change_form', PasswordChangeForm)

webutils/baseacct/forms.py

 from django.utils.translation import ugettext_lazy as _
 
 
-class LoginForm(AuthenticationForm):
-    username = forms.CharField(
-        label=_('Username'),
-        max_length=30,
-    )
-    password = forms.CharField(
-        label=_('Password'),
-    )
-
-
 class ResetForm(forms.Form):
     email = forms.EmailField(
         max_length=125,

webutils/baseacct/urls.py

     url(r'^logout-login/$',
         auth_views.logout_then_login,
         {'login_url': config.get_login_url()},
-        name='baseacct-logout'),
+        name='baseacct-logout-login'),
+    url(r'^password_change/$',
+        auth_views.password_change, {
+            'template_name': 'baseacct/password_change.html',
+            'post_change_redirect': config.get_post_change_redirect(),
+            'password_change_form': config.get_password_change_form(),
+        }, name='baseacct-password-change')
+    url(r'^password_change/done/$',
+        auth_views.password_change_done, {
+            'template_name': 'baseacct/password_change_done.html',
+        }, name='baseacct-password-change-done')
     url(r'^reset/$',
         'reset', {
             'template': 'baseacct/reset.html',

webutils/baseacct/views.py

 from django.conf import settings
 from django.contrib.auth.models import User
 from django.shortcuts import render_to_response, redirect
+from django.contrib.auth.decorators import login_required
 from webutils.baseacct import Config
 
 
 
     return render_to_response(template, {
         'form': form,
-    }, context_instance=RequestContext(request))
+    }, context_instance=RequestContext(request))