Merge branch 'master' of git.kaiyuancloud.cn:yumoqing/rbac
This commit is contained in:
commit
93f536e087
@ -1,17 +1,20 @@
|
|||||||
{
|
{
|
||||||
"models_dir": "${HOME}$/py/rbac/models",
|
|
||||||
"output_dir": "${HOME}$/py/sage/wwwroot/_a/permission",
|
|
||||||
"dbname": "sage",
|
|
||||||
"tblname": "permission",
|
"tblname": "permission",
|
||||||
|
"uitype":"tree",
|
||||||
"title":"权限",
|
"title":"权限",
|
||||||
"params": {
|
"params":{
|
||||||
"browserfields": {
|
"idField":"id",
|
||||||
"exclouded": ["id"],
|
"textField":"name",
|
||||||
"cwidth": {}
|
"editable":true,
|
||||||
},
|
"browserfields":{
|
||||||
"editexclouded": [
|
"alters":{}
|
||||||
"id"
|
},
|
||||||
],
|
"edit_exclouded_fields":[],
|
||||||
"record_toolbar": null
|
"parentField":"parentid",
|
||||||
}
|
"toolbar":{
|
||||||
|
},
|
||||||
|
"binds":[
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
{
|
{
|
||||||
"models_dir": "${HOME}$/py/rbac/models",
|
|
||||||
"output_dir": "${HOME}$/py/sage/wwwroot/_a/users",
|
|
||||||
"dbname": "sage",
|
|
||||||
"tblname": "users",
|
"tblname": "users",
|
||||||
"title":"用户",
|
"title":"用户",
|
||||||
"params": {
|
"params": {
|
||||||
"sortby":"username",
|
"sortby":"username",
|
||||||
|
"confidential_fields":["password"],
|
||||||
"logined_userorgid":"orgid",
|
"logined_userorgid":"orgid",
|
||||||
"browserfields": {
|
"browserfields": {
|
||||||
"exclouded": ["id", "password", "orgid", "nick_name" ],
|
"exclouded": ["id", "password", "orgid", "nick_name" ],
|
||||||
|
@ -9,6 +9,7 @@ from appPublic.log import debug, exception
|
|||||||
from appPublic.dictObject import DictObject
|
from appPublic.dictObject import DictObject
|
||||||
from appPublic.uniqueID import getID
|
from appPublic.uniqueID import getID
|
||||||
from ahserver.auth_api import AuthAPI, user_login
|
from ahserver.auth_api import AuthAPI, user_login
|
||||||
|
from ahserver.globalEnv import password_encode
|
||||||
from ahserver.serverenv import ServerEnv, get_serverenv, set_serverenv
|
from ahserver.serverenv import ServerEnv, get_serverenv, set_serverenv
|
||||||
import jwt
|
import jwt
|
||||||
|
|
||||||
@ -55,7 +56,8 @@ async def get_user_roles(userid):
|
|||||||
roles.append(r.name)
|
roles.append(r.name)
|
||||||
return roles
|
return roles
|
||||||
|
|
||||||
async def get_owner_orgid(sor):
|
async def get_owner_orgid(sor, *args):
|
||||||
|
debug('uyyyyyyyyyyyyyyyy')
|
||||||
global ownerid
|
global ownerid
|
||||||
if ownerid:
|
if ownerid:
|
||||||
return ownerid
|
return ownerid
|
||||||
@ -66,16 +68,6 @@ async def get_owner_orgid(sor):
|
|||||||
ownerid = recs[0].orgid
|
ownerid = recs[0].orgid
|
||||||
return ownerid
|
return ownerid
|
||||||
|
|
||||||
def mypassword(passwd):
|
|
||||||
config = getConfig()
|
|
||||||
key = config.password_key or default_password_key
|
|
||||||
return password(passwd, key = key)
|
|
||||||
|
|
||||||
def myunpassword(passwd):
|
|
||||||
config = getConfig()
|
|
||||||
key = config.password_key or default_password_key
|
|
||||||
return unpassword(passwd)
|
|
||||||
|
|
||||||
async def create_org(sor, ns):
|
async def create_org(sor, ns):
|
||||||
await sor.C('organization', ns)
|
await sor.C('organization', ns)
|
||||||
otns = {
|
otns = {
|
||||||
@ -100,6 +92,7 @@ async def register_user(sor, ns):
|
|||||||
if ns.password != ns.cfm_password:
|
if ns.password != ns.cfm_password:
|
||||||
debug('password not match')
|
debug('password not match')
|
||||||
return False
|
return False
|
||||||
|
ns.password = password_encode(ns.password)
|
||||||
id = getID()
|
id = getID()
|
||||||
ns.id = id
|
ns.id = id
|
||||||
ns.orgid = id
|
ns.orgid = id
|
||||||
@ -111,8 +104,6 @@ async def register_user(sor, ns):
|
|||||||
def load_rbac():
|
def load_rbac():
|
||||||
AuthAPI.checkUserPermission = objcheckperm
|
AuthAPI.checkUserPermission = objcheckperm
|
||||||
env = ServerEnv()
|
env = ServerEnv()
|
||||||
env.password = mypassword
|
|
||||||
env.unpassword = myunpassword
|
|
||||||
env.get_user_roles = get_user_roles
|
env.get_user_roles = get_user_roles
|
||||||
env.check_user_password = checkUserPassword
|
env.check_user_password = checkUserPassword
|
||||||
env.register_user = register_user
|
env.register_user = register_user
|
||||||
@ -145,7 +136,7 @@ async def getAuthenticationUserid(sor, request):
|
|||||||
auther = BasicAuth('x')
|
auther = BasicAuth('x')
|
||||||
m = auther.decode(auth)
|
m = auther.decode(auth)
|
||||||
username = m.login
|
username = m.login
|
||||||
password = mypassword(m.password)
|
password = password_encode(m.password)
|
||||||
sql = "select * from users where username=${username}$ and password=${password}$"
|
sql = "select * from users where username=${username}$ and password=${password}$"
|
||||||
recs = await sor.sqlExe(sql, {'username':username,'password':password})
|
recs = await sor.sqlExe(sql, {'username':username,'password':password})
|
||||||
if len(recs) < 1:
|
if len(recs) < 1:
|
||||||
@ -172,8 +163,7 @@ right join userrole c on b.roleid = c.roleid
|
|||||||
where c.userid = ${userid}$
|
where c.userid = ${userid}$
|
||||||
"""
|
"""
|
||||||
|
|
||||||
rf = RegisterFunction()
|
dbname = await get_dbname()
|
||||||
dbname = await rf.exe('get_module_dbname', 'rbac')
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext(dbname) as sor:
|
async with db.sqlorContext(dbname) as sor:
|
||||||
perms = await sor.R('permission', {'path':path})
|
perms = await sor.R('permission', {'path':path})
|
||||||
|
@ -9,6 +9,5 @@ async with db.sqlorContext(dbname) as sor:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
fe = format_exc()
|
fe = format_exc()
|
||||||
exception(f'{e=}\n{fe}')
|
exception(f'{e=}\n{fe}')
|
||||||
|
|
||||||
return UiMessage(title="Success", message="register success")
|
return UiMessage(title="Success", message="register success")
|
||||||
return UiError(title='Error', message="register failed")
|
return UiError(title='Error', message="register failed")
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
|
|
||||||
debug(f'{params_kw=}, {password=}')
|
debug(f'{params_kw=}, {password=}')
|
||||||
await rfexe('password', params_kw)
|
|
||||||
ns = {
|
ns = {
|
||||||
"username":params_kw.username,
|
"username":params_kw.username,
|
||||||
"password":params_kw.password
|
"password":password_encode(params_kw.password)
|
||||||
}
|
}
|
||||||
|
|
||||||
info(f'{ns=}')
|
info(f'{ns=}')
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
"width":"70%"
|
"width":"70%"
|
||||||
},
|
},
|
||||||
"items":[
|
"items":[
|
||||||
{% if 'customer' in get_user_roles(get_user()) %}
|
{% if 'customer.customer' in get_user_roles(get_user()) %}
|
||||||
{
|
{
|
||||||
"name":"recharge",
|
"name":"recharge",
|
||||||
"label":"充值",
|
"label":"充值",
|
||||||
@ -17,7 +17,7 @@
|
|||||||
{
|
{
|
||||||
"name":"myacc",
|
"name":"myacc",
|
||||||
"label":"我的账户",
|
"label":"我的账户",
|
||||||
"url":"{{entire_url('myaccout')}}"
|
"url":"{{entire_url('myaccount')}}"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name":"mybill",
|
"name":"mybill",
|
||||||
|
Loading…
Reference in New Issue
Block a user