mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 03:17:04 +00:00
New Context.SetLogoutFunc/Logout and SetFunc/CallFunc methods
Read HISTORY.md
This commit is contained in:
@@ -37,6 +37,8 @@ func newApp() *iris.Application {
|
||||
|
||||
// http://localhost:8080/admin/settings
|
||||
needAuth.Get("/settings", h)
|
||||
|
||||
needAuth.Get("/logout", logout)
|
||||
}
|
||||
|
||||
return app
|
||||
@@ -55,3 +57,11 @@ func h(ctx iris.Context) {
|
||||
|
||||
ctx.Writef("%s %s:%s", ctx.Path(), username, password)
|
||||
}
|
||||
|
||||
func logout(ctx iris.Context) {
|
||||
err := ctx.Logout() // fires 401, invalidates the basic auth.
|
||||
if err != nil {
|
||||
ctx.Application().Logger().Errorf("Logout error: %v", err)
|
||||
}
|
||||
ctx.Redirect("/admin", iris.StatusTemporaryRedirect)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user