simplify get_token method

This commit is contained in:
Cayo Puigdefabregas 2021-04-15 21:21:41 +02:00
parent 3f423e7712
commit 70188f43a2
1 changed files with 4 additions and 21 deletions

View File

@ -19,8 +19,8 @@ from flask.json import jsonify
from teal.cache import cache from teal.cache import cache
from teal.resource import Resource, View from teal.resource import Resource, View
from ereuse_devicehub import auth
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.resources.user.models import Session
from ereuse_devicehub.resources.enums import SessionType from ereuse_devicehub.resources.enums import SessionType
from ereuse_devicehub.resources.action import models as evs from ereuse_devicehub.resources.action import models as evs
from ereuse_devicehub.resources.device import models as devs from ereuse_devicehub.resources.device import models as devs
@ -339,26 +339,9 @@ class WbConfDocumentView(DeviceView):
return output return output
def get_token(self): def get_token(self):
internal_session = Session.query.filter_by(user_id=g.user.id, tk = [s.token for s in g.user.sessions if s.type == SessionType.Internal][0]
type=SessionType.Internal).first() token = auth.Auth.encode(tk)
if not internal_session: return token
internal_session = Session(user_id=g.user.id, type=SessionType.Internal)
db.session.add(internal_session)
db.session.commit()
return internal_session.token
# TODO @cayop for when in others iterations we need implement external token
# external_session = Session.query.filter_by(user_id=g.user.id,
# type=SessionType.Internal).first()
# if not external_session:
# external_session = Session(user_id=g.user.id, type=SessionType.External)
# external_session = Session(user_id=g.user.id, type=SessionType.External)
# db.session.add(external_session)
# db.session.commit()
# return external_session.token
class DocumentDef(Resource): class DocumentDef(Resource):