diff --git a/application/library/backend/oauth2server/handler.go b/application/library/backend/oauth2server/handler.go index 69f0c519f0..01495ca741 100644 --- a/application/library/backend/oauth2server/handler.go +++ b/application/library/backend/oauth2server/handler.go @@ -10,6 +10,7 @@ import ( "github.com/webx-top/echo/formfilter" "github.com/admpub/nging/v5/application/dbschema" + "github.com/admpub/nging/v5/application/handler" handlerIndex "github.com/admpub/nging/v5/application/handler/index" "github.com/admpub/nging/v5/application/library/common" "github.com/admpub/nging/v5/application/model" @@ -50,7 +51,7 @@ func loginHandler(w http.ResponseWriter, r *http.Request) { println(`[loginHandler.Forms]:`, echo.Dump(ctx.Forms(), false)) } - ctx.Request().Form().Set(`next`, RoutePrefix+`/auth`) + ctx.Request().Form().Set(`next`, handler.URLFor(RoutePrefix+`/auth`)) err := handlerIndex.Login(ctx) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) @@ -73,7 +74,7 @@ func authHandler(w http.ResponseWriter, r *http.Request) { user, ok := ctx.Session().Get(`user`).(*dbschema.NgingUser) var err error if !ok || user == nil { - err = ctx.Redirect(RoutePrefix + `/login`) + err = ctx.Redirect(handler.URLFor(RoutePrefix + `/login`)) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) } @@ -115,7 +116,7 @@ func authHandler(w http.ResponseWriter, r *http.Request) { return } if agreed { - err = ctx.Redirect(RoutePrefix + `/authorize`) + err = ctx.Redirect(handler.URLFor(RoutePrefix + `/authorize`)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } @@ -126,7 +127,7 @@ func authHandler(w http.ResponseWriter, r *http.Request) { if accept { err = m.Save(user.Id, clientID, scopes) if err == nil { - err = ctx.Redirect(RoutePrefix + `/authorize`) + err = ctx.Redirect(handler.URLFor(RoutePrefix + `/authorize`)) } if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/application/library/backend/oauth2server/handler_authorize.go b/application/library/backend/oauth2server/handler_authorize.go index 1ef85df8e5..07becc07f9 100644 --- a/application/library/backend/oauth2server/handler_authorize.go +++ b/application/library/backend/oauth2server/handler_authorize.go @@ -7,6 +7,7 @@ import ( "github.com/admpub/log" "github.com/admpub/nging/v5/application/dbschema" + "github.com/admpub/nging/v5/application/handler" "github.com/admpub/nging/v5/application/middleware" "github.com/admpub/nging/v5/application/model" "github.com/webx-top/echo" @@ -40,7 +41,7 @@ func UserAuthorizeHandler(w http.ResponseWriter, r *http.Request) (userID string if !ok || user == nil { // 没有登录时记录当前的提交数据 ctx.Session().Set(requestFormDataCacheKey, ctx.Forms()) - err = ctx.Redirect(RoutePrefix + `/login`) + err = ctx.Redirect(handler.URLFor(RoutePrefix + `/login`)) return } clientID := ctx.Form("client_id") @@ -58,7 +59,7 @@ func UserAuthorizeHandler(w http.ResponseWriter, r *http.Request) (userID string if !agreed { // 没有授权时记录当前的提交数据 ctx.Session().Set(requestFormDataCacheKey, ctx.Forms()) - err = ctx.Redirect(RoutePrefix + `/auth`) + err = ctx.Redirect(handler.URLFor(RoutePrefix + `/auth`)) return } userID = param.AsString(user.Id) diff --git a/template/backend/oauth2server/auth.html b/template/backend/oauth2server/auth.html index a1481be178..6cc1b2510f 100644 --- a/template/backend/oauth2server/auth.html +++ b/template/backend/oauth2server/auth.html @@ -12,7 +12,7 @@

logo{{"账号授权"|$.T}}

-
+