Skip to content

Commit

Permalink
improve auth
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Sep 11, 2018
1 parent f97d41d commit 8e7775b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugins/admin/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func InitRouter(prefix string) *context.App {
"Location": prefix + "/login",
}, ``)
}).SetPermissionDenyCallback(func (ctx *context.Context) {
controller.ShowErrorPage(ctx, "permission deny")
controller.ShowErrorPage(ctx, "permission denied")
})

app.Group("", authenticator.Middleware)
Expand Down
11 changes: 10 additions & 1 deletion plugins/example/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ package example
import (
"github.com/chenhg5/go-admin/context"
"github.com/chenhg5/go-admin/modules/auth"
"github.com/chenhg5/go-admin/plugins/admin/controller"
)

func InitRouter(prefix string) *context.App {
app := context.NewApp()

app.GET(prefix + "/example", auth.SetPrefix(prefix).Middleware(TestHandler))
authenticator := auth.SetPrefix(prefix).SetAuthFailCallback(func (ctx *context.Context) {
ctx.Write(302, map[string]string{
"Location": prefix + "/login",
}, ``)
}).SetPermissionDenyCallback(func (ctx *context.Context) {
controller.ShowErrorPage(ctx, "permission denied")
})

app.GET(prefix + "/example", authenticator.Middleware(TestHandler))

return app
}

0 comments on commit 8e7775b

Please sign in to comment.