]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/auth.py
Fixes OSQA 307, AttributeError: 'ChangePasswordForm' object has no attribute 'cleaned...
[osqa.git] / forum / views / auth.py
index 477f16d1bcf9efb4234f26162725feb5594de28e..d321c9563ffa4513f436c4603680737ad1b31cf6 100644 (file)
@@ -147,6 +147,7 @@ def external_register(request):
 
             if User.objects.all().count() == 0:
                 user_.is_superuser = True
+                user_.is_staff = True
             
             user_.save()
             UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()
@@ -267,25 +268,28 @@ def auth_settings(request, id):
 
     auth_keys = user_.auth_keys.all()
 
-    if user_.has_usable_password():
-        FormClass = ChangePasswordForm
-    else:
+    if request.user.is_superuser or (not user_.has_usable_password()):
         FormClass = SetPasswordForm
+    else:
+        FormClass = ChangePasswordForm
 
     if request.POST:
         form = FormClass(request.POST, user=user_)
         if form.is_valid():
-            if user_.has_usable_password():
-                request.user.message_set.create(message=_("Your password was changed"))
-            else:
-                request.user.message_set.create(message=_("New password set"))
-                FormClass = ChangePasswordForm
-                
+            is_new_pass = not user_.has_usable_password()
             user_.set_password(form.cleaned_data['password1'])
             user_.save()
+
+            if is_new_pass:
+                request.user.message_set.create(message=_("New password set"))
+                if not request.user.is_superuser:
+                    form = ChangePasswordForm(user=user_)
+            else:
+                request.user.message_set.create(message=_("Your password was changed"))
+
             return HttpResponseRedirect(reverse('user_authsettings', kwargs={'id': user_.id}))
-    
-    form = FormClass(user=user_)
+    else:
+        form = FormClass(user=user_)
 
     auth_keys_list = []