fix user register
This commit is contained in:
parent
a0e63b2ae9
commit
8c979d7741
|
@ -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')
|
|
@ -831,15 +831,19 @@ class Device(Thing):
|
|||
if 'trublo' not in app.blueprints.keys() or not self.hid:
|
||||
return
|
||||
|
||||
if not session.get('token_dlt'):
|
||||
return
|
||||
|
||||
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')
|
||||
if not token_dlt or not api_dlt:
|
||||
return
|
||||
|
||||
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):
|
||||
return self.id < other.id
|
||||
|
|
|
@ -51,6 +51,7 @@ class Lot(Thing):
|
|||
primaryjoin=lambda: Lot.id == LotParent.child_id,
|
||||
secondaryjoin=lambda: LotParent.parent_id == Lot.id,
|
||||
cascade='refresh-expire', # propagate changes outside ORM
|
||||
sync_backref=False,
|
||||
backref=db.backref(
|
||||
'children',
|
||||
viewonly=True,
|
||||
|
|
|
@ -105,11 +105,13 @@ class User(UserMixin, Thing):
|
|||
|
||||
from modules.trublo.utils import encrypt
|
||||
|
||||
# import pdb; pdb.set_trace()
|
||||
api_dlt = app.config.get('API_DLT')
|
||||
data = register_user(api_dlt)
|
||||
api_token = data.get('data', {}).get('api_token')
|
||||
data = json.dumps(data)
|
||||
self.api_keys_dlt = encrypt(password, data)
|
||||
return data.get('data', {}).get('api_token')
|
||||
return api_token
|
||||
|
||||
def get_dlt_keys(self, password):
|
||||
if 'trublo' not in app.blueprints.keys():
|
||||
|
@ -117,6 +119,8 @@ class User(UserMixin, Thing):
|
|||
|
||||
from modules.trublo.utils import decrypt
|
||||
|
||||
# import pdb; pdb.set_trace()
|
||||
|
||||
if not self.api_keys_dlt:
|
||||
return {}
|
||||
|
||||
|
|
Reference in New Issue