mirror of
https://shylinux.com/x/icebergs
synced 2025-05-01 03:09:21 +08:00
opt ice.MSG_LANGUAGE
This commit is contained in:
parent
aba012a20e
commit
5051a7d2c1
@ -1,8 +1,11 @@
|
|||||||
package aaa
|
package aaa
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
|
"shylinux.com/x/icebergs/base/web/html"
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
"shylinux.com/x/toolkits/logs"
|
"shylinux.com/x/toolkits/logs"
|
||||||
)
|
)
|
||||||
@ -46,14 +49,20 @@ func SessCreate(m *ice.Message, username string) string {
|
|||||||
return m.Option(ice.MSG_SESSID, m.Cmdx(SESS, mdb.CREATE, username))
|
return m.Option(ice.MSG_SESSID, m.Cmdx(SESS, mdb.CREATE, username))
|
||||||
}
|
}
|
||||||
func SessCheck(m *ice.Message, sessid string) bool {
|
func SessCheck(m *ice.Message, sessid string) bool {
|
||||||
m.Options(ice.MSG_USERNICK, "", ice.MSG_USERNAME, "", ice.MSG_USERROLE, VOID, "aaa.checker", logs.FileLine(-1))
|
m.Options(ice.MSG_USERNICK, "", ice.MSG_USERNAME, "", ice.MSG_USERROLE, VOID, ice.MSG_LANGUAGE, "", "aaa.checker", logs.FileLine(-1))
|
||||||
return sessid != "" && m.Cmdy(SESS, CHECK, sessid, logs.FileLineMeta(-1)).Option(ice.MSG_USERNAME) != ""
|
return sessid != "" && m.Cmdy(SESS, CHECK, sessid, logs.FileLineMeta(-1)).Option(ice.MSG_USERNAME) != ""
|
||||||
}
|
}
|
||||||
func SessAuth(m *ice.Message, value ice.Any, arg ...string) *ice.Message {
|
func SessAuth(m *ice.Message, value ice.Any, arg ...string) *ice.Message {
|
||||||
|
language := kit.Format(kit.Value(value, LANGUAGE))
|
||||||
|
kit.If(language == "", func() { language = kit.Select("", "zh-cn", strings.Contains(m.Option(ice.MSG_USERUA), "zh_CN")) })
|
||||||
|
kit.If(language == "" && m.R != nil, func() { language = kit.Select("", kit.Split(m.R.Header.Get(html.AcceptLanguage), ",;"), 0) })
|
||||||
|
kit.If(language == "", func() { language = ice.Info.Lang })
|
||||||
|
language = strings.ReplaceAll(strings.ToLower(kit.Split(language, " .")[0]), "_", "-")
|
||||||
return m.Auth(
|
return m.Auth(
|
||||||
USERNICK, m.Option(ice.MSG_USERNICK, kit.Format(kit.Value(value, USERNICK))),
|
USERNICK, m.Option(ice.MSG_USERNICK, kit.Format(kit.Value(value, USERNICK))),
|
||||||
USERNAME, m.Option(ice.MSG_USERNAME, kit.Format(kit.Value(value, USERNAME))),
|
USERNAME, m.Option(ice.MSG_USERNAME, kit.Format(kit.Value(value, USERNAME))),
|
||||||
USERROLE, m.Option(ice.MSG_USERROLE, kit.Format(kit.Value(value, USERROLE))),
|
USERROLE, m.Option(ice.MSG_USERROLE, kit.Format(kit.Value(value, USERROLE))),
|
||||||
|
LANGUAGE, m.Option(ice.MSG_LANGUAGE, language),
|
||||||
arg, logs.FileLineMeta(kit.Select(logs.FileLine(-1), m.Option("aaa.checker"))),
|
arg, logs.FileLineMeta(kit.Select(logs.FileLine(-1), m.Option("aaa.checker"))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -77,3 +77,7 @@ func FormatDanger(value string) string {
|
|||||||
COLOR, "var(--danger-fg-color)",
|
COLOR, "var(--danger-fg-color)",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
AcceptLanguage = "Accept-Language"
|
||||||
|
)
|
||||||
|
@ -178,12 +178,15 @@ func _serve_auth(m *ice.Message, key string, cmds []string, w http.ResponseWrite
|
|||||||
ls := kit.Simple(mdb.Cache(m, m.Option(ice.MSG_USERIP), func() ice.Any {
|
ls := kit.Simple(mdb.Cache(m, m.Option(ice.MSG_USERIP), func() ice.Any {
|
||||||
if IsLocalHost(m) {
|
if IsLocalHost(m) {
|
||||||
aaa.UserRoot(m)
|
aaa.UserRoot(m)
|
||||||
return kit.Simple(m.Time(), m.OptionSplit(ice.MSG_USERNICK, ice.MSG_USERNAME, ice.MSG_USERROLE))
|
return kit.Simple(m.Time(), m.OptionSplit(ice.MSG_USERNICK, ice.MSG_USERNAME, ice.MSG_USERROLE, ice.MSG_LANGUAGE))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
if len(ls) > 0 {
|
if len(ls) > 0 {
|
||||||
m.Auth(aaa.USERNICK, m.Option(ice.MSG_USERNICK, ls[1]), aaa.USERNAME, m.Option(ice.MSG_USERNAME, ls[2]), aaa.USERROLE, m.Option(ice.MSG_USERROLE, ls[3]), CACHE, ls[0])
|
m.Auth(aaa.USERNICK, m.Option(ice.MSG_USERNICK, ls[1]),
|
||||||
|
aaa.USERNAME, m.Option(ice.MSG_USERNAME, ls[2]),
|
||||||
|
aaa.USERROLE, m.Option(ice.MSG_USERROLE, ls[3]),
|
||||||
|
aaa.LANGUAGE, m.Option(ice.MSG_LANGUAGE, ls[4]), CACHE, ls[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Cmd(COUNT, mdb.CREATE, aaa.IP, m.Option(ice.MSG_USERIP), m.Option(ice.MSG_USERUA), kit.Dict(ice.LOG_DISABLE, ice.TRUE))
|
m.Cmd(COUNT, mdb.CREATE, aaa.IP, m.Option(ice.MSG_USERIP), m.Option(ice.MSG_USERUA), kit.Dict(ice.LOG_DISABLE, ice.TRUE))
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package chat
|
package chat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/aaa"
|
"shylinux.com/x/icebergs/base/aaa"
|
||||||
"shylinux.com/x/icebergs/base/cli"
|
"shylinux.com/x/icebergs/base/cli"
|
||||||
@ -131,13 +129,9 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
msg := m.Cmd(aaa.USER, m.Option(ice.MSG_USERNAME))
|
msg := m.Cmd(aaa.USER, m.Option(ice.MSG_USERNAME))
|
||||||
kit.For([]string{aaa.LANGUAGE, aaa.USERNICK, aaa.EMAIL}, func(k string) { m.Option(k, msg.Append(k)) })
|
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.AVATAR, aaa.BACKGROUND}, func(k string) { m.Option(k, web.RequireFile(m, msg.Append(k))) })
|
kit.For([]string{aaa.AVATAR, aaa.BACKGROUND}, func(k string) { m.Option(k, web.RequireFile(m, msg.Append(k))) })
|
||||||
kit.If(m.Option(aaa.LANGUAGE) == "", func() {
|
|
||||||
m.Option(aaa.LANGUAGE, kit.Select("", "zh-cn", strings.Contains(m.Option(ice.MSG_USERUA), "zh_CN")))
|
|
||||||
})
|
|
||||||
kit.If(m.Option(aaa.LANGUAGE) == "", func() { m.Option(aaa.LANGUAGE, kit.Select("", kit.Split(m.R.Header.Get(web.AcceptLanguage), ",;"), 0)) })
|
|
||||||
kit.If(m.Option(aaa.LANGUAGE) == "", func() { m.Option(aaa.LANGUAGE, ice.Info.Lang) })
|
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user