fix: 登录/注册支持 redirect 参数,未登录跳转自动携带来源页

- login.js/register.js 登录成功后优先跳转 redirect 参数指定页面
- 新增 common.RedirectToLogin 辅助函数,自动携带当前路径
- 替换所有 9 处硬编码 /auth/login 重定向
This commit is contained in:
2026-05-31 01:23:09 +08:00
parent 9d84d6bf25
commit a62039e6bb
8 changed files with 39 additions and 15 deletions

View File

@ -14,8 +14,7 @@ import (
func (mc *MessageController) MessagesPage(c *gin.Context) {
uidVal, exists := c.Get("uid")
if !exists {
c.Redirect(http.StatusFound, "/auth/login")
c.Abort()
common.RedirectToLogin(c)
return
}
uid := uidVal.(uint)

View File

@ -58,8 +58,7 @@ func NewSettingsController(authService profileProvider, avatarService avatarProv
func (sc *SettingsController) SettingsPage(c *gin.Context) {
uidVal, exists := c.Get("uid")
if !exists {
c.Redirect(http.StatusFound, "/auth/login")
c.Abort()
common.RedirectToLogin(c)
return
}
uid := uidVal.(uint)

View File

@ -23,7 +23,7 @@ func NewSpaceController(spaceService spaceUseCase) *SpaceController {
func (ctrl *SpaceController) MySpace(c *gin.Context) {
uid, _, ok := common.GetGinUser(c)
if !ok {
c.Redirect(http.StatusFound, "/auth/login")
common.RedirectToLogin(c)
return
}
c.Redirect(http.StatusFound, "/space/"+strconv.FormatUint(uint64(uid), 10))

View File

@ -28,7 +28,7 @@ func NewStudioController(ps studioUseCase) *StudioController {
func (ctrl *StudioController) OverviewPage(c *gin.Context) {
uid, _, ok := common.GetGinUser(c)
if !ok {
c.Redirect(http.StatusFound, "/auth/login")
common.RedirectToLogin(c)
return
}
@ -56,7 +56,7 @@ func (ctrl *StudioController) OverviewPage(c *gin.Context) {
func (ctrl *StudioController) PostsPage(c *gin.Context) {
uid, _, ok := common.GetGinUser(c)
if !ok {
c.Redirect(http.StatusFound, "/auth/login")
common.RedirectToLogin(c)
return
}
@ -96,7 +96,7 @@ func (ctrl *StudioController) PostsPage(c *gin.Context) {
func (ctrl *StudioController) DraftsPage(c *gin.Context) {
uid, _, ok := common.GetGinUser(c)
if !ok {
c.Redirect(http.StatusFound, "/auth/login")
common.RedirectToLogin(c)
return
}
@ -131,7 +131,7 @@ func (ctrl *StudioController) DraftsPage(c *gin.Context) {
func (ctrl *StudioController) WritePage(c *gin.Context) {
uid, _, ok := common.GetGinUser(c)
if !ok {
c.Redirect(http.StatusFound, "/auth/login")
common.RedirectToLogin(c)
return
}
@ -171,7 +171,7 @@ func (ctrl *StudioController) WritePage(c *gin.Context) {
func (ctrl *StudioController) AnalyticsPage(c *gin.Context) {
uid, _, ok := common.GetGinUser(c)
if !ok {
c.Redirect(http.StatusFound, "/auth/login")
common.RedirectToLogin(c)
return
}