2025-10-25 20:53:48 +03:00
|
|
|
from flask import Blueprint, request, jsonify
|
2025-10-26 14:57:49 +03:00
|
|
|
from model.user import User
|
2025-10-25 11:24:31 +03:00
|
|
|
|
|
|
|
|
loginBP = Blueprint("loginapi", __name__)
|
2025-10-26 15:08:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@loginBP.route('/api/auth/login', methods = ['POST'])
|
2025-10-25 11:24:31 +03:00
|
|
|
def login():
|
2025-10-26 14:10:10 +03:00
|
|
|
if request.is_json:
|
|
|
|
|
req = request.json
|
2025-10-26 15:08:14 +03:00
|
|
|
|
|
|
|
|
email = req.get('email')
|
|
|
|
|
password = req.get('password')
|
|
|
|
|
|
|
|
|
|
if not email or not password:
|
|
|
|
|
return "Request must have email and password", 400
|
|
|
|
|
|
|
|
|
|
if len(email.strip()) < 4 or '@' not in email or '.' not in email:
|
|
|
|
|
return "Email is incorrect", 400
|
|
|
|
|
|
|
|
|
|
if len(password.strip()) < 8:
|
|
|
|
|
return "Password is too short", 400
|
|
|
|
|
|
2025-10-26 14:57:49 +03:00
|
|
|
user = User(email, password)
|
|
|
|
|
return jsonify(user.toDictionary())
|
2025-10-26 15:08:14 +03:00
|
|
|
|
2025-10-26 14:10:10 +03:00
|
|
|
else:
|
2025-10-26 15:08:14 +03:00
|
|
|
return "Request is not a json", 400
|