Commit 37159233 by xuzhenhao

增加了注销功能

1 parent 10ea3104
...@@ -66,9 +66,6 @@ func UserLoginApi(c *gin.Context) { ...@@ -66,9 +66,6 @@ func UserLoginApi(c *gin.Context) {
HttpOnly: true, HttpOnly: true,
Expires: time.Now().Add(2 * time.Hour), Expires: time.Now().Add(2 * time.Hour),
} }
// res := map[string]interface{}{
// "user_id": result.(map[string]interface{})["user_id"].(int),
// }
http.SetCookie(c.Writer, cookie) http.SetCookie(c.Writer, cookie)
ReturnRespones(c, "0", "authorize success") ReturnRespones(c, "0", "authorize success")
return return
...@@ -150,6 +147,24 @@ func ChangeUserPasswordApi(c *gin.Context) { ...@@ -150,6 +147,24 @@ func ChangeUserPasswordApi(c *gin.Context) {
return return
} }
//用户注销接口
func UserLogoutApi(c *gin.Context) {
token, err := c.Cookie("icesimbaToken")
if err != nil {
log.Println(err)
ReturnRespones(c, "104000", err)
return
}
cookie := &http.Cookie{
Name: "icesimbaToken",
Path: "/",
MaxAge: -1,
}
http.SetCookie(c.Writer, cookie)
ReturnRespones(c, "0", "成功注销")
return
}
//返回函数 //返回函数
func ReturnRespones(c *gin.Context, code string, result interface{}) { func ReturnRespones(c *gin.Context, code string, result interface{}) {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
......
...@@ -239,5 +239,10 @@ func CheckRequestToken(token string) (result interface{}, err error) { ...@@ -239,5 +239,10 @@ func CheckRequestToken(token string) (result interface{}, err error) {
err = errors.New("token已失效") err = errors.New("token已失效")
return "105005", err return "105005", err
} }
return string(r[0]["user_id"]), nil id := string(r[0]["user_id"])
idInt, err := strconv.Atoi(id)
if err != nil {
return "104000", err
}
return idInt, nil
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!