Implement logout
This commit is contained in:
parent
304b954b51
commit
36b066c687
4
login.go
4
login.go
@ -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)
|
||||||
|
}
|
||||||
|
6
main.go
6
main.go
@ -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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user