Commit 38fe9baef9865bf5bc7a226aa2c04b636c5336dd
1 parent
9d56cd61
Exists in
master
and in
39 other branches
Adding missing functionality from #64
Showing
2 changed files
with
19 additions
and
1 deletions
Show diff stats
src/accounts/models.py
... | ... | @@ -21,6 +21,22 @@ class User(AbstractUser): |
21 | 21 | verification_hash = models.CharField(max_length=32, null=True, blank=True) |
22 | 22 | modified = models.DateTimeField(auto_now=True) |
23 | 23 | |
24 | + def check_password(self, raw_password): | |
25 | + """ | |
26 | + Returns a boolean of whether the raw_password was correct. | |
27 | + """ | |
28 | + if not raw_password or not self.has_usable_password(): | |
29 | + return False | |
30 | + return self.password == raw_password | |
31 | + | |
32 | + def has_usable_password(self): | |
33 | + if not self.password: | |
34 | + return False | |
35 | + return True | |
36 | + | |
37 | + def set_password(self, raw_password): | |
38 | + self.password = unicode(raw_password) | |
39 | + | |
24 | 40 | def get_absolute_url(self): |
25 | 41 | return reverse('user_profile', kwargs={'username': self.username}) |
26 | 42 | ... | ... |
src/accounts/views.py
... | ... | @@ -200,7 +200,7 @@ class ChangeXMPPPasswordView(UpdateView): |
200 | 200 | changed = xmpp.change_password( |
201 | 201 | self.object.jid, |
202 | 202 | self.old_password, |
203 | - form.cleaned_data['password2'] | |
203 | + form.cleaned_data['password1'] | |
204 | 204 | ) |
205 | 205 | |
206 | 206 | if not changed: |
... | ... | @@ -211,6 +211,8 @@ class ChangeXMPPPasswordView(UpdateView): |
211 | 211 | transaction.rollback() |
212 | 212 | return response |
213 | 213 | else: |
214 | + self.request.user.set_password(form.cleaned_data['password1']) | |
215 | + self.request.user.save() | |
214 | 216 | transaction.commit() |
215 | 217 | |
216 | 218 | messages.success( | ... | ... |