usermanager working
This commit is contained in:
parent
f4dfc1b689
commit
04462f337f
|
@ -10,31 +10,27 @@ from lnbits.core.crud import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
from .models import Users, Wallets
|
from .models import Users, Wallets, CreateUserData
|
||||||
|
|
||||||
|
|
||||||
### Users
|
### Users
|
||||||
|
|
||||||
|
|
||||||
async def create_usermanager_user(
|
async def create_usermanager_user(
|
||||||
user_name: str,
|
data: CreateUserData
|
||||||
wallet_name: str,
|
|
||||||
admin_id: str,
|
|
||||||
email: Optional[str] = None,
|
|
||||||
password: Optional[str] = None,
|
|
||||||
) -> Users:
|
) -> Users:
|
||||||
account = await create_account()
|
account = await create_account()
|
||||||
user = await get_user(account.id)
|
user = await get_user(account.id)
|
||||||
assert user, "Newly created user couldn't be retrieved"
|
assert user, "Newly created user couldn't be retrieved"
|
||||||
|
|
||||||
wallet = await create_wallet(user_id=user.id, wallet_name=wallet_name)
|
wallet = await create_wallet(user_id=user.id, wallet_name=data.wallet_name)
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO usermanager.users (id, name, admin, email, password)
|
INSERT INTO usermanager.users (id, name, admin, email, password)
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(user.id, user_name, admin_id, email, password),
|
(user.id, data.user_name, data.admin_id, data.email, data.password),
|
||||||
)
|
)
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
|
@ -42,7 +38,7 @@ async def create_usermanager_user(
|
||||||
INSERT INTO usermanager.wallets (id, admin, name, "user", adminkey, inkey)
|
INSERT INTO usermanager.wallets (id, admin, name, "user", adminkey, inkey)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(wallet.id, admin_id, wallet_name, user.id, wallet.adminkey, wallet.inkey),
|
(wallet.id, data.admin_id, data.wallet_name, user.id, wallet.adminkey, wallet.inkey),
|
||||||
)
|
)
|
||||||
|
|
||||||
user_created = await get_usermanager_user(user.id)
|
user_created = await get_usermanager_user(user.id)
|
||||||
|
@ -59,6 +55,7 @@ async def get_usermanager_users(user_id: str) -> List[Users]:
|
||||||
rows = await db.fetchall(
|
rows = await db.fetchall(
|
||||||
"SELECT * FROM usermanager.users WHERE admin = ?", (user_id,)
|
"SELECT * FROM usermanager.users WHERE admin = ?", (user_id,)
|
||||||
)
|
)
|
||||||
|
|
||||||
return [Users(**row) for row in rows]
|
return [Users(**row) for row in rows]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ class CreateUserData(BaseModel):
|
||||||
user_name: str = Query(...)
|
user_name: str = Query(...)
|
||||||
wallet_name: str = Query(...)
|
wallet_name: str = Query(...)
|
||||||
admin_id: str = Query(...)
|
admin_id: str = Query(...)
|
||||||
email: str = Query(None)
|
email: str = Query("")
|
||||||
password: str = Query(None)
|
password: str = Query("")
|
||||||
|
|
||||||
|
|
||||||
class Users(BaseModel):
|
class Users(BaseModel):
|
||||||
|
|
|
@ -42,8 +42,8 @@
|
||||||
<code>JSON list of users</code>
|
<code>JSON list of users</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.url_root }}usermanager/api/v1/users -H "X-Api-Key: {{
|
>curl -X GET {{ request.url_root }}usermanager/api/v1/users -H
|
||||||
g.user.wallets[0].inkey }}"
|
"X-Api-Key: {{ user.wallets[0].inkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
@ -62,8 +62,9 @@
|
||||||
<code>JSON list of users</code>
|
<code>JSON list of users</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.url_root }}usermanager/api/v1/users/<user_id> -H
|
>curl -X GET {{ request.url_root
|
||||||
"X-Api-Key: {{ g.user.wallets[0].inkey }}"
|
}}usermanager/api/v1/users/<user_id> -H "X-Api-Key: {{
|
||||||
|
user.wallets[0].inkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
@ -84,8 +85,9 @@
|
||||||
<code>JSON wallet data</code>
|
<code>JSON wallet data</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.url_root }}usermanager/api/v1/wallets/<user_id> -H
|
>curl -X GET {{ request.url_root
|
||||||
"X-Api-Key: {{ g.user.wallets[0].inkey }}"
|
}}usermanager/api/v1/wallets/<user_id> -H "X-Api-Key: {{
|
||||||
|
user.wallets[0].inkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
@ -106,8 +108,9 @@
|
||||||
<code>JSON a wallets transactions</code>
|
<code>JSON a wallets transactions</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X GET {{ request.url_root }}usermanager/api/v1/wallets<wallet_id> -H
|
>curl -X GET {{ request.url_root
|
||||||
"X-Api-Key: {{ g.user.wallets[0].inkey }}"
|
}}usermanager/api/v1/wallets<wallet_id> -H "X-Api-Key: {{
|
||||||
|
user.wallets[0].inkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
@ -147,11 +150,11 @@
|
||||||
>
|
>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X POST {{ request.url_root }}usermanager/api/v1/users -d '{"admin_id": "{{
|
>curl -X POST {{ request.url_root }}usermanager/api/v1/users -d
|
||||||
g.user.id }}", "wallet_name": <string>, "user_name":
|
'{"admin_id": "{{ user.id }}", "wallet_name": <string>,
|
||||||
<string>, "email": <Optional string>, "password": <
|
"user_name": <string>, "email": <Optional string>,
|
||||||
Optional string>}' -H "X-Api-Key: {{ g.user.wallets[0].inkey }}" -H
|
"password": < Optional string>}' -H "X-Api-Key: {{
|
||||||
"Content-type: application/json"
|
user.wallets[0].inkey }}" -H "Content-type: application/json"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
@ -185,10 +188,10 @@
|
||||||
>
|
>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X POST {{ request.url_root }}usermanager/api/v1/wallets -d '{"user_id":
|
>curl -X POST {{ request.url_root }}usermanager/api/v1/wallets -d
|
||||||
<string>, "wallet_name": <string>, "admin_id": "{{
|
'{"user_id": <string>, "wallet_name": <string>,
|
||||||
g.user.id }}"}' -H "X-Api-Key: {{ g.user.wallets[0].inkey }}" -H
|
"admin_id": "{{ user.id }}"}' -H "X-Api-Key: {{ user.wallets[0].inkey
|
||||||
"Content-type: application/json"
|
}}" -H "Content-type: application/json"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
@ -209,8 +212,9 @@
|
||||||
<code>{"X-Api-Key": <string>}</code>
|
<code>{"X-Api-Key": <string>}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X DELETE {{ request.url_root }}usermanager/api/v1/users/<user_id> -H
|
>curl -X DELETE {{ request.url_root
|
||||||
"X-Api-Key: {{ g.user.wallets[0].inkey }}"
|
}}usermanager/api/v1/users/<user_id> -H "X-Api-Key: {{
|
||||||
|
user.wallets[0].inkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
@ -226,8 +230,9 @@
|
||||||
<code>{"X-Api-Key": <string>}</code>
|
<code>{"X-Api-Key": <string>}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X DELETE {{ request.url_root }}usermanager/api/v1/wallets/<wallet_id>
|
>curl -X DELETE {{ request.url_root
|
||||||
-H "X-Api-Key: {{ g.user.wallets[0].inkey }}"
|
}}usermanager/api/v1/wallets/<wallet_id> -H "X-Api-Key: {{
|
||||||
|
user.wallets[0].inkey }}"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
@ -248,9 +253,9 @@
|
||||||
<code>{"X-Api-Key": <string>}</code>
|
<code>{"X-Api-Key": <string>}</code>
|
||||||
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
|
||||||
<code
|
<code
|
||||||
>curl -X POST {{ request.url_root }}usermanager/api/v1/extensions -d '{"userid":
|
>curl -X POST {{ request.url_root }}usermanager/api/v1/extensions -d
|
||||||
<string>, "extension": <string>, "active":
|
'{"userid": <string>, "extension": <string>, "active":
|
||||||
<integer>}' -H "X-Api-Key: {{ g.user.wallets[0].inkey }}" -H
|
<integer>}' -H "X-Api-Key: {{ user.wallets[0].inkey }}" -H
|
||||||
"Content-type: application/json"
|
"Content-type: application/json"
|
||||||
</code>
|
</code>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
|
|
|
@ -368,6 +368,7 @@
|
||||||
self.users = _.reject(self.users, function (obj) {
|
self.users = _.reject(self.users, function (obj) {
|
||||||
return obj.id == userId
|
return obj.id == userId
|
||||||
})
|
})
|
||||||
|
self.getWallets()
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
|
|
|
@ -10,4 +10,4 @@ from . import usermanager_ext, usermanager_renderer
|
||||||
|
|
||||||
@usermanager_ext.get("/", response_class=HTMLResponse)
|
@usermanager_ext.get("/", response_class=HTMLResponse)
|
||||||
async def index(request: Request, user: User = Depends(check_user_exists)):
|
async def index(request: Request, user: User = Depends(check_user_exists)):
|
||||||
return await render_template("usermanager/index.html", user=user.dict())
|
return usermanager_renderer().TemplateResponse("usermanager/index.html", {"request": request,"user": user.dict()})
|
||||||
|
|
|
@ -50,7 +50,7 @@ async def api_usermanager_user(user_id, wallet: WalletTypeInfo = Depends(get_key
|
||||||
# }
|
# }
|
||||||
# )
|
# )
|
||||||
async def api_usermanager_users_create(data: CreateUserData, wallet: WalletTypeInfo = Depends(get_key_type)):
|
async def api_usermanager_users_create(data: CreateUserData, wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||||
user = await create_usermanager_user(**data)
|
user = await create_usermanager_user(data)
|
||||||
full = user.dict()
|
full = user.dict()
|
||||||
full["wallets"] = [wallet.dict() for wallet in await get_usermanager_users_wallets(user.id)]
|
full["wallets"] = [wallet.dict() for wallet in await get_usermanager_users_wallets(user.id)]
|
||||||
return full
|
return full
|
||||||
|
|
Loading…
Reference in New Issue
Block a user