From 6dbb13599c33f8ad336e92038bc17d9b81ed91d4 Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Fri, 30 Jul 2021 19:39:20 +0200
Subject: [PATCH] =?UTF-8?q?mo.fields:=20P=C5=99id=C3=A1no=20NewPassword=20?=
 =?UTF-8?q?a=20RepeatPassword?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 mo/web/fields.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/mo/web/fields.py b/mo/web/fields.py
index e6f21da0..1e230509 100644
--- a/mo/web/fields.py
+++ b/mo/web/fields.py
@@ -138,3 +138,24 @@ class School(Place):
                 field.place = mo.users.validate_and_find_school(field.data)
             except mo.CheckError as e:
                 field.place_error = str(e)
+
+
+class NewPassword(wtforms.PasswordField):
+    def __init__(self, label="Nové heslo", validators=None, **kwargs):
+        super().__init__(label, validators, **kwargs)
+
+    def pre_validate(field, form):
+        if field.data:
+            if not mo.users.validate_password(field.data):
+                raise wtforms.ValidationError(mo.users.password_help)
+
+
+class RepeatPassword(wtforms.PasswordField):
+    """Pro validaci hledá ve formuláři form.new_passwd a s ním porovnává."""
+
+    def __init__(self, label="Zopakujte heslo", validators=None, **kwargs):
+        super().__init__(label, validators, **kwargs)
+
+    def pre_validate(field, form):
+        if field.data != form.new_passwd.data:
+            raise wtforms.ValidationError('Hesla se neshodují.')
-- 
GitLab