退出接口添加删除redis token
parent
e516b374af
commit
653a972b8f
|
@ -199,3 +199,24 @@ func ArticlesType(c *gin.Context) {
|
|||
rsp.Msg = "OK"
|
||||
rsp.Status = 0
|
||||
}
|
||||
func DeleteArticle(c *gin.Context) {
|
||||
|
||||
rsp := RespBase{Msg:"FAIL", Status:210,}
|
||||
defer func() {
|
||||
c.JSON(200,rsp)
|
||||
}()
|
||||
sid := c.Param("id")
|
||||
id,err := strconv.Atoi(sid)
|
||||
if nil != err{
|
||||
rsp.Status = -234
|
||||
c.JSON(200,rsp)
|
||||
}
|
||||
err = model.DeleteDoc(int64(id))
|
||||
if nil != err{
|
||||
rsp.Status = -234
|
||||
c.JSON(200,rsp)
|
||||
}
|
||||
rsp.Data = id
|
||||
rsp.Status = 0
|
||||
rsp.Msg = "OK"
|
||||
}
|
|
@ -13,7 +13,8 @@ func AuthMiddle(c *gin.Context) {
|
|||
token := c.Query("token")
|
||||
user := c.Query("userid")
|
||||
if user == "" || token == ""{
|
||||
log.Print("error user not existed")
|
||||
log.Print("error user not existed or token missing")
|
||||
log.Print(c.Request.URL.String())
|
||||
c.JSON(200,controller.RespBase{
|
||||
"auth err",20,nil,
|
||||
})
|
||||
|
|
|
@ -446,8 +446,10 @@ func (this *UserController) Register(c *gin.Context) {
|
|||
}
|
||||
|
||||
func (this *UserController) Logout(c *gin.Context) {
|
||||
token := c.Param("token")
|
||||
log.Print("logout token is ",token)
|
||||
var resp RespBase
|
||||
|
||||
config.RedisOne().Del(token)
|
||||
resp.Msg = "退出成功"
|
||||
resp.Status = 0
|
||||
defer func() {
|
||||
|
|
4
main.go
4
main.go
|
@ -92,7 +92,7 @@ func main() {
|
|||
/** 用户注册 **/
|
||||
api.POST("/register", userController.Register)
|
||||
/** 用户退出登陆 **/
|
||||
api.GET("/logout", middle.AuthMiddle,userController.Logout)
|
||||
api.GET("/logout/:token", userController.Logout)
|
||||
api.POST("/verify", mailContoller.OnSendEmailCode)
|
||||
/** 修改密码**/
|
||||
api.POST("modify_pass",middle.AuthMiddle,userController.ModifyPasswd)
|
||||
|
@ -103,7 +103,7 @@ func main() {
|
|||
api.GET("article_type",controller.ArticlesType) //获取所有文章分类
|
||||
api.POST("/article_update",controller.UpdateArtilce)
|
||||
api.GET("/articleCount",controller.GetArticleCount)
|
||||
|
||||
api.DELETE("/article/:id",controller.DeleteArticle)
|
||||
api.POST("/image_upload",fileController.OnUpload)
|
||||
api.GET("/image_download/:file",fileController.OnDownLoad)
|
||||
}
|
||||
|
|
|
@ -58,3 +58,13 @@ func UpdateDoc(doc Doc) error{
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteDoc(id int64) error{
|
||||
sql := fmt.Sprintf(`delete from doc where id = %d`,id)
|
||||
_, e := db.GetMysqlClient().Query(sql)
|
||||
if nil != e {
|
||||
logs.Error(e.Error())
|
||||
return e
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue