diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 7175ab06..8796efa6 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -19,8 +19,8 @@ from flask.json import jsonify from teal.cache import cache from teal.resource import Resource, View +from ereuse_devicehub import auth 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.action import models as evs from ereuse_devicehub.resources.device import models as devs @@ -339,26 +339,9 @@ class WbConfDocumentView(DeviceView): return output def get_token(self): - internal_session = Session.query.filter_by(user_id=g.user.id, - type=SessionType.Internal).first() - if not internal_session: - 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 + tk = [s.token for s in g.user.sessions if s.type == SessionType.Internal][0] + token = auth.Auth.encode(tk) + return token class DocumentDef(Resource):