forked from x/icebergs
add offer
This commit is contained in:
parent
969b4feabe
commit
f8a408131d
43
base/aaa/email.go
Normal file
43
base/aaa/email.go
Normal file
@ -0,0 +1,43 @@
|
||||
package aaa
|
||||
|
||||
import (
|
||||
"net/smtp"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const (
|
||||
SEND = "send"
|
||||
)
|
||||
const EMAIL = "email"
|
||||
|
||||
func init() {
|
||||
const (
|
||||
TO = "to"
|
||||
SUBJECT = "subject"
|
||||
CONTENT = "content"
|
||||
SERVICE = "service"
|
||||
NL = "\r\n"
|
||||
DF = ": "
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
EMAIL: {Name: "email name auto create", Help: "邮件", Actions: ice.MergeActions(ice.Actions{
|
||||
SEND: {Name: "send to='shylinux@163.com' subject=hi content:textarea=hello", Help: "发送", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(SERVICE) == "" {
|
||||
msg := m.Cmd("", "admin")
|
||||
m.Option(SERVICE, msg.Append(SERVICE))
|
||||
m.Option(USERNAME, msg.Append(USERNAME))
|
||||
m.Option(PASSWORD, msg.Append(PASSWORD))
|
||||
}
|
||||
content := []byte(kit.JoinKV(DF, NL, "To", m.Option(TO), "From", m.Option(USERNAME), "Subject", m.Option(SUBJECT), "Content-Type", "text/html; charset=UTF-8")+NL+NL+m.Option(CONTENT))
|
||||
auth := smtp.PlainAuth("", m.Option(USERNAME), m.Option(PASSWORD), kit.Split(m.Option(SERVICE), ice.DF)[0])
|
||||
m.Warn(smtp.SendMail(m.Option(SERVICE), auth, m.Option(USERNAME), kit.Split(m.Option(TO)), content))
|
||||
m.Debug("email send %v %v", auth, string(content))
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,username,password,service")), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).PushAction(SEND)
|
||||
}},
|
||||
})
|
||||
}
|
36
base/aaa/offer.go
Normal file
36
base/aaa/offer.go
Normal file
@ -0,0 +1,36 @@
|
||||
package aaa
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const OFFER = "offer"
|
||||
|
||||
func init() {
|
||||
const (
|
||||
ACCEPT = "accept"
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
OFFER: {Name: "offer hash auto", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create email", Hand: func(m *ice.Message, arg ...string) {
|
||||
h := mdb.HashCreate(m, m.OptionSimple(EMAIL), "from", m.Option(ice.MSG_USERNAME))
|
||||
msg := m.Cmd("web.share", mdb.CREATE, mdb.TYPE, "field", mdb.NAME, m.PrefixKey(), mdb.TEXT, kit.Format(kit.List(h)),
|
||||
kit.Dict(ice.MSG_USERNAME, m.Option(EMAIL), ice.MSG_USERNICK, VOID, ice.MSG_USERROLE, VOID))
|
||||
m.Cmd(EMAIL, SEND, m.Option(EMAIL), "welcome to contents, please continue", ice.Render(m, ice.RENDER_ANCHOR, msg.Option(mdb.LINK)))
|
||||
}},
|
||||
ACCEPT: {Help: "接受", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(USER, mdb.CREATE, USERNAME, m.Option(EMAIL))
|
||||
m.ProcessOpen(kit.MergeURL2(m.Option(ice.MSG_USERWEB), ice.PS, ice.MSG_SESSID, m.Cmdx(SESS, mdb.CREATE, USERNAME, m.Option(EMAIL))))
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,email,from"), RoleAction(ACCEPT)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(ice.MSG_USERROLE) == VOID && len(arg) == 0 {
|
||||
return
|
||||
}
|
||||
if mdb.HashSelect(m, arg...).PushAction(ACCEPT); len(arg) == 0 {
|
||||
m.Action(mdb.CREATE)
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
@ -14,19 +14,18 @@ func _role_chain(arg ...string) string {
|
||||
key := path.Join(strings.ReplaceAll(kit.Keys(arg), ice.PT, ice.PS))
|
||||
return strings.TrimPrefix(strings.TrimSuffix(strings.ReplaceAll(key, ice.PS, ice.PT), ice.PT), ice.PT)
|
||||
}
|
||||
func _role_black(m *ice.Message, userrole, chain string) {
|
||||
m.Logs(mdb.INSERT, ROLE, userrole, BLACK, chain)
|
||||
func _role_set(m *ice.Message, userrole, zone, chain string, status bool) {
|
||||
m.Logs(mdb.INSERT, ROLE, userrole, zone, chain)
|
||||
mdb.HashSelectUpdate(m, userrole, func(value ice.Map) {
|
||||
black := value[BLACK].(ice.Map)
|
||||
black[chain] = true
|
||||
black := value[zone].(ice.Map)
|
||||
black[chain] = status
|
||||
})
|
||||
}
|
||||
func _role_black(m *ice.Message, userrole, chain string) {
|
||||
_role_set(m, userrole, BLACK, chain, true)
|
||||
}
|
||||
func _role_white(m *ice.Message, userrole, chain string) {
|
||||
m.Logs(mdb.INSERT, ROLE, userrole, WHITE, chain)
|
||||
mdb.HashSelectUpdate(m, userrole, func(value ice.Map) {
|
||||
white := value[WHITE].(ice.Map)
|
||||
white[chain] = true
|
||||
})
|
||||
_role_set(m, userrole, WHITE, chain, true)
|
||||
}
|
||||
func _role_check(value ice.Map, keys []string, ok bool) bool {
|
||||
white := value[WHITE].(ice.Map)
|
||||
@ -48,7 +47,7 @@ func _role_right(m *ice.Message, userrole string, keys ...string) (ok bool) {
|
||||
mdb.HashSelectDetail(m, kit.Select(VOID, userrole), func(value ice.Map) {
|
||||
ok = _role_check(value, keys, userrole == TECH)
|
||||
})
|
||||
return ok
|
||||
return
|
||||
}
|
||||
func _role_list(m *ice.Message, userrole string) *ice.Message {
|
||||
mdb.HashSelectDetail(m, kit.Select(VOID, userrole), func(value ice.Map) {
|
||||
@ -90,18 +89,10 @@ func init() {
|
||||
}
|
||||
}},
|
||||
mdb.INSERT: {Name: "insert role=void,tech zone=white,black key", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Logs(mdb.INSERT, ROLE, m.Option(ROLE), m.Option(mdb.ZONE), m.Option(mdb.KEY))
|
||||
mdb.HashSelectUpdate(m, m.Option(ROLE), func(key string, value ice.Map) {
|
||||
list := value[m.Option(mdb.ZONE)].(ice.Map)
|
||||
list[_role_chain(m.Option(mdb.KEY))] = true
|
||||
})
|
||||
_role_set(m, m.Option(ROLE), m.Option(mdb.ZONE), m.Option(mdb.KEY), true)
|
||||
}},
|
||||
mdb.DELETE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Logs(mdb.DELETE, ROLE, m.Option(ROLE), m.Option(mdb.ZONE), m.Option(mdb.KEY))
|
||||
mdb.HashSelectUpdate(m, m.Option(ROLE), func(key string, value ice.Map) {
|
||||
list := value[m.Option(mdb.ZONE)].(ice.Map)
|
||||
list[_role_chain(m.Option(mdb.KEY))] = false
|
||||
})
|
||||
_role_set(m, m.Option(ROLE), m.Option(mdb.ZONE), m.Option(mdb.KEY), false)
|
||||
}},
|
||||
BLACK: {Name: "black role chain", Help: "黑名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
_role_black(m, arg[0], _role_chain(arg[1:]...))
|
||||
@ -129,7 +120,10 @@ func RoleRight(m *ice.Message, userrole string, arg ...string) bool {
|
||||
}
|
||||
func RoleAction(cmds ...string) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(ROLE, WHITE, VOID, m.CommandKey())
|
||||
if c, ok := ice.Info.Index[m.CommandKey()].(*ice.Context); ok && c == m.Target() {
|
||||
m.Cmd(ROLE, WHITE, VOID, m.CommandKey())
|
||||
m.Cmd(ROLE, BLACK, VOID, m.CommandKey(), ice.ACTION)
|
||||
}
|
||||
m.Cmd(ROLE, WHITE, VOID, m.PrefixKey())
|
||||
m.Cmd(ROLE, BLACK, VOID, m.PrefixKey(), ice.ACTION)
|
||||
for _, cmd := range cmds {
|
||||
|
@ -20,7 +20,6 @@ func _sess_create(m *ice.Message, username string) (h string) {
|
||||
}
|
||||
func _sess_check(m *ice.Message, sessid string) {
|
||||
m.Assert(sessid != "")
|
||||
|
||||
val := kit.Dict()
|
||||
mdb.HashSelectDetail(m, sessid, func(value ice.Map) {
|
||||
if !m.WarnTimeNotValid(value[mdb.TIME], sessid) {
|
||||
|
@ -37,7 +37,6 @@ const (
|
||||
AVATAR = "avatar"
|
||||
GENDER = "gender"
|
||||
MOBILE = "mobile"
|
||||
EMAIL = "email"
|
||||
|
||||
CITY = "city"
|
||||
COUNTRY = "country"
|
||||
|
@ -83,6 +83,12 @@ func init() {
|
||||
m.Logs(mdb.CREATE, aaa.WHITE, arg[0])
|
||||
mdb.Rich(m, HOST, kit.Keym(aaa.WHITE), kit.Dict(mdb.TEXT, arg[0]))
|
||||
}},
|
||||
"replace": {Name: "replace", Hand: func(m *ice.Message, arg ...string) {
|
||||
if strings.Contains(arg[0], "://"+LOCALHOST) {
|
||||
arg[0] = strings.Replace(arg[0], "://"+LOCALHOST, "://"+m.Cmd("").Append(aaa.IP), 1)
|
||||
}
|
||||
m.Echo(arg[0])
|
||||
}},
|
||||
}, mdb.HashAction(aaa.BLACK, kit.Data(mdb.SHORT, mdb.TEXT), aaa.WHITE, kit.Data(mdb.SHORT, mdb.TEXT))), Hand: func(m *ice.Message, arg ...string) {
|
||||
_host_list(m, kit.Select("", arg, 0))
|
||||
}},
|
||||
|
@ -76,6 +76,10 @@ func init() {
|
||||
if m.Warn(m.Option(ice.MSG_USERNAME) == "", ice.ErrNotLogin, arg) {
|
||||
return
|
||||
}
|
||||
if len(arg) == 0 {
|
||||
_action_share(m, m.Option("share"))
|
||||
return
|
||||
}
|
||||
if m.Option(ice.MSG_USERPOD) == "" && m.Warn(!_river_right(m, arg[0]), ice.ErrNotRight, arg) {
|
||||
return
|
||||
}
|
||||
|
@ -150,6 +150,17 @@ func init() {
|
||||
}
|
||||
_go_complete(m, arg...)
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case nfs.GO:
|
||||
m.Echo(`package %s
|
||||
|
||||
func init() {
|
||||
|
||||
}
|
||||
`, path.Base(path.Dir(path.Join(arg[2], arg[1]))))
|
||||
}
|
||||
}},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_c_tags(m, GODOC, "gotags", "-f", nfs.TAGS, "-R", nfs.PWD)
|
||||
}},
|
||||
|
Loading…
x
Reference in New Issue
Block a user