lab-2/app/orders/user.py

31 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from flask import Blueprint, redirect, render_template, request, url_for
from app.services.user import create_user
user_bp = Blueprint("user", __name__)
@user_bp.route("/register", methods=["GET", "POST"])
def register():
error = None
success = None
if request.method == "POST":
username = request.form.get("username", "").strip()
password = request.form.get("password", "").strip()
if not username or not password:
error = "Введите логин и пароль."
elif len(password) < 4:
error = "Пароль должен быть не короче 4 символов."
elif create_user(username=username, password=password):
success = "Регистрация успешна. Теперь можно оформлять заказы."
else:
error = "Пользователь с таким логином уже существует."
return render_template("register.html", error=error, success=success)
@user_bp.route("/register/success")
def register_success():
return redirect(url_for("user.register"))