29 lines
732 B
Python
29 lines
732 B
Python
from flask import Blueprint, request, jsonify
|
|
from model.user import User
|
|
|
|
auth = Blueprint("auth", __name__)
|
|
|
|
|
|
@auth.route('/login', methods = ['POST'])
|
|
def login():
|
|
if request.is_json:
|
|
req = request.json
|
|
|
|
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
|
|
|
|
user = User(email, password)
|
|
return jsonify(user.toJson())
|
|
|
|
else:
|
|
return "Request is not a json", 400
|