mirror of
https://github.com/cuigh/swirl
synced 2024-12-28 23:02:02 +00:00
Customize 403/404 error pages
This commit is contained in:
parent
4bf5588c9c
commit
8c00a7f69d
@ -10,6 +10,7 @@ import (
|
||||
|
||||
type HomeController struct {
|
||||
Index web.HandlerFunc `path:"/" name:"index" authorize:"?" desc:"index page"`
|
||||
Error403 web.HandlerFunc `path:"/403" name:"403" authorize:"?" desc:"403 page"`
|
||||
Error404 web.HandlerFunc `path:"/404" name:"404" authorize:"*" desc:"404 page"`
|
||||
Login web.HandlerFunc `path:"/login" name:"login" authorize:"*" desc:"sign in page"`
|
||||
InitGet web.HandlerFunc `path:"/init" name:"init" authorize:"*" desc:"initialize page"`
|
||||
@ -95,8 +96,13 @@ func Home() (c *HomeController) {
|
||||
return ajaxResult(ctx, err)
|
||||
}
|
||||
|
||||
c.Error403 = func(ctx web.Context) error {
|
||||
return ctx.Render("403", nil)
|
||||
}
|
||||
|
||||
c.Error404 = func(ctx web.Context) error {
|
||||
return ctx.Render("404", nil)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
9
main.go
9
main.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
@ -18,6 +19,14 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
// customize error handler
|
||||
web.DefaultErrorHandler.OnCode(http.StatusNotFound, func(ctx web.Context, err error) {
|
||||
ctx.Redirect("/404")
|
||||
})
|
||||
web.DefaultErrorHandler.OnCode(http.StatusForbidden, func(ctx web.Context, err error) {
|
||||
ctx.Redirect("/403")
|
||||
})
|
||||
|
||||
ws := web.Auto()
|
||||
|
||||
// set render/validator..
|
||||
|
23
views/403.jet
Normal file
23
views/403.jet
Normal file
@ -0,0 +1,23 @@
|
||||
{{ extends "_layouts/empty" }}
|
||||
{{ block body() }}
|
||||
<section class="hero is-light is-fullheight is-bold">
|
||||
<div class="hero-body">
|
||||
<div class="container">
|
||||
<div class="columns">
|
||||
<div class="column is-6 is-offset-3">
|
||||
<div class="content">
|
||||
<h1 class="title is-1 has-text-centered has-text-danger is-marginless">403</h1>
|
||||
<h2 class="title has-text-centered has-text-black">Forbidden</h2>
|
||||
<p class="has-text-centered">
|
||||
You do not have permission to access this page.
|
||||
</p>
|
||||
<div class="has-text-centered">
|
||||
<a href="/" class="has-text-centered button is-primary is-outlined">To Home Page</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{{ end }}
|
Loading…
Reference in New Issue
Block a user