bugfix
This commit is contained in:
parent
1e0f3a408d
commit
d64fcd1d73
36
wwwroot/apply_apikey.dspy
Normal file
36
wwwroot/apply_apikey.dspy
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
debug(f'{params_kw=}')
|
||||||
|
db = DBPools()
|
||||||
|
env = request._run_ns
|
||||||
|
try:
|
||||||
|
async with get_sor_context(env, 'dapi') as sor:
|
||||||
|
orgid = await get_userorgid()
|
||||||
|
userid = await get_user()
|
||||||
|
ns = {
|
||||||
|
"id": params_kw.id,
|
||||||
|
"name": params_kw.appname,
|
||||||
|
"description": params_kw.description,
|
||||||
|
"secretkey": password_encode(uuid()),
|
||||||
|
"allowedips": params_kw.allowedips,
|
||||||
|
"orgid": orgid
|
||||||
|
}
|
||||||
|
await sor.C('downapp', ns)
|
||||||
|
ns1 = {
|
||||||
|
"id": uuid(),
|
||||||
|
"dappid": ns['id'],
|
||||||
|
"userid": userid,
|
||||||
|
"apikey": password_encode(uuid()),
|
||||||
|
"enabled_date": curDateString(),
|
||||||
|
"expired_date": '9999-12-31'
|
||||||
|
}
|
||||||
|
await sor.C('downapikey', ns1)
|
||||||
|
return {
|
||||||
|
"status": "ok"
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
return {
|
||||||
|
"status": "error",
|
||||||
|
"data": {
|
||||||
|
"message": f'{e}'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return UiError(title='create apikey', message='add apikey error')
|
||||||
36
wwwroot/downapps.dspy
Normal file
36
wwwroot/downapps.dspy
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
env = request._run_ns
|
||||||
|
userid = await get_user()
|
||||||
|
orgid = await get_userorgid()
|
||||||
|
if userid is None:
|
||||||
|
return {
|
||||||
|
"status": "error",
|
||||||
|
"data": {
|
||||||
|
"message": "need login"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
async with get_sor_context(env, 'dapi') as sor:
|
||||||
|
today = curDateString()
|
||||||
|
sql = """select a.id, a.name,b.id as apikeyid,
|
||||||
|
from downapp a, downapikey b
|
||||||
|
where a.orgid=${orgid}$
|
||||||
|
and b.userid=${userid}$
|
||||||
|
and a.id = b.dappid
|
||||||
|
and b.enabled_date <= ${today}$
|
||||||
|
and b.expired_date > ${today}$
|
||||||
|
"""
|
||||||
|
recs = await sor.sqlExe(sql, {'orgid': orgid})
|
||||||
|
return {
|
||||||
|
"status": "ok",
|
||||||
|
"data": {
|
||||||
|
"apikeys": recs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
return {
|
||||||
|
"status": "error",
|
||||||
|
"data": {
|
||||||
|
"message": f'{e},{today=}'
|
||||||
|
}
|
||||||
|
}
|
||||||
38
wwwroot/get_apikey.dspy
Normal file
38
wwwroot/get_apikey.dspy
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
debug(f'{params_kw=}')
|
||||||
|
env = request._run_ns
|
||||||
|
try:
|
||||||
|
async with get_sor_context(env, 'dapi') as sor:
|
||||||
|
orgid = await get_userorgid()
|
||||||
|
userid = await get_user()
|
||||||
|
ns = {
|
||||||
|
"id": params_kw.id,
|
||||||
|
"orgid":orgid,
|
||||||
|
"userid":userid
|
||||||
|
}
|
||||||
|
sql = """select a.*,
|
||||||
|
b.apikey
|
||||||
|
from downapp a, downapikey b
|
||||||
|
where a.id = b.dappid
|
||||||
|
and a.id = ${id}$
|
||||||
|
and a.orgid = ${orgid}$
|
||||||
|
and b.userid = ${userid}$"""
|
||||||
|
recs = await sor.sqlExe(sql, ns)
|
||||||
|
if len(recs):
|
||||||
|
r = recs[0]
|
||||||
|
return {
|
||||||
|
"status":"ok",
|
||||||
|
"data":r
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
"status": "error",
|
||||||
|
"data": {
|
||||||
|
"message": "没有找到用户apikey"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
return {
|
||||||
|
"status": "error",
|
||||||
|
"data": {
|
||||||
|
"message": f"{e}"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user