Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
admpub committed Dec 4, 2023
1 parent 4c36f86 commit 131581d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions application/library/backend/oauth2server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions application/library/backend/oauth2server/handler_authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion template/backend/oauth2server/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<h3 class="text-center"><img class="logo-img" src="{{AssetsURL}}/images/logo.png" alt="logo"/>{{"账号授权"|$.T}}</h3>
</div>
<div>
<form class="form-horizontal" action="{{FrontendURL}}/oauth2/auth" method="POST">
<form class="form-horizontal" action="{{BackendURL}}/oauth2/auth" method="POST">
<div class="content">
<div class="form-group">
<div class="col-sm-12">
Expand Down

0 comments on commit 131581d

Please sign in to comment.