forked from x/icebergs
opt some
This commit is contained in:
parent
87e3cbcdde
commit
760de54c11
@ -40,7 +40,7 @@ func _role_right(m *ice.Message, userrole string, keys ...string) (ok bool) {
|
||||
ok = false // 在黑名单
|
||||
}
|
||||
}
|
||||
if m.Warn(!ok, ice.ErrNotRight, keys, USERROLE, userrole) {
|
||||
if !ok {
|
||||
return // 没有权限
|
||||
}
|
||||
if userrole == TECH {
|
||||
@ -54,7 +54,7 @@ func _role_right(m *ice.Message, userrole string, keys ...string) (ok bool) {
|
||||
ok = true // 在白名单
|
||||
}
|
||||
}
|
||||
if m.Warn(!ok, ice.ErrNotRight, keys, USERROLE, userrole) {
|
||||
if !ok {
|
||||
return // 没有权限
|
||||
}
|
||||
if userrole == VOID {
|
||||
|
@ -115,5 +115,8 @@ func UserZone(m *ice.Message, username ice.Any) (zone string) {
|
||||
return UserInfo(m, username, USERZONE, ice.MSG_USERZONE)
|
||||
}
|
||||
func UserLogin(m *ice.Message, username, password string) bool {
|
||||
m.Option(ice.MSG_USERROLE, VOID)
|
||||
m.Option(ice.MSG_USERNAME, "")
|
||||
m.Option(ice.MSG_USERNICK, "")
|
||||
return m.Cmdy(USER, LOGIN, username, password).Option(ice.MSG_USERNAME) != ""
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ func Watch(m *ice.Message, key string, arg ...string) *ice.Message {
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, m.PrefixKey())
|
||||
}
|
||||
return m.Cmd(EVENT, LISTEN, EVENT, key, ice.CMD, kit.Join(arg, ice.SP))
|
||||
return m.Cmd("gdb.event", LISTEN, EVENT, key, ice.CMD, kit.Join(arg, ice.SP))
|
||||
}
|
||||
func Event(m *ice.Message, key string, arg ...ice.Any) *ice.Message {
|
||||
return m.Cmdy(EVENT, HAPPEN, EVENT, key, arg)
|
||||
return m.Cmdy("gdb.event", HAPPEN, EVENT, key, arg)
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ func HashShort(m *ice.Message) string {
|
||||
}
|
||||
func HashField(m *ice.Message) string { return kit.Select(HASH_FIELD, m.Config(FIELD)) }
|
||||
func HashArgs(m *ice.Message, arg ...Any) []string {
|
||||
return _mdb_args(m, HashField(m), arg...)
|
||||
return _mdb_args(m, "", arg...)
|
||||
}
|
||||
func HashInputs(m *ice.Message, arg ...Any) *ice.Message {
|
||||
return m.Cmdy(INPUTS, m.PrefixKey(), "", HASH, HashArgs(m, arg))
|
||||
|
@ -32,6 +32,9 @@ func _mdb_args(m *ice.Message, field string, arg ...Any) []string {
|
||||
}
|
||||
}
|
||||
args := kit.Simple(res...)
|
||||
if field == "" {
|
||||
return args
|
||||
}
|
||||
for i := 0; i < len(args); i += 2 {
|
||||
if !strings.Contains(field, args[i]) && !strings.HasPrefix(args[i], EXTRA) {
|
||||
args[i] = kit.Keys(EXTRA, args[i])
|
||||
|
@ -16,9 +16,15 @@ func _header_check(m *ice.Message, arg ...string) bool {
|
||||
if m.Option(web.SHARE) != "" {
|
||||
m.Cmd(web.SHARE, m.Option(web.SHARE), ice.OptionFields(""), func(value ice.Maps) {
|
||||
switch value[mdb.TYPE] {
|
||||
case web.FIELD, web.STORM:
|
||||
case web.LOGIN:
|
||||
if value[aaa.USERNAME] != m.Option(ice.MSG_USERNAME) {
|
||||
web.RenderCookie(m, aaa.SessCreate(m, value[aaa.USERNAME]))
|
||||
}
|
||||
fallthrough
|
||||
case web.STORM, web.FIELD:
|
||||
m.Option(ice.MSG_USERNAME, value[aaa.USERNAME])
|
||||
m.Option(ice.MSG_USERROLE, value[aaa.USERROLE])
|
||||
m.Auth(aaa.USERROLE, value[aaa.USERROLE], aaa.USERNAME, value[aaa.USERNAME])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -44,7 +44,9 @@ func _river_list(m *ice.Message) {
|
||||
}
|
||||
|
||||
m.Cmd(mdb.SELECT, m.PrefixKey(), "", mdb.HASH, ice.OptionFields(mdb.HASH, mdb.NAME), func(value ice.Maps) {
|
||||
m.Debug("what %v", 123)
|
||||
m.Cmd(mdb.SELECT, m.PrefixKey(), kit.Keys(mdb.HASH, value[mdb.HASH], OCEAN), mdb.HASH, m.Option(ice.MSG_USERNAME), func(val ice.Maps) {
|
||||
m.Debug("what %v", 123)
|
||||
m.Push("", value, []string{mdb.HASH, mdb.NAME}, val)
|
||||
})
|
||||
})
|
||||
|
@ -5,14 +5,13 @@ import (
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const SCAN = "scan"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SCAN: {Name: "scan hash auto scanQRCode scanQRCode0", Help: "扫码", Meta: kit.Dict(ice.Display("")), Actions: ice.MergeActions(ice.Actions{
|
||||
SCAN: {Name: "scan hash auto scanQRCode scanQRCode0", Help: "扫码", Actions: ice.MergeActions(ice.Actions{
|
||||
"scanQRCode0": {Name: "scan create", Help: "本机扫码"},
|
||||
"scanQRCode": {Name: "scan create", Help: "扫码"},
|
||||
mdb.CREATE: {Name: "create type=text name=hi text:textarea=hi", Help: "添加"},
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
@ -31,9 +32,7 @@ const LOGIN = "login"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: ice.Configs{
|
||||
LOGIN: {Name: LOGIN, Help: "认证", Value: kit.Data(
|
||||
tcp.SERVER, "https://api.weixin.qq.com",
|
||||
)},
|
||||
LOGIN: {Name: LOGIN, Help: "认证", Value: kit.Data(tcp.SERVER, "https://api.weixin.qq.com")},
|
||||
}, Commands: ice.Commands{
|
||||
"/login/": {Name: "/login/", Help: "认证", Actions: ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -49,6 +48,9 @@ func init() {
|
||||
}},
|
||||
aaa.USER: {Name: "user", Help: "用户", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(aaa.USERNAME, m.Option(ice.MSG_USERNAME))
|
||||
if m.Cmd(aaa.USER, m.Option(aaa.USERNAME)).Length() == 0 {
|
||||
m.Cmd(aaa.USER, mdb.CREATE, m.OptionSimple(aaa.USERNAME))
|
||||
}
|
||||
m.Cmd(aaa.USER, mdb.MODIFY,
|
||||
aaa.USERNICK, m.Option("nickName"), aaa.USERZONE, MP,
|
||||
aaa.AVATAR, m.Option("avatarUrl"), aaa.GENDER, kit.Select("女", "男", m.Option(aaa.GENDER) == "1"),
|
||||
@ -65,8 +67,7 @@ func init() {
|
||||
}},
|
||||
LOGIN: {Name: "login appid auto qrcode tokens create", Help: "认证", Actions: ice.Actions{
|
||||
mdb.CREATE: {Name: "create appid appmm", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Config(APPID, m.Option(APPID))
|
||||
m.Config(APPMM, m.Option(APPMM))
|
||||
ctx.ConfigFromOption(m, APPID, APPMM)
|
||||
}},
|
||||
TOKENS: {Name: "tokens", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
|
||||
if now := time.Now().Unix(); m.Config(TOKENS) == "" || now > kit.Int64(m.Config(EXPIRES)) {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
@ -16,17 +17,20 @@ import (
|
||||
)
|
||||
|
||||
func _wx_sign(m *ice.Message, nonce, stamp string) string {
|
||||
return kit.Format(sha1.Sum([]byte(kit.Join(kit.Sort(kit.Simple(
|
||||
text := kit.Join(kit.Sort(kit.Simple(
|
||||
kit.Format("jsapi_ticket=%s", m.Cmdx(ACCESS, TICKET)),
|
||||
kit.Format("url=%s", m.Option(ice.MSG_USERWEB)),
|
||||
kit.Format("timestamp=%s", stamp),
|
||||
kit.Format("noncestr=%s", nonce),
|
||||
)), "&"))))
|
||||
)), "&")
|
||||
m.Debug("what %v", text)
|
||||
return kit.Format(sha1.Sum([]byte(text)))
|
||||
}
|
||||
func _wx_config(m *ice.Message, nonce string) {
|
||||
m.Option(APPID, m.Config(APPID))
|
||||
m.Option(ssh.SCRIPT, m.Config(ssh.SCRIPT))
|
||||
m.Option("signature", _wx_sign(m, m.Option("noncestr", nonce), m.Option("timestamp", kit.Format(time.Now().Unix()))))
|
||||
m.Option("debug", "true")
|
||||
}
|
||||
func _wx_check(m *ice.Message) {
|
||||
check := kit.Sort([]string{m.Config(TOKEN), m.Option("timestamp"), m.Option("nonce")})
|
||||
@ -70,19 +74,14 @@ func init() {
|
||||
}
|
||||
}},
|
||||
LOGIN: {Name: "login appid appmm token", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Config(APPID, m.Option(APPID))
|
||||
m.Config(APPMM, m.Option(APPMM))
|
||||
m.Config(TOKEN, m.Option(TOKEN))
|
||||
ctx.ConfigFromOption(m, APPID, APPMM, TOKEN)
|
||||
}},
|
||||
|
||||
TOKENS: {Name: "tokens", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
|
||||
if now := time.Now().Unix(); m.Config(TOKENS) == "" || now > kit.Int64(m.Config(EXPIRES)) {
|
||||
msg := m.Cmd(web.SPIDE, WX, web.SPIDE_GET, "/cgi-bin/token?grant_type=client_credential",
|
||||
APPID, m.Config(APPID), "secret", m.Config(APPMM))
|
||||
msg := m.Cmd(web.SPIDE, WX, web.SPIDE_GET, "/cgi-bin/token?grant_type=client_credential", APPID, m.Config(APPID), "secret", m.Config(APPMM))
|
||||
if m.Warn(msg.Append(ERRCODE) != "", msg.Append(ERRCODE), msg.Append(ERRMSG)) {
|
||||
return
|
||||
}
|
||||
|
||||
m.Config(EXPIRES, now+kit.Int64(msg.Append("expires_in")))
|
||||
m.Config(TOKENS, msg.Append("access_token"))
|
||||
}
|
||||
@ -90,11 +89,10 @@ func init() {
|
||||
}},
|
||||
TICKET: {Name: "ticket", Help: "票据", Hand: func(m *ice.Message, arg ...string) {
|
||||
if now := time.Now().Unix(); m.Config(TICKET) == "" || now > kit.Int64(m.Config(EXPIRE)) {
|
||||
msg := m.Cmd(web.SPIDE, WX, web.SPIDE_GET, "/cgi-bin/ticket/getticket?type=jsapi", "access_token", m.Cmdx(ACCESS, TOKENS))
|
||||
msg := m.Cmd(web.SPIDE, WX, web.SPIDE_GET, "/cgi-bin/ticket/getticket?type=jsapi", "access_token", m.Cmdx("", TOKENS))
|
||||
if m.Warn(msg.Append(ERRCODE) != "0", msg.Append(ERRCODE), msg.Append(ERRMSG)) {
|
||||
return
|
||||
}
|
||||
|
||||
m.Config(EXPIRE, now+kit.Int64(msg.Append("expires_in")))
|
||||
m.Config(TICKET, msg.Append(TICKET))
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ func _wx_parse(m *ice.Message) {
|
||||
FromUserName string
|
||||
ToUserName string
|
||||
CreateTime int64
|
||||
MsgID int64
|
||||
MsgId int64
|
||||
Event string
|
||||
MsgType string
|
||||
Content string
|
||||
@ -34,7 +34,9 @@ func _wx_parse(m *ice.Message) {
|
||||
|
||||
PicUrl string
|
||||
}{}
|
||||
defer m.R.Body.Close()
|
||||
buf, _ := ioutil.ReadAll(m.R.Body)
|
||||
|
||||
m.Debug("buf: %+v", string(buf))
|
||||
xml.NewDecoder(bytes.NewBuffer(buf)).Decode(&data)
|
||||
m.Debug("data: %+v", data)
|
||||
@ -42,7 +44,7 @@ func _wx_parse(m *ice.Message) {
|
||||
m.Option("FromUserName", data.FromUserName)
|
||||
m.Option("ToUserName", data.ToUserName)
|
||||
m.Option("CreateTime", data.CreateTime)
|
||||
m.Option("MsgID", data.MsgID)
|
||||
m.Option("MsgId", data.MsgId)
|
||||
|
||||
m.Option("Event", data.Event)
|
||||
m.Option("MsgType", data.MsgType)
|
||||
@ -100,11 +102,8 @@ func init() {
|
||||
}},
|
||||
LOGIN: {Name: "login", Help: "登录", Actions: ice.Actions{
|
||||
mdb.CREATE: {Name: "create appid appmm token", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Conf(ACCESS, kit.Keym(APPID), m.Option(APPID))
|
||||
m.Conf(ACCESS, kit.Keym(APPMM), m.Option(APPMM))
|
||||
m.Conf(ACCESS, kit.Keym(TOKEN), m.Option(TOKEN))
|
||||
m.Cmd(ACCESS, LOGIN, arg)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func _wx_action(m *ice.Message) {
|
||||
m.Set(ice.MSG_RESULT).RenderResult()
|
||||
m.SetResult().RenderResult()
|
||||
|
||||
m.Echo(`<xml>
|
||||
<FromUserName><![CDATA[%s]]></FromUserName>
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func _wx_reply(m *ice.Message, tmpl string) {
|
||||
if res, err := kit.Render(m.Config(nfs.TEMPLATE), m); err == nil {
|
||||
m.Set(ice.MSG_RESULT).RenderResult(string(res))
|
||||
m.SetResult().RenderResult(string(res))
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,9 +25,8 @@ func init() {
|
||||
m.Cmdy(MENU, kit.Select("home", m.Option(mdb.NAME)))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Cmdy(arg); m.Length() == 0 && (m.Result() == "" || m.Result(1) == ice.ErrNotFound) {
|
||||
m.Set(ice.MSG_RESULT)
|
||||
m.Cmdy(cli.SYSTEM, arg) // 系统命令
|
||||
if m.Cmdy(arg); m.Length() == 0 && (m.Result() == "" || m.IsErrNotFound()) {
|
||||
m.SetResult().Cmdy(cli.SYSTEM, arg) // 系统命令
|
||||
}
|
||||
if m.Result() == "" {
|
||||
m.Table()
|
||||
|
Loading…
x
Reference in New Issue
Block a user