commit
5ec40b9c5b
|
@ -1,6 +1,7 @@
|
||||||
import csv
|
import csv
|
||||||
import enum
|
import enum
|
||||||
import uuid
|
import uuid
|
||||||
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
import pathlib
|
import pathlib
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
@ -22,6 +23,7 @@ from teal.resource import Resource, View
|
||||||
from ereuse_devicehub import auth
|
from ereuse_devicehub import auth
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.resources.enums import SessionType
|
from ereuse_devicehub.resources.enums import SessionType
|
||||||
|
from ereuse_devicehub.resources.user.models import Session
|
||||||
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
|
||||||
from ereuse_devicehub.resources.deliverynote.models import Deliverynote
|
from ereuse_devicehub.resources.deliverynote.models import Deliverynote
|
||||||
|
@ -336,7 +338,20 @@ class WbConfDocumentView(DeviceView):
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_token(self):
|
def get_token(self):
|
||||||
tk = [s.token for s in g.user.sessions if s.type == SessionType.Internal][0]
|
if not g.user.sessions:
|
||||||
|
ses = Session(user=g.user)
|
||||||
|
db.session.add(ses)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
tk = ''
|
||||||
|
now = time.time()
|
||||||
|
for s in g.user.sessions:
|
||||||
|
if s.type == SessionType.Internal and (s.expired == 0 or s.expired > now):
|
||||||
|
tk = s.token
|
||||||
|
break
|
||||||
|
|
||||||
|
assert tk != ''
|
||||||
|
|
||||||
token = auth.Auth.encode(tk)
|
token = auth.Auth.encode(tk)
|
||||||
return token
|
return token
|
||||||
|
|
||||||
|
|
Reference in New Issue