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

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