31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
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"))
|