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,
|
||||
})
|
||||
}
|
||||
|
||||
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.Static("/static", "./static")
|
||||
|
||||
// Middleware
|
||||
//e.Use(middleware.Logger())
|
||||
//e.Use(middleware.Recover())
|
||||
@ -18,6 +19,7 @@ func main() {
|
||||
router.GET("/login.html", login)
|
||||
a := router.Group("/api/v1")
|
||||
{
|
||||
a.GET("/logout", logout)
|
||||
a.GET("/login", func(c *gin.Context) {
|
||||
c.Redirect(http.StatusPermanentRedirect, "/login.html")
|
||||
})
|
||||
@ -62,6 +64,10 @@ func login(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "login.html", nil)
|
||||
}
|
||||
|
||||
func logout(c *gin.Context) {
|
||||
clearLogin(c)
|
||||
}
|
||||
|
||||
func loginPost(c *gin.Context) {
|
||||
username, _ := c.GetPostForm("username")
|
||||
password, _ := c.GetPostForm("password")
|
||||
|
@ -41,7 +41,7 @@
|
||||
The entered credentials are invalid
|
||||
</div>
|
||||
|
||||
<input type="submit" value="Login"/>
|
||||
<input type="submit" value="Login" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user