From 280ce2f1964a535dc0bdc124125b44a0f2aaaccd Mon Sep 17 00:00:00 2001 From: crunk Date: Sun, 2 Jun 2024 22:16:52 +0200 Subject: [PATCH] refactor: moved user forms to statuspengguna folder --- .../forms/forgotpasswordform.py | 15 ++++++++ verse/statuspengguna/forms/loginform.py | 18 +++++++++ verse/statuspengguna/forms/registerform.py | 38 +++++++++++++++++++ .../statuspengguna/forms/resetpasswordform.py | 23 +++++++++++ verse/statuspengguna/loginuser.py | 2 +- verse/statuspengguna/registeruser.py | 2 +- verse/statuspengguna/resetpassword.py | 2 +- 7 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 verse/statuspengguna/forms/forgotpasswordform.py create mode 100644 verse/statuspengguna/forms/loginform.py create mode 100644 verse/statuspengguna/forms/registerform.py create mode 100644 verse/statuspengguna/forms/resetpasswordform.py diff --git a/verse/statuspengguna/forms/forgotpasswordform.py b/verse/statuspengguna/forms/forgotpasswordform.py new file mode 100644 index 0000000..385327d --- /dev/null +++ b/verse/statuspengguna/forms/forgotpasswordform.py @@ -0,0 +1,15 @@ +"""Forgotten password form to help user.""" + +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField, validators +from wtforms.validators import Email, Length + + +class ForgotPasswordForm(FlaskForm): + """Forgotten password distribusiverse form class.""" + + email = StringField( + "Email address:", + validators=[validators.InputRequired(), Email(), Length(6, 64)], + ) + submit = SubmitField("Send email") diff --git a/verse/statuspengguna/forms/loginform.py b/verse/statuspengguna/forms/loginform.py new file mode 100644 index 0000000..b446850 --- /dev/null +++ b/verse/statuspengguna/forms/loginform.py @@ -0,0 +1,18 @@ +"""Login form to validate user.""" + +from flask_wtf import FlaskForm +from wtforms import PasswordField, StringField, SubmitField, validators +from wtforms.validators import Email, Length + + +class LoginForm(FlaskForm): + """Login distribusiverse form class.""" + + email = StringField( + "Email address:", + validators=[validators.InputRequired(), Email(), Length(6, 64)], + ) + password = PasswordField( + "Password:", validators=[validators.InputRequired()] + ) + submit = SubmitField("Sign In") diff --git a/verse/statuspengguna/forms/registerform.py b/verse/statuspengguna/forms/registerform.py new file mode 100644 index 0000000..89c42d6 --- /dev/null +++ b/verse/statuspengguna/forms/registerform.py @@ -0,0 +1,38 @@ +"""Register form to make a new user.""" + +from flask_wtf import FlaskForm +from wtforms import PasswordField, StringField, SubmitField, validators +from wtforms.validators import Email, EqualTo, Length + + +class RegisterForm(FlaskForm): + """Register for distribusi-verse form class""" + + username = StringField( + "Username:", + validators=[validators.InputRequired(), Length(3, 150)], + ) + + email = StringField( + "Email address:", + validators=[ + validators.InputRequired(), + Email(), + Length(6, 128), + ], + ) + + password = PasswordField( + "New password:", + validators=[validators.InputRequired(), Length(12, 72)], + ) + + confirmpassword = PasswordField( + "Confirm your password:", + validators=[ + validators.InputRequired(), + Length(12, 72), + EqualTo("password", message="Passwords must match !"), + ], + ) + submit = SubmitField("Register to Distribusi-verse") diff --git a/verse/statuspengguna/forms/resetpasswordform.py b/verse/statuspengguna/forms/resetpasswordform.py new file mode 100644 index 0000000..481cb02 --- /dev/null +++ b/verse/statuspengguna/forms/resetpasswordform.py @@ -0,0 +1,23 @@ +"""Reset Password Form form to reset a users PasswordField.""" + +from flask_wtf import FlaskForm +from wtforms import PasswordField, SubmitField, validators +from wtforms.validators import EqualTo, Length + + +class ResetPasswordForm(FlaskForm): + """ResetPassword for distribusi-verse form class""" + + password = PasswordField( + "New password:", + validators=[validators.InputRequired(), Length(12, 72)], + ) + confirmpassword = PasswordField( + "Confirm your password:", + validators=[ + validators.InputRequired(), + Length(12, 72), + EqualTo("password", message="Passwords must match !"), + ], + ) + submit = SubmitField("Reset your password") diff --git a/verse/statuspengguna/loginuser.py b/verse/statuspengguna/loginuser.py index 6f18cde..ba28c72 100644 --- a/verse/statuspengguna/loginuser.py +++ b/verse/statuspengguna/loginuser.py @@ -10,7 +10,7 @@ from flask import ( from flask_bcrypt import check_password_hash from flask_login import login_user -from forms.loginform import LoginForm +from statuspengguna.forms.loginform import LoginForm from models.user_model import User login_section = Blueprint( diff --git a/verse/statuspengguna/registeruser.py b/verse/statuspengguna/registeruser.py index e97f1ee..af1216f 100644 --- a/verse/statuspengguna/registeruser.py +++ b/verse/statuspengguna/registeruser.py @@ -11,7 +11,7 @@ from sqlalchemy.exc import ( from werkzeug.routing import BuildError from app import db -from forms.registerform import RegisterForm +from statuspengguna.forms.registerform import RegisterForm from models.user_model import User register_user = Blueprint( diff --git a/verse/statuspengguna/resetpassword.py b/verse/statuspengguna/resetpassword.py index c0288ae..a9fc1b5 100644 --- a/verse/statuspengguna/resetpassword.py +++ b/verse/statuspengguna/resetpassword.py @@ -13,7 +13,7 @@ from sqlalchemy.exc import ( from werkzeug.routing import BuildError from app import db -from forms.resetpasswordform import ResetPasswordForm +from statuspengguna.forms.resetpasswordform import ResetPasswordForm from models.user_model import User reset_password = Blueprint(