From 88b13961fe61d5fe9fd9e35b6058ba9667ac32f7 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 24 Nov 2022 17:54:25 +0100 Subject: [PATCH] add permitons to new users --- ereuse_devicehub/config.py | 1 + ereuse_devicehub/resources/user/models.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ereuse_devicehub/config.py b/ereuse_devicehub/config.py index 4dd3f12e..9eff3042 100644 --- a/ereuse_devicehub/config.py +++ b/ereuse_devicehub/config.py @@ -95,3 +95,4 @@ class DevicehubConfig(Config): MAIL_USE_TLS = config('MAIL_USE_TLS', True) MAIL_DEFAULT_SENDER = config('MAIL_DEFAULT_SENDER', '') API_DLT = config('API_DLT', None) + KEYUSER1 = config('KEYUSER1', None) diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index efb569e8..7373cb3b 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -3,6 +3,7 @@ from uuid import uuid4 from citext import CIText from flask import current_app as app +from flask import session from flask_login import UserMixin from sqlalchemy import BigInteger, Boolean, Column, Sequence from sqlalchemy.dialects.postgresql import UUID @@ -127,6 +128,22 @@ class User(UserMixin, Thing): data = json.dumps(data) self.api_keys_dlt = encrypt(password, data) + def allow_permitions(self, password): + if 'trublo' not in app.blueprints.keys(): + return + + from ereuseapi.methods import API + + target_user = session.get('token_dlt', '.').split(".")[0] + keyUser1 = app.config.get('KEYUSER1') + api_dlt = app.config.get('API_DLT') + if not keyUser1 or api_dlt: + return + + apiUser1 = API(api_dlt, keyUser1, "ethereum") + + apiUser1.issue_credential("Operator", target_user) + class UserInventory(db.Model): """Relationship between users and their inventories."""