Skip to content

Commit 2bc96f1

Browse files
authored
Merge pull request #165 from jimasuen/fix-usermanager
Fixes to user_manager.py
2 parents 4bc4c3c + 487fd22 commit 2bc96f1

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

pylnbits/user_manager.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
import logging
33

4+
import urllib.parse
5+
46
from aiohttp.client import ClientSession
57

68
from pylnbits.utils import delete_url, get_url, post_url
@@ -52,7 +54,7 @@ async def get_users(self):
5254
upath = "/usermanager/api/v1/users"
5355
path = self._lnbits_url + upath
5456
res = await get_url(session=self._session, path=path,
55-
headers=self._invoice_headers)
57+
headers=self._admin_headers)
5658
return res
5759
except Exception as e:
5860
logger.info(e)
@@ -86,7 +88,7 @@ async def get_wallets(self, user_id):
8688
wpath = "/usermanager/api/v1/wallets/" + user_id
8789
path = self._lnbits_url + wpath
8890
res = await get_url(session=self._session, path=path,
89-
headers=self._invoice_headers)
91+
headers=self._admin_headers)
9092
return res
9193
except Exception as e:
9294
logger.info(e)
@@ -120,7 +122,7 @@ async def post_user_initial(self, admin_id, user_name, wallet_name):
120122
"wallet_name": wallet_name}
121123
jbody = json.dumps(body)
122124
res = await post_url(session=self._session, path=path,
123-
headers=self._invoice_headers, body=jbody)
125+
headers=self._admin_headers, body=jbody)
124126
return res
125127
except Exception as e:
126128
logger.info(e)
@@ -144,7 +146,7 @@ async def post_wallet(self, user_id, wallet_name, admin_id):
144146
"admin_id": admin_id}
145147
jbody = json.dumps(body)
146148
res = await post_url(session=self._session,
147-
path=path, headers=self._invoice_headers, body=jbody)
149+
path=path, headers=self._admin_headers, body=jbody)
148150
return res
149151
except Exception as e:
150152
logger.info(e)
@@ -158,7 +160,7 @@ async def delete_user(self, user_id):
158160
tpath = "/usermanager/api/v1/users/" + user_id
159161
path = self._lnbits_url + tpath
160162
res = await delete_url(session=self._session,
161-
path=path, headers=self._invoice_headers)
163+
path=path, headers=self._admin_headers)
162164
return res
163165
except Exception as e:
164166
logger.info(e)
@@ -172,26 +174,23 @@ async def delete_wallet(self, wallet_id):
172174
tpath = "/usermanager/api/v1/wallets/" + wallet_id
173175
path = self._lnbits_url + tpath
174176
res = await delete_url(session=self._session,
175-
path=path, headers=self._invoice_headers)
177+
path=path, headers=self._admin_headers)
176178
return res
177179
except Exception as e:
178180
logger.info(e)
179181
return e
180182

181-
# temporarily use this to activate extensions:
182-
# https://yourdomain.com/extensions?usr=89.....&enable=lnurlp
183-
# unclear why curl doesn't work ?
184-
async def post_activate_ext(self, user_id: str, extension: str, active: int):
183+
async def post_activate_ext(self, user_id: str, extension: str, active: bool):
185184
"""
186185
activates an extension for a user created by User Manager Extension
187186
"""
188187
try:
189188
tpath = "/usermanager/api/v1/extensions"
190-
path = self._lnbits_url + tpath
191-
body = {"userid": user_id, "extension": extension, "active": active}
192-
jbody = json.dumps(body)
189+
params = {"extension": extension, "userid": user_id, "active": active}
190+
query_params = urllib.parse.urlencode(params)
191+
path = self._lnbits_url + tpath + "?" + query_params
193192
res = await post_url(session=self._session, path=path,
194-
headers=self._invoice_headers, body=jbody)
193+
headers=self._invoice_headers, body="")
195194
return res
196195
except Exception as e:
197196
logger.info(e)

0 commit comments

Comments
 (0)