Skip to content
Permalink
Browse files

[#16] context property에 requested_user property 추가

  • Loading branch information...
JoMingyu committed Mar 11, 2019
1 parent 48581b6 commit d6cfa1d851cf4375084cab1e49407c54964a0025
Showing with 26 additions and 12 deletions.
  1. +23 −0 app/context.py
  2. +3 −12 app/views/user/account/refresh.py
@@ -1,4 +1,8 @@
from flask import g
from flask_jwt_extended import get_jwt_identity

from app.extensions import main_db
from app.models.user import TblUsers


class _ContextProperty:
@@ -10,5 +14,24 @@ def request_payload_object(self):
def request_payload_object(self, value):
g.request_payload_object = value

@property
def requested_user(self) -> TblUsers:
requested_user = getattr(g, 'requested_user', None)

if requested_user:
return requested_user
else:
session = main_db.session

user = TblUsers.get_first_or_abort_on_none(
session,
TblUsers.id == get_jwt_identity(),
401
)

g.requested_user = user

return user


context_property = _ContextProperty()
@@ -1,7 +1,6 @@
from flask_jwt_extended import jwt_refresh_token_required, create_access_token, get_jwt_identity
from flask_jwt_extended import jwt_refresh_token_required, create_access_token

from app.extensions import main_db
from app.models.user import TblUsers
from app.context import context_property
from app.views.base import BaseResource


@@ -11,15 +10,7 @@ def get(self):
"""
Access token refresh API
"""

session = main_db.session
identity = get_jwt_identity()

user: TblUsers = TblUsers.get_first_or_abort_on_none(
session,
TblUsers.id == identity,
code=401
)
user = context_property.requested_user

return {
'accessToken': create_access_token(user.id)

0 comments on commit d6cfa1d

Please sign in to comment.
You can’t perform that action at this time.