From cee53d8626df326da5ff4561a07cb202930ef0d5 Mon Sep 17 00:00:00 2001 From: shy Date: Mon, 3 Jan 2022 14:04:52 +0800 Subject: [PATCH] opt sso --- base/web/render.go | 5 +++-- core/chat/header.go | 8 ++------ core/chat/sso.go | 6 ++++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/base/web/render.go b/base/web/render.go index 80e5ced2..4714fbdb 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -32,11 +32,11 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) { RenderCookie(msg, arg[0], arg[1:]...) case ice.RENDER_REDIRECT: // url [arg...] - http.Redirect(msg.W, msg.R, kit.MergeURL(arg[0], arg[1:]), 307) + http.Redirect(msg.W, msg.R, kit.MergeURL(arg[0], arg[1:]), http.StatusSeeOther) case ice.RENDER_DOWNLOAD: // file [type [name]] if strings.HasPrefix(arg[0], "http") { - http.Redirect(msg.W, msg.R, arg[0], 307) + http.Redirect(msg.W, msg.R, arg[0], http.StatusSeeOther) break } msg.W.Header().Set("Content-Disposition", fmt.Sprintf("filename=%s", kit.Select(path.Base(kit.Select(arg[0], msg.Option("filename"))), arg, 2))) @@ -85,6 +85,7 @@ func CookieName(url string) string { } func RenderCookie(msg *ice.Message, value string, arg ...string) { // name path expire expire := time.Now().Add(kit.Duration(kit.Select(msg.Conf(aaa.SESS, "meta.expire"), arg, 2))) + msg.Debug("what %v %v", value, arg) http.SetCookie(msg.W, &http.Cookie{Value: value, Name: kit.Select(ice.MSG_SESSID, arg, 0), Path: kit.Select("/", arg, 1), Expires: expire}) } diff --git a/core/chat/header.go b/core/chat/header.go index 76038792..0677eb67 100644 --- a/core/chat/header.go +++ b/core/chat/header.go @@ -86,10 +86,8 @@ func init() { }, Commands: map[string]*ice.Command{ web.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { switch arg[0] { - case "/sso/": - if m.Option(ice.MSG_USERNAME) != "" { - return - } + case "/sso": + return case "/pod/": return // 免登录 case "/header": @@ -154,9 +152,7 @@ func init() { if m.Cmd(GRANT, m.Option(ice.POD), 1).Length() > 0 { _header_grant(m, web.SPACE, m.Option(GRANT)) } - m.Debug("what %v", m.FormatMeta()) m.Option(GRANT, ice.TRUE) - m.Debug("what %v", m.FormatMeta()) } m.Option(TRANS, kit.Format(kit.Value(c.Commands[cmd].Meta, "_trans"))) diff --git a/core/chat/sso.go b/core/chat/sso.go index 66d1242c..533a670e 100644 --- a/core/chat/sso.go +++ b/core/chat/sso.go @@ -13,6 +13,10 @@ const SSO = "sso" func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ "/sso": {Name: "/sso", Help: "登录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if m.Option(ice.MSG_USERNAME) == "" { + m.RenderIndex(web.SERVE, ice.VOLCANOS) + return + } sessid := m.Cmdx(web.SPACE, m.Option(web.SPACE), aaa.SESS, mdb.CREATE, mdb.TIME, m.Time("720h"), aaa.USERROLE, m.Option(ice.MSG_USERROLE), @@ -20,6 +24,8 @@ func init() { aaa.USERNICK, m.Option(ice.MSG_USERNICK), ) m.RenderRedirect(kit.MergeURL(m.Option("back"), ice.MSG_SESSID, sessid)) + // web.RenderCookie(m, sessid, web.CookieName(m.Option("back"))) + // m.RenderRedirect(kit.MergeURL(m.Option("back"))) }}, }}) }