From 2727a198ae2f1e33c83dfa96cd9ebebed3c71b0b Mon Sep 17 00:00:00 2001 From: shy Date: Tue, 2 Jan 2024 17:37:00 +0800 Subject: [PATCH] opt aaa.sesss --- base/aaa/aaa.go | 2 +- base/aaa/offer.go | 3 ++- base/aaa/portal/apply.go | 8 ++++---- base/aaa/sess.go | 6 ++++++ base/web/share.go | 2 +- base/web/stats.go | 6 +++++- base/web/token.go | 2 +- conf.go | 5 +++-- core/chat/grant.go | 2 +- misc/wx/access.go | 10 +++++----- misc/wx/ide.go | 2 +- 11 files changed, 30 insertions(+), 18 deletions(-) diff --git a/base/aaa/aaa.go b/base/aaa/aaa.go index 5a94eb03..769927a9 100644 --- a/base/aaa/aaa.go +++ b/base/aaa/aaa.go @@ -19,4 +19,4 @@ var Index = &ice.Context{Name: AAA, Help: "认证模块", Commands: ice.Commands }}, }} -func init() { ice.Index.Register(Index, nil, OFFER, EMAIL, USER, TOTP, SESS, ROLE, RSA) } +func init() { ice.Index.Register(Index, nil, APPLY, OFFER, EMAIL, USER, TOTP, SESS, ROLE, RSA) } diff --git a/base/aaa/offer.go b/base/aaa/offer.go index 9a7291cc..ef9d93c2 100644 --- a/base/aaa/offer.go +++ b/base/aaa/offer.go @@ -10,6 +10,7 @@ const ( INVITE = "invite" ACCEPT = "accept" ) +const APPLY = "apply" const OFFER = "offer" func init() { @@ -28,7 +29,7 @@ func init() { msg := m.Cmd("", m.Option(mdb.HASH)) if ls := kit.Split(msg.Append(EMAIL), mdb.AT); !m.Warn(msg.Length() == 0 || len(ls) < 2, ice.ErrNotValid, m.Option(mdb.HASH)) { m.Cmd(USER, mdb.CREATE, USERNICK, ls[0], USERNAME, msg.Append(EMAIL), USERZONE, ls[1]) - m.ProcessOpen(kit.MergeURL2(m.Option(ice.MSG_USERWEB), ice.PS, ice.MSG_SESSID, SessCreate(m, msg.Append(EMAIL)), mdb.HASH, "")) + m.ProcessOpen(kit.MergeURL2(m.Option(ice.MSG_USERWEB), ice.PS, ice.MSG_SESSID, SessValid(m.Options(ice.MSG_USERNAME, msg.Append(EMAIL))), mdb.HASH, "")) mdb.HashModify(m, m.OptionSimple(mdb.HASH), mdb.STATUS, ACCEPT) } }}, diff --git a/base/aaa/portal/apply.go b/base/aaa/portal/apply.go index c9b603d0..60c1310d 100644 --- a/base/aaa/portal/apply.go +++ b/base/aaa/portal/apply.go @@ -35,7 +35,7 @@ func (s apply) Input(m *ice.Message, arg ...string) { } } func (s apply) Apply(m *ice.Message, arg ...string) { - if m.Warn(m.Options(arg).Cmd(aaa.USER, m.Option(aaa.EMAIL)).Length() > 0, "already exists") { + if m.Warn(m.Options(arg).Cmd(aaa.USER, m.Option(aaa.EMAIL)).Length() > 0, ice.ErrAlreadyExists) { return } m.ProcessCookie(_cookie_key(m), s.Hash.Create(m, kit.Simple(append(arg, aaa.USERNAME, m.Option(aaa.EMAIL)), mdb.STATUS, s.Apply, @@ -53,9 +53,9 @@ func (s apply) Login(m *ice.Message, arg ...string) { m.OptionDefault(mdb.HASH, m.Option(_cookie_key(m))) s.Hash.Modify(m, kit.Simple(m.OptionSimple(mdb.HASH), mdb.STATUS, s.Login)...) web.RenderCookie(m.Message, m.Cmdx(aaa.SESS, mdb.CREATE, s.Hash.List(m.Spawn(), m.Option(mdb.HASH)).Append(aaa.USERNAME))) - m.ProcessLocation("/c/web.chat.portal") + m.ProcessLocation(nfs.PS) } else { - if m.Warn(m.Cmd(aaa.USER, m.Option(aaa.EMAIL)).Length() == 0, "user not exists") { + if m.Warn(m.Cmd(aaa.USER, m.Option(aaa.EMAIL)).Length() == 0, ice.ErrNotFound) { return } m.Options(ice.MSG_USERNAME, m.Option(aaa.EMAIL)) @@ -66,7 +66,7 @@ func (s apply) Login(m *ice.Message, arg ...string) { } } func (s apply) Email(m *ice.Message, arg ...string) { - ctx.DisplayStoryForm(m.Message, "email*", s.Login).Echo("邮件发送成功后,请在邮箱中授权登录") + ctx.DisplayStoryForm(m.Message, "email*", s.Login).Echo("please auth login in mailbox, after email sent") } func (s apply) List(m *ice.Message, arg ...string) *ice.Message { kit.If(m.Option(_cookie_key(m)), func(p string) { arg = []string{p} }) diff --git a/base/aaa/sess.go b/base/aaa/sess.go index 20f0d278..b6468f0b 100644 --- a/base/aaa/sess.go +++ b/base/aaa/sess.go @@ -52,6 +52,12 @@ func SessCheck(m *ice.Message, sessid string) bool { m.Options(ice.MSG_USERNICK, "", ice.MSG_USERNAME, "", ice.MSG_USERROLE, VOID, ice.MSG_CHECKER, logs.FileLine(-1)) return sessid != "" && m.Cmdy(SESS, CHECK, sessid, logs.FileLineMeta(-1)).Option(ice.MSG_USERNAME) != "" } +func SessValid(m *ice.Message) string { + if m.Option(ice.MSG_SESSID) == "" || m.Cmd(SESS, m.Option(ice.MSG_SESSID)).Length() == 0 { + return m.Option(ice.MSG_SESSID, SessCreate(m, m.Option(ice.MSG_USERNAME))) + } + return m.Option(ice.MSG_SESSID) +} func SessAuth(m *ice.Message, value ice.Any, arg ...string) *ice.Message { language := kit.Select(m.Option(ice.MSG_LANGUAGE), kit.Format(kit.Value(value, LANGUAGE))) kit.If(language == "", func() { diff --git a/base/web/share.go b/base/web/share.go index 3fff3221..67bc1abd 100644 --- a/base/web/share.go +++ b/base/web/share.go @@ -113,7 +113,7 @@ func init() { RenderMain(m) } }}, - }, aaa.WhiteAction(), StatsAction("", "共享总数"), mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,usernick,username,userrole", mdb.EXPIRE, mdb.DAYS)), Hand: func(m *ice.Message, arg ...string) { + }, aaa.WhiteAction(), mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,usernick,username,userrole", mdb.EXPIRE, mdb.DAYS)), Hand: func(m *ice.Message, arg ...string) { if kit.IsIn(m.Option(ice.MSG_USERROLE), aaa.ROOT, aaa.TECH) || len(arg) > 0 && arg[0] != "" { mdb.HashSelect(m, arg...) } diff --git a/base/web/stats.go b/base/web/stats.go index 42b2dff7..eed079de 100644 --- a/base/web/stats.go +++ b/base/web/stats.go @@ -19,12 +19,16 @@ func init() { STATS: {Help: "汇总量", Hand: func(m *ice.Message, arg ...string) { defer ctx.DisplayStory(m, "") if m.Option(ice.MSG_USERPOD) == "" { - PushStats(m, kit.Keys(aaa.SESS, mdb.TOTAL), m.Cmd(aaa.SESS).Length(), "", "会话总数") + PushStats(m, kit.Keys(aaa.APPLY, mdb.TOTAL), m.Cmd(aaa.APPLY).Length(), "", "注册总数") + PushStats(m, kit.Keys(aaa.OFFER, mdb.TOTAL), m.Cmd(aaa.OFFER).Length(), "", "邀请总数") if ice.Info.Username == ice.Info.Make.Username { PushStats(m, kit.Keys(aaa.USER, mdb.TOTAL), m.Cmd(aaa.USER).Length()-1, "", "用户总数") } else { PushStats(m, kit.Keys(aaa.USER, mdb.TOTAL), m.Cmd(aaa.USER).Length()-2, "", "用户总数") } + PushStats(m, kit.Keys(aaa.SESS, mdb.TOTAL), m.Cmd(aaa.SESS).Length(), "", "会话总数") + PushStats(m, kit.Keys(TOKEN, mdb.TOTAL), m.Cmd(TOKEN).Length(), "", "令牌总数") + PushStats(m, kit.Keys(SHARE, mdb.TOTAL), m.Cmd(SHARE).Length(), "", "共享总数") PushStats(m, kit.Keys(ctx.COMMAND, mdb.TOTAL), m.Cmd(ctx.COMMAND).Length(), "", "命令总数") } gdb.Event(m, STATS_TABLES) diff --git a/base/web/token.go b/base/web/token.go index e17c3920..69bbf74c 100644 --- a/base/web/token.go +++ b/base/web/token.go @@ -45,7 +45,7 @@ func init() { m.Cmd(cli.SYSTEM, "git", "config", "--global", "credential.helper", "store") m.ProcessClose() }}, - }, StatsAction("", "令牌总数"), mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,type,name,text", mdb.EXPIRE, mdb.MONTH)), Hand: func(m *ice.Message, arg ...string) { + }, mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,type,name,text", mdb.EXPIRE, mdb.MONTH)), Hand: func(m *ice.Message, arg ...string) { if mdb.HashSelect(m, arg...); len(arg) > 0 { m.EchoScript(kit.Format("ish_miss_serve_log dev %s token %s", UserHost(m), arg[0])) } diff --git a/conf.go b/conf.go index 272b65af..4ee5d6ae 100644 --- a/conf.go +++ b/conf.go @@ -328,8 +328,9 @@ const ( // Err ErrNotFound = "not found: " ErrNotStart = "not start: " - ErrNotImplement = "not implement: " - ErrTooDeepCount = "too deep count: " + ErrAlreadyExists = "already exists: " + ErrNotImplement = "not implement: " + ErrTooDeepCount = "too deep count: " ) const ( // ctx COMMAND = "command" diff --git a/core/chat/grant.go b/core/chat/grant.go index ee3128ae..6f7e0824 100644 --- a/core/chat/grant.go +++ b/core/chat/grant.go @@ -36,7 +36,7 @@ func init() { } else if msg := m.Cmd(web.SPACE, m.Option(web.SPACE)); m.Warn(msg.Append(mdb.TYPE) != aaa.LOGIN, ice.ErrNotFound, m.Option(web.SPACE)) { return } else { - kit.If(m.Option(ice.MSG_SESSID) == "" || m.Cmd(aaa.SESS, m.Option(ice.MSG_SESSID)).Length() == 0, func() { web.RenderCookie(m, aaa.SessCreate(m, m.Option(ice.MSG_USERNAME))) }) + web.RenderCookie(m, aaa.SessValid(m)) m.Option(ice.MSG_USERUA, msg.Append(aaa.UA)) if ls := kit.Split(m.Option(web.SPACE), nfs.PT); len(ls) > 1 { m.Option(ice.MSG_SESSID, m.Cmdx(web.SPACE, kit.Keys(kit.Slice(ls, 0, -1)), aaa.SESS, mdb.CREATE, m.Option(ice.MSG_USERNAME))) diff --git a/misc/wx/access.go b/misc/wx/access.go index f0a48755..d0e134fa 100644 --- a/misc/wx/access.go +++ b/misc/wx/access.go @@ -93,17 +93,17 @@ func init() { if m.Cmd("", m.Option(ACCESS, arg[0])).Append(mdb.TYPE) == ice.WEB { m.Cmdy(SCAN, mdb.CREATE, mdb.TYPE, QR_STR_SCENE, mdb.NAME, "请授权登录", mdb.TEXT, m.Option(web.SPACE), ctx.INDEX, web.CHAT_GRANT, ctx.ARGS, m.Option(web.SPACE)) } else { - h := m.Cmdx(IDE, mdb.CREATE, mdb.NAME, m.Option(web.SPACE), PAGES, PAGES_ACTION, tcp.WIFI, kit.Select("", arg, 1), + h := m.Cmdx(IDE, mdb.CREATE, mdb.NAME, "请授权登录", mdb.TEXT, m.Option(web.SPACE), PAGES, PAGES_ACTION, tcp.WIFI, kit.Select("", arg, 1), ctx.INDEX, web.CHAT_GRANT, ctx.ARGS, kit.JoinQuery(m.OptionSimple(web.SPACE, log.DEBUG)...), ) m.Echo(m.Cmdx(SCAN, UNLIMIT, SCENE, h, ENV, kit.Select("release", arg, 2), IS_HYALINE, ice.FALSE, mdb.NAME, m.Option(web.SPACE))) } }}, web.SPACE_GRANT: {Hand: func(m *ice.Message, arg ...string) { - if strings.HasPrefix(m.Option(ice.MSG_REFERER), "https://servicewechat.com/") { - m.Cmd(mdb.PRUNES, m.Prefix(SCAN), "", mdb.HASH, mdb.NAME, m.Option(web.SPACE)) - m.Cmd(mdb.PRUNES, m.Prefix(IDE), "", mdb.HASH, mdb.NAME, m.Option(web.SPACE)) - } + m.Cmd(mdb.PRUNES, m.Prefix(SCAN), "", mdb.HASH, mdb.TEXT, m.Option(web.SPACE)) + m.Cmd(mdb.PRUNES, m.Prefix(SCAN), "", mdb.HASH, mdb.NAME, m.Option(web.SPACE)) + m.Cmd(mdb.PRUNES, m.Prefix(IDE), "", mdb.HASH, mdb.TEXT, m.Option(web.SPACE)) + m.Cmd(mdb.PRUNES, web.SHARE, "", mdb.HASH, mdb.TEXT, m.Option(web.SPACE)) }}, web.SPACE_LOGIN_CLOSE: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(mdb.PRUNES, m.Prefix(SCAN), "", mdb.HASH, m.OptionSimple(mdb.NAME)) diff --git a/misc/wx/ide.go b/misc/wx/ide.go index cf2d87aa..b4c10674 100644 --- a/misc/wx/ide.go +++ b/misc/wx/ide.go @@ -166,7 +166,7 @@ func init() { defer web.ToastProcess(m)() m.Cmd(web.SPACE, m.Option(web.WEIXIN), lex.PARSE, m.Cmdx("", m.Option(mdb.HASH))) }}, - }, web.StatsAction("", "小程序场景数"), mdb.ExportHashAction(mdb.FIELD, "time,hash,name,pages,space,index,args,wifi", cli.DARWIN, "/Applications/wechatwebdevtools.app/Contents/MacOS/cli")), Hand: func(m *ice.Message, arg ...string) { + }, web.StatsAction("", "小程序场景数"), mdb.ExportHashAction(mdb.FIELD, "time,hash,name,text,pages,space,index,args,wifi", cli.DARWIN, "/Applications/wechatwebdevtools.app/Contents/MacOS/cli")), Hand: func(m *ice.Message, arg ...string) { if len(arg) == 0 && tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) && kit.Value(kit.UnMarshal(IdeCli(m.Spawn(), ISLOGIN).Append(cli.CMD_OUT)), aaa.LOGIN) != true { m.EchoInfoButton("请登录: ", aaa.LOGIN) return