Files
mahssagebus-api/api/login/views.py
2021-09-30 23:00:46 +03:00

24 lines
883 B
Python

from flask import Blueprint, current_app
from flask_jwt_extended import jwt_required, create_access_token
from flask_apispec import use_kwargs, marshal_with, doc
from marshmallow import fields
from api.exceptions import BadRequestException
from api.utils import docwrap
import api.constants as constants
from .serializers import token_response_schema, login_schema
blueprint = Blueprint('login', __name__)
@docwrap('Login', None)
@blueprint.route('', methods=['POST'])
@jwt_required(optional=True)
@use_kwargs(login_schema)
@marshal_with(token_response_schema)
def login_user(username, password):
if username == constants.API_USER and password == current_app.config[constants.API_PASS]:
return {'token': create_access_token(identity=username, fresh=True, expires_delta=False)}
else:
raise BadRequestException("Wrong combination of username and password")