fix new api for iota
This commit is contained in:
parent
ca273285fe
commit
72c8fac29e
|
@ -95,22 +95,10 @@ class DidView(View):
|
||||||
if not session.get('token_dlt'):
|
if not session.get('token_dlt'):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
token_dlt = session.get('token_dlt')
|
role = session.get('iota_abac_attributes', {}).get('role', '')
|
||||||
api_dlt = app.config.get('API_DLT')
|
if not role:
|
||||||
if not token_dlt or not api_dlt:
|
|
||||||
return []
|
return []
|
||||||
|
self.context['rols'] = [(x.strip(), x.strip()) for x in role.split(",")]
|
||||||
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]
|
|
||||||
|
|
||||||
def get_rol(self):
|
def get_rol(self):
|
||||||
rols = self.context.get('rols', [])
|
rols = self.context.get('rols', [])
|
||||||
|
|
|
@ -43,7 +43,6 @@ class RegisterUserDlt:
|
||||||
user = User(email=email, password=password)
|
user = User(email=email, password=password)
|
||||||
user.individuals.add(Person(name=name))
|
user.individuals.add(Person(name=name))
|
||||||
|
|
||||||
# import pdb; pdb.set_trace()
|
|
||||||
try:
|
try:
|
||||||
response = register_user(api_dlt, privateKey=eth_priv_key[2:])
|
response = register_user(api_dlt, privateKey=eth_priv_key[2:])
|
||||||
api_token = response.get('data', {}).get('api_token')
|
api_token = response.get('data', {}).get('api_token')
|
||||||
|
|
|
@ -180,21 +180,13 @@ class User(UserMixin, Thing):
|
||||||
if not api_dlt:
|
if not api_dlt:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
api = API(api_dlt, token_dlt, "ethereum")
|
self.get_abac_did()
|
||||||
|
role = session.get('iota_abac_attributes', {}).get('role', [])
|
||||||
result = api.check_user_roles()
|
return [(x.strip(), x.strip()) for x in role.split(",")]
|
||||||
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]
|
|
||||||
|
|
||||||
def _call_abac(self, path):
|
def _call_abac(self, path):
|
||||||
abac_tk = app.config.get('ABAC_TOKEN')
|
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')
|
domain = app.config.get('ABAC_URL')
|
||||||
eth_pub_key = session.get('eth_pub_key')
|
eth_pub_key = session.get('eth_pub_key')
|
||||||
|
|
||||||
|
@ -204,7 +196,7 @@ class User(UserMixin, Thing):
|
||||||
|
|
||||||
header = {
|
header = {
|
||||||
'Authorization': f'Bearer {abac_tk}',
|
'Authorization': f'Bearer {abac_tk}',
|
||||||
'Cookie': abac_coockie
|
# 'Cookie': abac_coockie
|
||||||
}
|
}
|
||||||
url = f'{domain}{eth_pub_key}/{abac_path}'
|
url = f'{domain}{eth_pub_key}/{abac_path}'
|
||||||
return requests.get(url, headers=header)
|
return requests.get(url, headers=header)
|
||||||
|
|
|
@ -28,6 +28,10 @@ class LoginView(View):
|
||||||
template_name = 'ereuse_devicehub/user_login.html'
|
template_name = 'ereuse_devicehub/user_login.html'
|
||||||
|
|
||||||
def dispatch_request(self):
|
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()
|
form = LoginForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
# Login and validate the user.
|
# Login and validate the user.
|
||||||
|
|
Reference in New Issue