feat/db-init #3
+18
-9
@@ -1,19 +1,28 @@
|
||||
from flask import Blueprint, request, jsonify
|
||||
from model.user import User
|
||||
from utils.createLogger import createLogger
|
||||
|
||||
loginBP = Blueprint("loginapi", __name__)
|
||||
log = createLogger("LoginAPI")
|
||||
@loginBP.route('/api/login', methods = ['POST'])
|
||||
|
||||
|
||||
@loginBP.route('/api/auth/login', methods = ['POST'])
|
||||
def login():
|
||||
if request.is_json:
|
||||
req = request.json
|
||||
email = req['email']
|
||||
password = req['password']
|
||||
#if(isvalid(email, password)):
|
||||
|
||||
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)
|
||||
log.debug("Respons is sended")
|
||||
return jsonify(user.toDictionary())
|
||||
|
||||
else:
|
||||
log.error("Request is not a JSON")
|
||||
return "Request is not a json", 500
|
||||
return "Request is not a json", 400
|
||||
|
||||
Reference in New Issue
Block a user