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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
@app.route('/login', methods=['GET', '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:
if res.check_password(password):
login_user(res)
return redirect(url_for('login'))
else:
error = 'Пароль не правильный'
else:
error = 'В базе нет такого пароля'
else:
abort(404)
return jsonify(error=error), 401