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