fix user register

This commit is contained in:
Cayo Puigdefabregas 2022-12-01 13:03:24 +01:00
parent a0e63b2ae9
commit 8c979d7741
4 changed files with 47 additions and 3 deletions

View File

@ -0,0 +1,35 @@
"""add api_keys_dlt to user
Revision ID: 4b7f77f121bf
Revises: af038a8a388c
Create Date: 2022-12-01 10:35:36.795035
"""
import citext
import sqlalchemy as sa
from alembic import context, op
# revision identifiers, used by Alembic.
revision = '4b7f77f121bf'
down_revision = 'af038a8a388c'
branch_labels = None
depends_on = None
def get_inv():
INV = context.get_x_argument(as_dictionary=True).get('inventory')
if not INV:
raise ValueError("Inventory value is not specified")
return INV
def upgrade():
op.add_column(
'user',
sa.Column('api_keys_dlt', type_=citext.CIText(), nullable=True),
schema='common',
)
def downgrade():
op.drop_column('user', 'api_keys_dlt', schema='common')

View File

@ -831,15 +831,19 @@ class Device(Thing):
if 'trublo' not in app.blueprints.keys() or not self.hid: if 'trublo' not in app.blueprints.keys() or not self.hid:
return return
if not session.get('token_dlt'):
return
chid = hashlib.sha3_256(self.hid.encode('utf-8')).hexdigest() chid = hashlib.sha3_256(self.hid.encode('utf-8')).hexdigest()
token_dlt = session.get('token_dlt', ".").split(".")[1] token_dlt = session.get('token_dlt').split(".")[1]
api_dlt = app.config.get('API_DLT') api_dlt = app.config.get('API_DLT')
if not token_dlt or not api_dlt: if not token_dlt or not api_dlt:
return return
api = API(api_dlt, token_dlt, "ethereum") api = API(api_dlt, token_dlt, "ethereum")
result = api.register_device(chid) api.register_device(chid)
# result = api.register_device(chid)
def __lt__(self, other): def __lt__(self, other):
return self.id < other.id return self.id < other.id

View File

@ -51,6 +51,7 @@ class Lot(Thing):
primaryjoin=lambda: Lot.id == LotParent.child_id, primaryjoin=lambda: Lot.id == LotParent.child_id,
secondaryjoin=lambda: LotParent.parent_id == Lot.id, secondaryjoin=lambda: LotParent.parent_id == Lot.id,
cascade='refresh-expire', # propagate changes outside ORM cascade='refresh-expire', # propagate changes outside ORM
sync_backref=False,
backref=db.backref( backref=db.backref(
'children', 'children',
viewonly=True, viewonly=True,

View File

@ -105,11 +105,13 @@ class User(UserMixin, Thing):
from modules.trublo.utils import encrypt from modules.trublo.utils import encrypt
# import pdb; pdb.set_trace()
api_dlt = app.config.get('API_DLT') api_dlt = app.config.get('API_DLT')
data = register_user(api_dlt) data = register_user(api_dlt)
api_token = data.get('data', {}).get('api_token')
data = json.dumps(data) data = json.dumps(data)
self.api_keys_dlt = encrypt(password, data) self.api_keys_dlt = encrypt(password, data)
return data.get('data', {}).get('api_token') return api_token
def get_dlt_keys(self, password): def get_dlt_keys(self, password):
if 'trublo' not in app.blueprints.keys(): if 'trublo' not in app.blueprints.keys():
@ -117,6 +119,8 @@ class User(UserMixin, Thing):
from modules.trublo.utils import decrypt from modules.trublo.utils import decrypt
# import pdb; pdb.set_trace()
if not self.api_keys_dlt: if not self.api_keys_dlt:
return {} return {}