Commit d25240dcd7440a393db31e8089474135f449e34b
1 parent
86894a1f
Exists in
master
and in
39 other branches
Fixing xmpp password change
Showing
2 changed files
with
18 additions
and
6 deletions
Show diff stats
src/accounts/forms.py
@@ -81,6 +81,7 @@ class ChangeXMPPPasswordForm(forms.ModelForm): | @@ -81,6 +81,7 @@ class ChangeXMPPPasswordForm(forms.ModelForm): | ||
81 | 81 | ||
82 | def __init__(self, *args, **kwargs): | 82 | def __init__(self, *args, **kwargs): |
83 | super(ChangeXMPPPasswordForm, self).__init__(*args, **kwargs) | 83 | super(ChangeXMPPPasswordForm, self).__init__(*args, **kwargs) |
84 | + | ||
84 | for field_name, field in self.fields.items(): | 85 | for field_name, field in self.fields.items(): |
85 | # Adds form-control class to all form fields | 86 | # Adds form-control class to all form fields |
86 | field.widget.attrs.update({'class': 'form-control'}) | 87 | field.widget.attrs.update({'class': 'form-control'}) |
@@ -90,7 +91,13 @@ class ChangeXMPPPasswordForm(forms.ModelForm): | @@ -90,7 +91,13 @@ class ChangeXMPPPasswordForm(forms.ModelForm): | ||
90 | password2 = self.cleaned_data.get("password2") | 91 | password2 = self.cleaned_data.get("password2") |
91 | if password1 and password2 and password1 != password2: | 92 | if password1 and password2 and password1 != password2: |
92 | raise forms.ValidationError( | 93 | raise forms.ValidationError( |
93 | - self.error_messages['password_mismatch'], | 94 | + _("Password mismatch"), |
94 | code='password_mismatch', | 95 | code='password_mismatch', |
95 | ) | 96 | ) |
96 | return password2 | 97 | return password2 |
98 | + | ||
99 | + def save(self, commit=True): | ||
100 | + self.instance.password = self.cleaned_data['password2'] | ||
101 | + if commit: | ||
102 | + self.instance.save() | ||
103 | + return self.instance |
src/accounts/views.py
@@ -192,13 +192,18 @@ class ChangeXMPPPasswordView(UpdateView): | @@ -192,13 +192,18 @@ class ChangeXMPPPasswordView(UpdateView): | ||
192 | }) | 192 | }) |
193 | 193 | ||
194 | def get_object(self, queryset=None): | 194 | def get_object(self, queryset=None): |
195 | - return get_object_or_404(XMPPAccount, user=self.request.user.pk) | 195 | + obj = get_object_or_404(XMPPAccount, user=self.request.user.pk) |
196 | + self.old_password = obj.password | ||
197 | + return obj | ||
196 | 198 | ||
197 | def form_valid(self, form): | 199 | def form_valid(self, form): |
198 | - self.object = form.save() | 200 | + response = super(ChangeXMPPPasswordView, self).form_valid(form) |
199 | 201 | ||
200 | - xmpp_account = self.get_object() | ||
201 | - changed = xmpp.change_password(xmpp_account, password) | 202 | + changed = xmpp.change_password( |
203 | + self.object.jid, | ||
204 | + self.old_password, | ||
205 | + form.cleaned_data['password2'] | ||
206 | + ) | ||
202 | if not changed: | 207 | if not changed: |
203 | raise Exception | 208 | raise Exception |
204 | - return super(ChangeXMPPPassword, self).form_valid(form) | 209 | + return response |