fix: 登录/注册支持 redirect 参数,未登录跳转自动携带来源页
- login.js/register.js 登录成功后优先跳转 redirect 参数指定页面 - 新增 common.RedirectToLogin 辅助函数,自动携带当前路径 - 替换所有 9 处硬编码 /auth/login 重定向
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
|
||||
"metazone.cc/metalab/internal/model"
|
||||
@ -74,6 +77,16 @@ func BuildAdminPageData(c *gin.Context, extra gin.H) gin.H {
|
||||
return data
|
||||
}
|
||||
|
||||
// RedirectToLogin 重定向到登录页,携带当前页面路径作为 redirect 参数
|
||||
func RedirectToLogin(c *gin.Context) {
|
||||
returnURL := url.QueryEscape(c.Request.URL.Path)
|
||||
if c.Request.URL.RawQuery != "" {
|
||||
returnURL = url.QueryEscape(c.Request.URL.Path + "?" + c.Request.URL.RawQuery)
|
||||
}
|
||||
c.Redirect(http.StatusFound, fmt.Sprintf("/auth/login?redirect=%s", returnURL))
|
||||
c.Abort()
|
||||
}
|
||||
|
||||
// injectSiteInfo 从 context 注入站点展示信息
|
||||
func injectSiteInfo(c *gin.Context, data gin.H) {
|
||||
if framework, exists := c.Get("site_framework"); exists {
|
||||
|
||||
Reference in New Issue
Block a user