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()
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 = []