mirror of
https://github.com/Fluffy-Bean/GameExpo23.git
synced 2025-05-17 17:04:54 +00:00
make forms less problematic
This commit is contained in:
parent
f2ee0279f0
commit
b19dedc568
9 changed files with 42 additions and 43 deletions
|
@ -2,12 +2,12 @@ import re
|
|||
import uuid
|
||||
|
||||
from flask import Blueprint, render_template, request, flash, redirect, url_for
|
||||
from flask_login import login_required, login_user, logout_user, current_user
|
||||
from flask_login import login_user
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
from server.extensions import db
|
||||
from server.models import Users, Sessions
|
||||
from server.config import USER_REGEX, USER_EMAIL_REGEX
|
||||
from .extensions import db
|
||||
from .models import Users
|
||||
from .config import USER_REGEX
|
||||
|
||||
|
||||
blueprint = Blueprint("auth", __name__)
|
||||
|
@ -21,23 +21,20 @@ def auth():
|
|||
@blueprint.route("/register", methods=["POST"])
|
||||
def register():
|
||||
# Get the form data
|
||||
username = request.form["username"].strip()
|
||||
email = request.form["email"].strip()
|
||||
password = request.form["password"].strip()
|
||||
username = request.form.get("username", None).strip()
|
||||
password = request.form.get("password", None).strip()
|
||||
confirm = request.form.get("confirm", None).strip()
|
||||
|
||||
username_regex = re.compile(USER_REGEX)
|
||||
email_regex = re.compile(USER_EMAIL_REGEX)
|
||||
error = []
|
||||
|
||||
# Validate the form
|
||||
if not username or not username_regex.match(username):
|
||||
error.append("Username is invalid! Must be alphanumeric, and can contain ._-")
|
||||
if not email or not email_regex.match(email):
|
||||
error.append("Email is invalid! Must be email format")
|
||||
if not password:
|
||||
error.append("Password is empty!")
|
||||
elif len(password) < 8:
|
||||
if not password or len(password) < 8:
|
||||
error.append("Password is too short! Must be at least 8 characters long.")
|
||||
if not confirm or password != confirm:
|
||||
error.append("Passwords do not match!")
|
||||
if Users.query.filter_by(username=username).first():
|
||||
error.append("Username already exists!")
|
||||
|
||||
|
@ -50,7 +47,6 @@ def register():
|
|||
register_user = Users(
|
||||
alt_id=str(uuid.uuid4()),
|
||||
username=username,
|
||||
email=generate_password_hash(email, method="scrypt"),
|
||||
password=generate_password_hash(password, method="scrypt"),
|
||||
)
|
||||
db.session.add(register_user)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue