add register devices
This commit is contained in:
parent
e7cf069a33
commit
789eb1b526
|
@ -61,7 +61,7 @@ class LoginForm(FlaskForm):
|
||||||
if not user.is_active:
|
if not user.is_active:
|
||||||
self.form_errors.append(self.error_messages['inactive'])
|
self.form_errors.append(self.error_messages['inactive'])
|
||||||
|
|
||||||
if 'trublo' not in app.blueprints.keys():
|
if 'trublo' in app.blueprints.keys():
|
||||||
token_dlt = (
|
token_dlt = (
|
||||||
user.get_dlt_keys(self.password.data).get('data', {}).get('api_token')
|
user.get_dlt_keys(self.password.data).get('data', {}).get('api_token')
|
||||||
)
|
)
|
||||||
|
|
|
@ -116,6 +116,7 @@ class SnapshotMixin:
|
||||||
snapshot.severity = Severity.Warning
|
snapshot.severity = Severity.Warning
|
||||||
|
|
||||||
self.is_server_erase(snapshot)
|
self.is_server_erase(snapshot)
|
||||||
|
snapshot.device.register_dlt()
|
||||||
|
|
||||||
return snapshot
|
return snapshot
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import copy
|
import copy
|
||||||
|
import hashlib
|
||||||
import pathlib
|
import pathlib
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from fractions import Fraction
|
from fractions import Fraction
|
||||||
|
@ -9,7 +10,9 @@ from typing import Dict, List, Set
|
||||||
from boltons import urlutils
|
from boltons import urlutils
|
||||||
from citext import CIText
|
from citext import CIText
|
||||||
from ereuse_utils.naming import HID_CONVERSION_DOC, Naming
|
from ereuse_utils.naming import HID_CONVERSION_DOC, Naming
|
||||||
from flask import g, request
|
from ereuseapi.methods import API
|
||||||
|
from flask import current_app as app
|
||||||
|
from flask import g, request, session
|
||||||
from more_itertools import unique_everseen
|
from more_itertools import unique_everseen
|
||||||
from sqlalchemy import BigInteger, Boolean, Column
|
from sqlalchemy import BigInteger, Boolean, Column
|
||||||
from sqlalchemy import Enum as DBEnum
|
from sqlalchemy import Enum as DBEnum
|
||||||
|
@ -816,6 +819,20 @@ class Device(Thing):
|
||||||
}
|
}
|
||||||
return types.get(self.type, '')
|
return types.get(self.type, '')
|
||||||
|
|
||||||
|
def register_dlt(self):
|
||||||
|
if 'trublo' not in app.blueprints.keys() or not self.hid:
|
||||||
|
return
|
||||||
|
|
||||||
|
chid = hashlib.sha3_256(self.hid.encode('utf-8')).hexdigest()
|
||||||
|
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)
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
return self.id < other.id
|
return self.id < other.id
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,9 @@ class User(UserMixin, Thing):
|
||||||
|
|
||||||
from modules.trublo.utils import decrypt
|
from modules.trublo.utils import decrypt
|
||||||
|
|
||||||
|
if not self.api_keys_dlt:
|
||||||
|
return {}
|
||||||
|
|
||||||
data = decrypt(password, self.api_keys_dlt)
|
data = decrypt(password, self.api_keys_dlt)
|
||||||
return json.loads(data)
|
return json.loads(data)
|
||||||
|
|
||||||
|
|
Reference in New Issue