add register devices

This commit is contained in:
Cayo Puigdefabregas 2022-11-25 13:27:14 +01:00
parent e7cf069a33
commit 789eb1b526
4 changed files with 23 additions and 2 deletions

View File

@ -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')
) )

View File

@ -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

View File

@ -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

View File

@ -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)