add logout api
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user