2021-09-27 12:03:35 +02:00
|
|
|
from flask import request, jsonify
|
|
|
|
from flask_jwt_extended import create_access_token
|
|
|
|
from flask_cors import cross_origin
|
|
|
|
|
2021-10-28 16:09:10 +02:00
|
|
|
from areas import api_v1
|
2021-09-27 12:03:35 +02:00
|
|
|
|
|
|
|
USERNAME = 'admin'
|
|
|
|
PASSWORD = 'admin'
|
|
|
|
|
|
|
|
|
|
|
|
@api_v1.route('/login', methods=['POST'])
|
|
|
|
@cross_origin()
|
|
|
|
def login():
|
|
|
|
username = request.json.get('username')
|
|
|
|
password = request.json.get('password')
|
|
|
|
|
|
|
|
if username != USERNAME or password != PASSWORD:
|
|
|
|
return jsonify({'errorMessage': 'Invalid username or password'}), 401
|
|
|
|
|
|
|
|
access_token = create_access_token(identity=username)
|
|
|
|
return jsonify({'username': USERNAME, 'access_token': access_token})
|