mirror of
https://shylinux.com/x/icebergs
synced 2025-06-25 18:17:29 +08:00
opt aaa.apply
This commit is contained in:
parent
69c2d29df7
commit
d4c197c737
@ -8,67 +8,73 @@ import (
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
type apply struct {
|
||||
ice.Hash
|
||||
email string `data:"admin"`
|
||||
field string `data:"time,hash,mobile,email,usernick,username,userrole,status"`
|
||||
sso string `name:"sso" help:"登录"`
|
||||
input string `name:"input" help:"注册" role:"void"`
|
||||
field string `data:"time,hash,status,email,usernick,username,userrole,icons,agent,system,ip,ua"`
|
||||
apply string `name:"apply" help:"申请" role:"void"`
|
||||
agree string `name:"agree userrole=tech" help:"同意" icon:"bi bi-check2-square"`
|
||||
agree string `name:"agree userrole=tech,void" help:"同意" icon:"bi bi-check2-square"`
|
||||
login string `name:"login" help:"登录" role:"void"`
|
||||
list string `name:"list hash auto sso" help:"注册"`
|
||||
}
|
||||
|
||||
func (s apply) Sso(m *ice.Message, arg ...string) {
|
||||
m.Cmd(web.CHAT_HEADER, mdb.CREATE, mdb.TYPE, cli.QRCODE, mdb.NAME, "扫码登录", mdb.ORDER, "10")
|
||||
m.Cmd(web.CHAT_HEADER, mdb.CREATE, mdb.TYPE, mdb.PLUGIN, mdb.NAME, "邮箱登录", mdb.ORDER, "20", ctx.INDEX, m.PrefixKey(), ctx.ARGS, kit.FuncName(s.Email))
|
||||
m.Cmd(web.CHAT_HEADER, mdb.CREATE, mdb.TYPE, mdb.PLUGIN, mdb.NAME, "注册用户", mdb.ORDER, "30", ctx.INDEX, m.PrefixKey(), ctx.ARGS, kit.FuncName(s.Input))
|
||||
}
|
||||
func (s apply) Input(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(mdb.HASH) == kit.FuncName(s.Input), func() { m.Options(mdb.HASH, "") })
|
||||
if k := _cookie_key(m); m.Option(k) == "" || s.List(m, m.Option(k)).Length() == 0 && m.Result() == "" {
|
||||
ctx.DisplayStoryForm(m.Message, "email*", aaa.USERNICK, s.Apply)
|
||||
}
|
||||
m.AddHeaderLogin(cli.QRCODE, cli.QRCODE, "扫码登录", "10")
|
||||
m.AddHeaderLogin(mdb.PLUGIN, aaa.EMAIL, "邮箱登录", "20", ctx.INDEX, m.PrefixKey(), ctx.ARGS, kit.FuncName(s.Login))
|
||||
m.AddHeaderLogin(mdb.PLUGIN, aaa.APPLY, "注册用户", "30", ctx.INDEX, m.PrefixKey(), ctx.ARGS, kit.FuncName(s.Apply))
|
||||
}
|
||||
func (s apply) Apply(m *ice.Message, arg ...string) {
|
||||
if m.Warn(m.Options(arg).Cmd(aaa.USER, m.Option(aaa.EMAIL)).Length() > 0, ice.ErrAlreadyExists) {
|
||||
return
|
||||
if m.IsGetMethod() {
|
||||
if k := _cookie_key(m); m.Option(k) == "" || s.List(m, m.Option(k)).Length() == 0 && m.Result() == "" {
|
||||
m.DisplayForm(m, "email*", aaa.USERNICK, s.Apply)
|
||||
}
|
||||
} else if !m.Warn(m.Options(arg).Cmd(aaa.USER, m.Option(aaa.EMAIL)).Length() > 0, ice.ErrAlreadyExists, aaa.USER, m.Option(aaa.EMAIL)) {
|
||||
m.ProcessCookie(_cookie_key(m), s.Hash.Create(m, kit.Simple(append(arg, mdb.STATUS, kit.FuncName(s.Apply), aaa.USERNAME, m.Option(aaa.EMAIL)), web.ParseUA(m.Message), cli.DAEMON, m.Option(ice.MSG_DAEMON))...))
|
||||
}
|
||||
m.ProcessCookie(_cookie_key(m), s.Hash.Create(m, kit.Simple(append(arg, aaa.USERNAME, m.Option(aaa.EMAIL)), mdb.STATUS, s.Apply,
|
||||
aaa.IP, m.Option(ice.MSG_USERIP), aaa.UA, m.Option(ice.MSG_USERUA), cli.DAEMON, m.Option(ice.MSG_DAEMON))...))
|
||||
}
|
||||
func (s apply) Agree(m *ice.Message, arg ...string) {
|
||||
if m.Warn(m.Option(mdb.HASH) == "", ice.ErrNotValid, mdb.PARAMS, mdb.HASH) {
|
||||
return
|
||||
}
|
||||
msg := s.Hash.List(m.Spawn(), m.Option(mdb.HASH))
|
||||
if m.Warn(msg.Length() == 0, ice.ErrNotFound, m.PrefixKey(), m.Option(mdb.HASH)) {
|
||||
return
|
||||
}
|
||||
s.Hash.Modify(m, kit.Simple(m.OptionSimple(mdb.HASH, aaa.USERROLE), mdb.STATUS, s.Agree)...)
|
||||
m.Cmd(aaa.USER, mdb.CREATE, msg.AppendSimple(aaa.USERNICK, aaa.USERNAME), m.Option(aaa.USERROLE))
|
||||
web.PushNotice(m.Spawn(kit.Dict(ice.MSG_DAEMON, msg.Append(cli.DAEMON))).Message, html.REFRESH)
|
||||
m.Cmd(aaa.USER, mdb.CREATE, msg.AppendSimple(aaa.USERNICK, aaa.USERNAME), m.OptionSimple(aaa.USERROLE))
|
||||
m.PushRefresh(msg.Append(cli.DAEMON))
|
||||
}
|
||||
func (s apply) Login(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(mdb.HASH) == kit.FuncName(s.Input), func() { m.Options(mdb.HASH, "") })
|
||||
if m.Options(arg).Option(aaa.EMAIL) == "" {
|
||||
m.OptionDefault(mdb.HASH, m.Option(_cookie_key(m)))
|
||||
kit.If(m.Option(mdb.HASH) == kit.FuncName(s.Apply), func() { m.Options(mdb.HASH, "") })
|
||||
if m.IsGetMethod() {
|
||||
m.DisplayForm("email*", s.Login)
|
||||
} else if m.Options(arg).Option(aaa.EMAIL) == "" {
|
||||
if m.Warn(m.OptionDefault(mdb.HASH, m.Option(_cookie_key(m))) == "", ice.ErrNotValid, mdb.PARAMS, mdb.HASH) {
|
||||
m.ProcessCookie(_cookie_key(m), "")
|
||||
return
|
||||
}
|
||||
msg := s.Hash.List(m.Spawn(), m.Option(mdb.HASH))
|
||||
if m.Warn(msg.Length() == 0, ice.ErrNotFound, m.PrefixKey(), m.Option(mdb.HASH)) {
|
||||
m.ProcessCookie(_cookie_key(m), "")
|
||||
return
|
||||
}
|
||||
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)))
|
||||
web.RenderCookie(m.Message, m.Cmdx(aaa.SESS, mdb.CREATE, msg.Append(aaa.USERNAME)))
|
||||
m.ProcessLocation(nfs.PS)
|
||||
} else {
|
||||
if m.Warn(m.Cmd(aaa.USER, m.Option(aaa.EMAIL)).Length() == 0, ice.ErrNotFound) {
|
||||
if m.Warn(m.Cmd(aaa.USER, m.Option(aaa.EMAIL)).Length() == 0, ice.ErrNotFound, aaa.USER, m.Option(aaa.EMAIL)) {
|
||||
return
|
||||
}
|
||||
m.Options(ice.MSG_USERNAME, m.Option(aaa.EMAIL))
|
||||
space := kit.Keys(kit.Slice(kit.Split(m.Option(ice.MSG_DAEMON), nfs.PT), 0, -1))
|
||||
share := m.Cmd(web.SHARE, mdb.CREATE, mdb.TYPE, web.FIELD, mdb.NAME, web.CHAT_GRANT, mdb.TEXT, space).Append(mdb.LINK)
|
||||
aaa.SendEmail(m.Options(web.LINK, share).Message, "", "", "")
|
||||
m.ProcessHold()
|
||||
m.SendEmail(m.Options(web.LINK, share), "", "", "")
|
||||
m.ProcessHold(m.Trans("please auth login in mailbox", "请注意查收邮件"))
|
||||
}
|
||||
}
|
||||
func (s apply) Email(m *ice.Message, arg ...string) {
|
||||
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} })
|
||||
s.Hash.List(m, arg...).Table(func(value ice.Maps) {
|
||||
@ -82,19 +88,19 @@ func (s apply) List(m *ice.Message, arg ...string) *ice.Message {
|
||||
}
|
||||
})
|
||||
if len(arg) == 0 {
|
||||
m.EchoQRCode(m.MergePodCmd("", "", ctx.ACTION, s.Input))
|
||||
} else if m.Option(_cookie_key(m)) != "" || !kit.IsIn(m.ActionKey(), "", ice.LIST, mdb.SELECT) {
|
||||
m.EchoQRCode(m.MergePodCmd("", "", ctx.ACTION, s.Apply))
|
||||
} else if m.Option(_cookie_key(m)) != "" || m.ActionKey() != "" {
|
||||
switch m.Append(mdb.STATUS) {
|
||||
case kit.FuncName(s.Login):
|
||||
if m.ActionKey() == kit.FuncName(s.Input) {
|
||||
if m.ActionKey() == kit.FuncName(s.Apply) {
|
||||
m.ProcessCookie(_cookie_key(m), "")
|
||||
} else {
|
||||
m.SetAppend().ProcessLocation(nfs.PS)
|
||||
}
|
||||
case kit.FuncName(s.Agree):
|
||||
m.SetAppend().EchoInfoButton("please login", s.Login)
|
||||
m.SetAppend().EchoInfoButton(m.Trans("please login", "请登录"), s.Login)
|
||||
case kit.FuncName(s.Apply):
|
||||
m.SetAppend().EchoInfoButton("please wait admin agree")
|
||||
m.SetAppend().EchoInfoButton(m.Trans("please wait admin agree", "请等待管理员同意"), nil)
|
||||
}
|
||||
}
|
||||
return m
|
||||
|
@ -44,8 +44,12 @@ func DisplayStoryForm(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
case string:
|
||||
args = append(args, ice.SplitCmd("list "+v, nil)...)
|
||||
default:
|
||||
trans := kit.Value(m.Commands(m.CommandKey()).Meta, ice.CTX_TRANS)
|
||||
if t := reflect.TypeOf(v); t.Kind() == reflect.Func {
|
||||
args = append(args, kit.Dict(mdb.TYPE, html.BUTTON, mdb.NAME, kit.FuncName(arg[i])))
|
||||
name := kit.FuncName(arg[i])
|
||||
args = append(args, kit.Dict(mdb.TYPE, html.BUTTON, mdb.NAME, name,
|
||||
mdb.VALUE, kit.Select(name, kit.Value(trans, name), !m.IsEnglish()),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,8 +87,8 @@ func init() {
|
||||
ISLOCAL: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] = strings.Split(strings.TrimPrefix(arg[0], "["), "]")[0]; arg[0] == "::1" || strings.HasPrefix(arg[0], "127.") || arg[0] == LOCALHOST {
|
||||
m.Echo(ice.OK)
|
||||
} else if mdb.HashSelectField(m, strings.Split(arg[0], nfs.DF)[0], mdb.TYPE) == aaa.WHITE {
|
||||
m.Echo(ice.OK)
|
||||
// } else if mdb.HashSelectField(m, strings.Split(arg[0], nfs.DF)[0], mdb.TYPE) == aaa.WHITE {
|
||||
// m.Echo(ice.OK)
|
||||
}
|
||||
}},
|
||||
PUBLISH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -273,6 +273,22 @@ func Domain(host, port string) string {
|
||||
func Script(m *ice.Message, str string, arg ...ice.Any) string {
|
||||
return ice.Render(m, ice.RENDER_SCRIPT, kit.Format(str, arg...))
|
||||
}
|
||||
func ParseUA(m *ice.Message) (res []string) {
|
||||
res = append(res, aaa.IP, m.Option(ice.MSG_USERIP), aaa.UA, m.Option(ice.MSG_USERUA))
|
||||
for _, p := range []string{"Android", "iPhone", "Mac", "Windows"} {
|
||||
if strings.Contains(m.Option(ice.MSG_USERUA), p) {
|
||||
res = append(res, cli.SYSTEM, p)
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, p := range []string{"MicroMessenger", "Alipay", "Edg", "Chrome", "Safari", "Go-http-client"} {
|
||||
if strings.Contains(m.Option(ice.MSG_USERUA), p) {
|
||||
res = append(res, AGENT, p, mdb.ICONS, agentIcons[p])
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
func ChatCmdPath(m *ice.Message, arg ...string) string {
|
||||
return m.MergePodCmd("", kit.Select(m.PrefixKey(), path.Join(arg...)))
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ func init() {
|
||||
}
|
||||
nfs.TemplateText = func(m *ice.Message, p string) string {
|
||||
if p := kit.Select(nfs.TemplatePath(m, path.Base(p)), m.Option("_template")); kit.HasPrefix(p, "/require/", ice.HTTP) {
|
||||
return m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodGet, p)
|
||||
return m.Cmdx(SPIDE, ice.OPS, SPIDE_RAW, http.MethodGet, p)
|
||||
} else {
|
||||
return m.Cmdx(nfs.CAT, p)
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
@ -104,7 +106,7 @@ func init() {
|
||||
link := tcp.PublishLocalhost(m, m.Option(ice.MSG_USERWEB))
|
||||
m.Push(mdb.NAME, link).PushQRCode(mdb.TEXT, link)
|
||||
}},
|
||||
mdb.CREATE: {Name: "create type*=plugin,qrcode,oauth name* icons link order space index args", Hand: func(m *ice.Message, arg ...string) { mdb.HashCreate(m, m.OptionSimple()) }},
|
||||
mdb.CREATE: {Name: "create type*=plugin,qrcode,oauth name* help icons link order space index args", Hand: func(m *ice.Message, arg ...string) { mdb.HashCreate(m, m.OptionSimple()) }},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { mdb.HashRemove(m, m.OptionSimple(mdb.NAME)) }},
|
||||
mdb.MODIFY: {Hand: func(m *ice.Message, arg ...string) { mdb.HashModify(m, m.OptionSimple(mdb.NAME), arg) }},
|
||||
ice.DEMO: {Help: "体验", Icon: "bi bi-shield-fill-check", Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -118,13 +120,15 @@ func init() {
|
||||
m.Echo("login failure")
|
||||
}
|
||||
}},
|
||||
}, web.ApiAction(), mdb.ImportantHashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,icons,type,link,order,space,index,args")), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, web.ApiAction(), mdb.ImportantHashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,help,icons,type,link,order,space,index,args")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if ice.Info.NodeType == web.WORKER {
|
||||
return
|
||||
}
|
||||
kit.If(m.Option(ice.MSG_USERPOD), func(p string) {
|
||||
m.Option(ice.MSG_NODETYPE, m.Cmdx(web.SPACE, p, cli.RUNTIME, ice.MSG_NODETYPE))
|
||||
})
|
||||
m.OptionDefault(ice.MSG_LANGUAGE, strings.ToLower(kit.Select("", kit.Split(m.R.Header.Get(html.AcceptLanguage), ",;"), 0)))
|
||||
m.OptionDefault(aaa.LANGUAGE, m.Option(ice.MSG_LANGUAGE))
|
||||
m.Option("language.list", m.Cmd(nfs.DIR, nfs.TemplatePath(m, aaa.LANGUAGE)+nfs.PS, nfs.FILE).Appendv(nfs.FILE))
|
||||
m.Option("theme.list", m.Cmd(nfs.DIR, nfs.TemplatePath(m, aaa.THEME)+nfs.PS, nfs.FILE).Appendv(nfs.FILE))
|
||||
m.Option(nfs.REPOS, m.Cmdv(web.SPIDE, nfs.REPOS, web.CLIENT_URL))
|
||||
@ -134,7 +138,7 @@ func init() {
|
||||
mdb.HashSelect(m, arg...).Sort(mdb.ORDER, ice.INT)
|
||||
m.Table(func(value ice.Maps) { m.Push(mdb.STATUS, kit.Select(mdb.ENABLE, mdb.DISABLE, value[mdb.ORDER] == "")) })
|
||||
kit.If(m.Length() == 0, func() {
|
||||
m.Push(mdb.TIME, m.Time()).Push(mdb.NAME, "扫码登录").Push(mdb.ICONS, nfs.USR_ICONS_VOLCANOS).Push(mdb.TYPE, cli.QRCODE).Push(web.LINK, "").Push(mdb.ORDER, "10")
|
||||
m.Push(mdb.TIME, m.Time()).Push(mdb.NAME, "qrcode").Push(mdb.HELP, "扫码登录").Push(mdb.ICONS, nfs.USR_ICONS_VOLCANOS).Push(mdb.TYPE, cli.QRCODE).Push(web.LINK, "").Push(mdb.ORDER, "10")
|
||||
})
|
||||
kit.If(GetSSO(m), func(p string) {
|
||||
m.Push(mdb.TIME, m.Time()).Push(mdb.NAME, web.SERVE).Push(mdb.ICONS, nfs.USR_ICONS_ICEBERGS).Push(mdb.TYPE, "oauth").Push(web.LINK, p)
|
||||
@ -145,9 +149,11 @@ func init() {
|
||||
return
|
||||
}
|
||||
msg := m.Cmd(aaa.USER, m.Option(ice.MSG_USERNAME))
|
||||
m.Option(aaa.LANGUAGE, m.Option(ice.MSG_LANGUAGE))
|
||||
kit.For([]string{aaa.USERNICK, aaa.EMAIL}, func(k string) { m.Option(k, msg.Append(k)) })
|
||||
kit.For([]string{aaa.USERNICK, aaa.EMAIL, aaa.LANGUAGE}, func(k string) { m.OptionDefault(k, msg.Append(k)) })
|
||||
kit.For([]string{aaa.AVATAR, aaa.BACKGROUND}, func(k string) { m.Option(k, web.RequireFile(m, msg.Append(k))) })
|
||||
}},
|
||||
})
|
||||
}
|
||||
func AddHeaderLogin(m *ice.Message, types, name, help, order string, arg ...string) {
|
||||
m.Cmd(web.CHAT_HEADER, mdb.CREATE, mdb.TYPE, types, mdb.NAME, name, mdb.HELP, help, mdb.ORDER, order, arg)
|
||||
}
|
||||
|
2
misc.go
2
misc.go
@ -160,7 +160,7 @@ func (m *Message) Toast(content string, arg ...string) { // title duration
|
||||
Info.PushNotice(m, "toast", content, arg)
|
||||
}
|
||||
func (m *Message) Trans(en string, zh string) string {
|
||||
switch strings.ToLower(kit.Split(m.Option(MSG_LANGUAGE), "_-")[0]) {
|
||||
switch strings.ToLower(kit.Select("", kit.Split(m.Option(MSG_LANGUAGE), "_-"), 0)) {
|
||||
case "zh":
|
||||
return zh
|
||||
default:
|
||||
|
@ -82,6 +82,7 @@ func (m *Message) Fields(length int, fields ...string) string {
|
||||
return m.OptionDefault(MSG_FIELDS, kit.Select(FIELDS_DETAIL, fields, length))
|
||||
}
|
||||
func (m *Message) Action(arg ...Any) *Message {
|
||||
kit.If(len(arg) == 1 && arg[0] == nil, func() { arg = arg[:0] })
|
||||
kit.For(arg, func(i int, v Any) { arg[i] = kit.LowerCapital(kit.Format(v)) })
|
||||
return m.Options(MSG_ACTION, kit.Format(arg))
|
||||
}
|
||||
|
@ -223,7 +223,12 @@ func (m *Message) EchoInfoButton(info string, arg ...Any) *Message {
|
||||
m.Display("/plugin/table.js", "style", "form")
|
||||
return m.Echo(html.Format("div", info, "class", "info", "style", kit.JoinCSS())).EchoButton(arg...).Echo(NL).Action(arg...)
|
||||
}
|
||||
func (m *Message) EchoButton(arg ...Any) *Message { return m.Echo(Render(m, RENDER_BUTTON, arg...)) }
|
||||
func (m *Message) EchoButton(arg ...Any) *Message {
|
||||
if len(arg) == 0 || len(arg) == 1 && arg[0] == nil {
|
||||
return m
|
||||
}
|
||||
return m.Echo(Render(m, RENDER_BUTTON, arg...))
|
||||
}
|
||||
func (m *Message) EchoAnchor(arg ...string) *Message { return m.Echo(Render(m, RENDER_ANCHOR, arg)) }
|
||||
func (m *Message) EchoQRCode(src string) *Message { return m.Echo(Render(m, RENDER_QRCODE, src)) }
|
||||
func (m *Message) EchoImages(src string) *Message { return m.Echo(Render(m, RENDER_IMAGES, src)) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user