Browse Source

Added logout endpoint and documentation

pull/5/head
Kenneth Bruen 3 years ago
parent
commit
f19aad8d3e
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 19
      server/foxbank_server/apis/login.py

19
server/foxbank_server/apis/login.py

@ -26,6 +26,7 @@ class Login(MethodView):
@bp.response(401, returns.ErrorSchema, description='Login failure') @bp.response(401, returns.ErrorSchema, description='Login failure')
@bp.response(200, LoginSuccessSchema) @bp.response(200, LoginSuccessSchema)
def post(self, username: str, code: str): def post(self, username: str, code: str):
"""Login via username and TOTP code"""
user: User | None = get_user(username=username) user: User | None = get_user(username=username)
if user is None: if user is None:
return returns.INVALID_DETAILS return returns.INVALID_DETAILS
@ -37,6 +38,23 @@ class Login(MethodView):
token = ram_db.login_user(user.id) token = ram_db.login_user(user.id)
return returns.success(token=token) return returns.success(token=token)
@ensure_logged_in
@bp.doc(security=[{'Token': []}])
@bp.response(401, returns.ErrorSchema, description='Login failure')
@bp.response(204)
def delete(self):
"""Logout"""
ram_db.logout_user(decorators.token)
@bp.post('/logout')
@ensure_logged_in
@bp.doc(security=[{'Token': []}])
@bp.response(401, returns.ErrorSchema, description='Login failure')
@bp.response(204)
def logout_route():
"""Logout"""
ram_db.logout_user(decorators.token)
@bp.route('/whoami') @bp.route('/whoami')
class WhoAmI(MethodView): class WhoAmI(MethodView):
class WhoAmISchema(returns.SuccessSchema): class WhoAmISchema(returns.SuccessSchema):
@ -47,6 +65,7 @@ class WhoAmI(MethodView):
@bp.doc(security=[{'Token': []}]) @bp.doc(security=[{'Token': []}])
@ensure_logged_in @ensure_logged_in
def get(self): def get(self):
"""Get information about currently logged in user"""
user: User | None = get_user(user_id=decorators.user_id) user: User | None = get_user(user_id=decorators.user_id)
if user is not None: if user is not None:
user = user.to_json() user = user.to_json()

Loading…
Cancel
Save