diff --git a/base/aaa/sess.go b/base/aaa/sess.go index 03d6fc69..bc4eb279 100644 --- a/base/aaa/sess.go +++ b/base/aaa/sess.go @@ -13,7 +13,6 @@ func _sess_list(m *ice.Message) { } func _sess_auth(m *ice.Message, sessid string, username string, userrole string) { m.Richs(SESS, nil, sessid, func(value map[string]interface{}) { - m.Debug("fuck %v", m.Option(ice.MSG_USERROLE)) if m.Option(ice.MSG_USERROLE) == ROOT { value[USERROLE] = userrole } else if m.Option(ice.MSG_USERROLE) == TECH && userrole != ROOT { @@ -32,12 +31,15 @@ func _sess_check(m *ice.Message, sessid string) { }) m.Log_AUTH( USERNAME, m.Option(ice.MSG_USERNAME, value[USERNAME]), - USERROLE, m.Option(ice.MSG_USERROLE, value[USERROLE]), + USERROLE, m.Option(ice.MSG_USERROLE, kit.Select(UserRole(m, value[USERNAME]), value[USERROLE])), USERNICK, m.Option(ice.MSG_USERROLE), ) }) } func _sess_create(m *ice.Message, username string) string { + if m.Richs(USER, nil, username, nil) == nil { + _user_create(m, username, "") + } h := m.Rich(SESS, nil, kit.Dict( kit.MDB_TIME, m.Time(m.Conf(SESS, "meta.expire")), USERNAME, username, "from", m.Option(ice.MSG_SESSID), diff --git a/base/aaa/user.go b/base/aaa/user.go index 3f743c80..da988113 100644 --- a/base/aaa/user.go +++ b/base/aaa/user.go @@ -48,7 +48,7 @@ func _user_create(m *ice.Message, name, word string) { } func _user_search(m *ice.Message, kind, name, text string, arg ...string) { m.Richs(USER, nil, kit.MDB_FOREACH, func(key string, val map[string]interface{}) { - if name != val[USERNAME] { + if name != "" && name != val[USERNAME] { return } m.Push("pod", m.Option("pod")) @@ -57,8 +57,8 @@ func _user_search(m *ice.Message, kind, name, text string, arg ...string) { m.Push(key, val, []string{kit.MDB_TIME}) m.Push(kit.MDB_SIZE, kit.Format("")) m.Push(kit.MDB_TYPE, kit.Format(UserRole(m, val[USERNAME]))) - m.Push(kit.MDB_NAME, kit.Format(val[USERNAME])) - m.Push(kit.MDB_TEXT, kit.Format(val[USERNODE])) + m.Push(kit.MDB_NAME, kit.Format(val[USERNICK])) + m.Push(kit.MDB_TEXT, kit.Format(val[USERNAME])) }) } diff --git a/core/chat/river.go b/core/chat/river.go index 49711965..1a30ee83 100644 --- a/core/chat/river.go +++ b/core/chat/river.go @@ -122,6 +122,10 @@ func init() { m.Cmdy("/storm", arg[1:]) return } + if m.Option(ice.MSG_SESSID) == "" { + m.Render("status", "401") + return + } _river_list(m) }}, }, diff --git a/meta.go b/meta.go index ddb836c4..e3be92a3 100644 --- a/meta.go +++ b/meta.go @@ -438,6 +438,7 @@ func (m *Message) Optionv(key string, arg ...interface{}) interface{} { m.meta[key] = kit.Simple(arg) case []string: m.meta[key] = str + delete(m.data, key) default: m.data[key] = str } diff --git a/misc/lark/lark.shy b/misc/lark/lark.shy index a96af071..470f9560 100644 --- a/misc/lark/lark.shy +++ b/misc/lark/lark.shy @@ -1,4 +1,4 @@ -title "lark" +title "飞书机器人" refer "官网" ` 官网 https://www.feishu.cn/ diff --git a/misc/mp/mp.go b/misc/mp/mp.go index aac293f5..c864e536 100644 --- a/misc/mp/mp.go +++ b/misc/mp/mp.go @@ -2,10 +2,13 @@ package mp import ( "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/aaa" + "github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/core/chat" "github.com/shylinux/toolkits" + "net/http" "path" ) @@ -20,14 +23,14 @@ var Index = &ice.Context{Name: "mp", Help: "小程序", )}, }, Commands: map[string]*ice.Command{ - ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() - web.SpideCreate(m, "weixin", m.Conf("login", "meta.weixin")) + m.Cmd(web.SPIDE, mdb.CREATE, "weixin", m.Conf("login", "meta.weixin")) m.Confm("login", "meta.userrole", func(key string, value string) { m.Cmd(aaa.ROLE, value, key) }) }}, - ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save("login") }}, @@ -56,11 +59,11 @@ var Index = &ice.Context{Name: "mp", Help: "小程序", "/login/": {Name: "/login/", Help: "登录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { switch arg[0] { case "code": - msg := m.Cmd(web.SPIDE, "weixin", "GET", m.Conf("login", "meta.auth"), "js_code", m.Option("code"), + msg := m.Cmd(web.SPIDE, "weixin", http.MethodGet, m.Conf("login", "meta.auth"), "js_code", m.Option("code"), "appid", m.Conf("login", "meta.appid"), "secret", m.Conf("login", "meta.appmm")) // 用户登录 - m.Echo(m.Option(ice.MSG_SESSID, m.Cmdx(aaa.USER, "login", msg.Append("openid")))) + m.Echo(aaa.SessCreate(msg, msg.Append("openid"), aaa.UserRole(msg, msg.Append("openid")))) case "info": // 用户信息 @@ -114,7 +117,7 @@ var Index = &ice.Context{Name: "mp", Help: "小程序", case "upload": msg := m.Cmd(web.CACHE, "upload") - m.Cmd(web.STORY, ice.STORY_WATCH, msg.Append("data"), path.Join("usr/local/mp/", path.Base(msg.Append("name")))) + m.Cmd(web.STORY, web.WATCH, msg.Append("data"), path.Join("usr/local/mp/", path.Base(msg.Append("name")))) m.Cmd(web.FAVOR, "device", "file", msg.Append("name"), msg.Append("data")) m.Render(msg.Append("data")) diff --git a/misc/mp/mp.shy b/misc/mp/mp.shy new file mode 100644 index 00000000..794ef9ab --- /dev/null +++ b/misc/mp/mp.shy @@ -0,0 +1,15 @@ +title "微信小程序" +refer "" ` +官网 https://weixin.qq.com/ +后台 https://mp.weixin.qq.com/ +文档 https://developers.weixin.qq.com/miniprogram/dev/api/ +源码 https://github.com/shylinux/icebergs/blob/master/misc/mp/mp.go +` + +field "用户" user + +section "icebergs" +field "icebergs_统计" web.code.git.trend args `[ icebergs ]` action `{ height 200 speed 20 }` +field "icebergs_源码" web.code.inner args `[ usr/icebergs misc/mp/mp.go 1 ]` +field "icebergs_项目" web.code.git.spide args `[ icebergs ]` + diff --git a/misc/wx/wx.go b/misc/wx/wx.go index f17a3dbe..4ddabc70 100644 --- a/misc/wx/wx.go +++ b/misc/wx/wx.go @@ -2,6 +2,8 @@ package wx import ( "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/base/aaa" + "github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/core/chat" "github.com/shylinux/toolkits" @@ -94,13 +96,13 @@ var Index = &ice.Context{Name: "wx", Help: "公众号", )}, }, Commands: map[string]*ice.Command{ - ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() m.Confm("login", "meta.userrole", func(key string, value string) { m.Cmd(aaa.ROLE, value, key) }) }}, - ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save("login") }},