Implement logout

This commit is contained in:
Jan Bader 2016-12-03 20:30:40 +01:00
parent 304b954b51
commit 36b066c687
3 changed files with 11 additions and 1 deletions

View File

@ -75,3 +75,7 @@ func loginSuccess(c *gin.Context, username string, name string) {
"token": t, "token": t,
}) })
} }
func clearLogin(c *gin.Context) {
c.SetCookie(authCookie, "", -1, "", "", false, true)
}

View File

@ -11,6 +11,7 @@ func main() {
router.LoadHTMLGlob("./templates/*") router.LoadHTMLGlob("./templates/*")
router.Static("/static", "./static") router.Static("/static", "./static")
// Middleware // Middleware
//e.Use(middleware.Logger()) //e.Use(middleware.Logger())
//e.Use(middleware.Recover()) //e.Use(middleware.Recover())
@ -18,6 +19,7 @@ func main() {
router.GET("/login.html", login) router.GET("/login.html", login)
a := router.Group("/api/v1") a := router.Group("/api/v1")
{ {
a.GET("/logout", logout)
a.GET("/login", func(c *gin.Context) { a.GET("/login", func(c *gin.Context) {
c.Redirect(http.StatusPermanentRedirect, "/login.html") c.Redirect(http.StatusPermanentRedirect, "/login.html")
}) })
@ -62,6 +64,10 @@ func login(c *gin.Context) {
c.HTML(http.StatusOK, "login.html", nil) c.HTML(http.StatusOK, "login.html", nil)
} }
func logout(c *gin.Context) {
clearLogin(c)
}
func loginPost(c *gin.Context) { func loginPost(c *gin.Context) {
username, _ := c.GetPostForm("username") username, _ := c.GetPostForm("username")
password, _ := c.GetPostForm("password") password, _ := c.GetPostForm("password")