fix new api for iota

This commit is contained in:
Cayo Puigdefabregas 2024-01-29 18:49:02 +01:00
parent ca273285fe
commit 72c8fac29e
4 changed files with 12 additions and 29 deletions

View File

@ -95,22 +95,10 @@ class DidView(View):
if not session.get('token_dlt'):
return []
token_dlt = session.get('token_dlt')
api_dlt = app.config.get('API_DLT')
if not token_dlt or not api_dlt:
role = session.get('iota_abac_attributes', {}).get('role', '')
if not role:
return []
api = API(api_dlt, token_dlt, "ethereum")
result = api.check_user_roles()
if result.get('Status') != 200:
return []
if 'Success' not in result.get('Data', {}).get('status'):
return []
rols = result.get('Data', {}).get('data', {})
self.context['rols'] = [(k, k) for k, v in rols.items() if v]
self.context['rols'] = [(x.strip(), x.strip()) for x in role.split(",")]
def get_rol(self):
rols = self.context.get('rols', [])

View File

@ -43,7 +43,6 @@ class RegisterUserDlt:
user = User(email=email, password=password)
user.individuals.add(Person(name=name))
# import pdb; pdb.set_trace()
try:
response = register_user(api_dlt, privateKey=eth_priv_key[2:])
api_token = response.get('data', {}).get('api_token')

View File

@ -180,21 +180,13 @@ class User(UserMixin, Thing):
if not api_dlt:
return []
api = API(api_dlt, token_dlt, "ethereum")
result = api.check_user_roles()
if result.get('Status') != 200:
return []
if 'Success' not in result.get('Data', {}).get('status'):
return []
rols = result.get('Data', {}).get('data', {})
return [(k, k) for k, v in rols.items() if v]
self.get_abac_did()
role = session.get('iota_abac_attributes', {}).get('role', [])
return [(x.strip(), x.strip()) for x in role.split(",")]
def _call_abac(self, path):
abac_tk = app.config.get('ABAC_TOKEN')
abac_coockie = app.config.get('ABAC_COOKIE')
# abac_coockie = app.config.get('ABAC_COOKIE')
domain = app.config.get('ABAC_URL')
eth_pub_key = session.get('eth_pub_key')
@ -204,7 +196,7 @@ class User(UserMixin, Thing):
header = {
'Authorization': f'Bearer {abac_tk}',
'Cookie': abac_coockie
# 'Cookie': abac_coockie
}
url = f'{domain}{eth_pub_key}/{abac_path}'
return requests.get(url, headers=header)

View File

@ -28,6 +28,10 @@ class LoginView(View):
template_name = 'ereuse_devicehub/user_login.html'
def dispatch_request(self):
if session.get('_user_id'):
next_url = flask.request.args.get('next')
return flask.redirect(next_url or flask.url_for('inventory.devicelist'))
form = LoginForm()
if form.validate_on_submit():
# Login and validate the user.