add logout api

This commit is contained in:
Jay
2018-04-18 15:05:37 +08:00
parent 6419162471
commit d86e8e47f4
3 changed files with 41 additions and 0 deletions
+18
View File
@@ -95,3 +95,21 @@ func UserLogin(c *context.Context) {
c.Success(m)
}
// UserLogout route
func UserLogout(c *context.Context) {
token := c.GetHeader("X-Auth-Token")
// token, ok := c.C["token"]
if len(token) == 0 {
c.DataFormat("token not found")
return
}
err := memstore.RedisDel("golang", token)
if err != nil {
c.ServerError("remvoe session fail")
return
}
c.Success(nil)
}
+1
View File
@@ -40,5 +40,6 @@ func SetDefaultRoutes(r *gin.Engine) {
accountAPI := api.Group("/account")
{
accountAPI.POST("/login", context.PatchContext(account.UserLogin))
accountAPI.POST("/logout", context.PatchContext(account.UserLogout))
}
}