implements login view
This commit is contained in:
23
api/login/views.py
Normal file
23
api/login/views.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from flask import Blueprint, current_app
|
||||
from flask_jwt_extended import jwt_required, create_access_token
|
||||
from flask_apispec import use_kwargs, marshal_with
|
||||
|
||||
from api.exceptions import BadRequestException
|
||||
import api.constants as constants
|
||||
|
||||
from .models import TokenResponse
|
||||
from .serializers import login_schema, token_response_schema
|
||||
|
||||
blueprint = Blueprint('login', __name__)
|
||||
|
||||
|
||||
@blueprint.route('', methods=['POST'])
|
||||
@jwt_required(optional=True)
|
||||
@use_kwargs(login_schema)
|
||||
@marshal_with(token_response_schema)
|
||||
def login_user(username, password, **kwargs):
|
||||
print(f'user: {username}; pass: {password}; expected:{current_app.config[constants.API_PASS]}')
|
||||
if username == constants.API_USER and password == current_app.config[constants.API_PASS]:
|
||||
return TokenResponse(create_access_token(identity=username, fresh=True))
|
||||
else:
|
||||
raise BadRequestException("Wrong combination of username and password")
|
||||
Reference in New Issue
Block a user