app route login methods POST def login if request headers get X-Reques

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
@app.route('/login', methods=['POST'])
def login():
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
email = request.form['email']
password = request.form['password']
res = db_session.query(db.Client).filter_by(email=email).first()
if res and res.check_password(password):
login_user(res)
return redirect(url_for('/index'))
return jsonify(error='Пароль не правильный или в нашей базе данных нет такого email'), 401
abort(404)