feat: created a base form with some validators
This commit is contained in:
39
app/reset.py
Normal file
39
app/reset.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import functools
|
||||
|
||||
from flask import (
|
||||
Blueprint, flash, g, redirect, render_template, request, session, url_for
|
||||
)
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, PasswordField, BooleanField, \
|
||||
SubmitField
|
||||
from wtforms.validators import ValidationError, DataRequired, \
|
||||
Email, EqualTo, Length
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
|
||||
|
||||
bp = Blueprint('reset', __name__, url_prefix='/reset')
|
||||
|
||||
class ResetPasswordForm(FlaskForm):
|
||||
username = StringField(label=('Username'),
|
||||
validators=[DataRequired(),
|
||||
Length(max=64)])
|
||||
currentpassword = PasswordField(label=('Current password'),
|
||||
validators=[DataRequired()])
|
||||
newpassword = PasswordField(label=('New password'),
|
||||
validators=[DataRequired(),
|
||||
Length(min=8, message='Password should be at least %(min)d characters long')],
|
||||
render_kw={"onkeyup": "validate_form()"})
|
||||
confirm_password = PasswordField(
|
||||
label=('Confirm Password'),
|
||||
validators=[DataRequired(message='* Required'),
|
||||
EqualTo('newpassword', message='Both password fields must be equal!')],
|
||||
render_kw={"onkeyup": "validate_confirm()"})
|
||||
|
||||
submit = SubmitField(label=('Change my password'), render_kw={"onclick": "validate_form()"})
|
||||
|
||||
@bp.route('/', methods=('GET', 'POST'))
|
||||
def reset():
|
||||
form = ResetPasswordForm()
|
||||
if form.validate_on_submit():
|
||||
return f'''<h1> Welcome {form.username.data} </h1>'''
|
||||
return render_template('reset.html', form=form)
|
||||
Reference in New Issue
Block a user