def test_password_is_username_new_password_form(self): data = { 'password': self.user1.user.username, 'password_confirm': self.user1.user.username } form = NewPasswordForm(data=data, identifier=self.user1.user.username) self.assertFalse(form.is_valid())
def test_not_matching_new_password_form(self): data = { 'password': self.newpassword, 'password_confirm': "Wronnngggg" } form = NewPasswordForm(data=data, identifier=self.user1.user.username) self.assertFalse(form.is_valid())
def test_valid_new_password_form(self): data = { 'password': self.newpassword, 'password_confirm': self.newpassword } form = NewPasswordForm(data=data, identifier=self.user1.user.username) self.assertTrue(form.is_valid())
def new_password(request): """Create a new password for a user.""" try: token = request.GET["token"] except KeyError: return redirect("/") token = get_object_or_404(TokenForgotPassword, token=token) if request.method == "POST": form = NewPasswordForm(token.user.username, request.POST) if form.is_valid(): data = form.data password = data["password"] # User can't confirm his request if it is too late. if datetime.now() > token.date_end: return render(request, "member/new_password/failed.html") token.user.set_password(password) token.user.save() token.delete() return render(request, "member/new_password/success.html") else: return render(request, "member/new_password/index.html", {"form": form}) form = NewPasswordForm(identifier=token.user.username) return render(request, "member/new_password/index.html", {"form": form})
def test_password_too_long_new_password_form(self): toolong = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789-----" data = { 'password': toolong, 'password_confirm': toolong } form = NewPasswordForm(data=data, identifier=self.user1.user.username) self.assertFalse(form.is_valid())
def test_password_too_short_new_password_form(self): tooshort = "short" data = { 'password': tooshort, 'password_confirm': tooshort } form = NewPasswordForm(data=data, identifier=self.user1.user.username) self.assertFalse(form.is_valid())