1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00
This commit is contained in:
shylinux 2020-07-25 11:58:14 +08:00
parent d73015258e
commit 5b41af897b
8 changed files with 41 additions and 14 deletions

View File

@ -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),

View File

@ -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]))
})
}

View File

@ -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)
}},
},

View File

@ -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
}

View File

@ -1,4 +1,4 @@
title "lark"
title "飞书机器人"
refer "官网" `
官网 https://www.feishu.cn/

View File

@ -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"))

15
misc/mp/mp.shy Normal file
View File

@ -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 ]`

View File

@ -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")
}},