def test_too_long_change_password_form(self): data = { 'password_old': self.oldpassword, 'password_new': stringof77chars, 'password_confirm': stringof77chars } form = ChangePasswordForm(data=data, user=self.user1.user) self.assertFalse(form.is_valid())
def test_not_matching_change_password_form(self): data = { 'password_old': self.oldpassword, 'password_new': self.newpassword, 'password_confirm': 'Wronnnng' } form = ChangePasswordForm(data=data, user=self.user1.user) self.assertFalse(form.is_valid())
def test_valid_change_password_form(self): data = { 'password_old': self.oldpassword, 'password_new': self.newpassword, 'password_confirm': self.newpassword } form = ChangePasswordForm(data=data, user=self.user1.user) self.assertTrue(form.is_valid())
def test_match_pseudo_change_password_form(self): self.user1.user.username = "******" data = { 'password_old': self.oldpassword, 'password_new': self.user1.user.username, 'password_confirm': self.user1.user.username } form = ChangePasswordForm(data=data, user=self.user1.user) self.assertFalse(form.is_valid())
def test_too_short_change_password_form(self): tooshort = "short" data = { 'password_old': self.oldpassword, 'password_new': tooshort, 'password_confirm': tooshort } form = ChangePasswordForm(data=data, user=self.user1.user) self.assertFalse(form.is_valid())
def change_password(request): if request.method == 'POST': form = ChangePasswordForm(request.POST) if form.is_valid(): old_password = form.cleaned_data['old_password'] user = request.user user_obj = auth.authenticate(username=user.username, password=old_password) if user_obj: new_password = form.cleaned_data['new_password'] user.set_password(new_password) user.save() request.flash['message'] = _('Your password has been changed') return redirect('member-profile') form = ChangePasswordForm() return render(request, 'member/change_password.html', {'form': form})