diff --git a/controller/blog.go b/controller/blog.go index 77a91f2..834393d 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -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" +} \ No newline at end of file diff --git a/controller/middle/auth.go b/controller/middle/auth.go index e3cb043..fda3816 100644 --- a/controller/middle/auth.go +++ b/controller/middle/auth.go @@ -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, }) diff --git a/controller/user.go b/controller/user.go index 2f73aee..e1c1af3 100644 --- a/controller/user.go +++ b/controller/user.go @@ -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() { diff --git a/main.go b/main.go index 3ee1451..3fb7a36 100644 --- a/main.go +++ b/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) } diff --git a/model/blog.go b/model/blog.go index ba91555..4501dfc 100644 --- a/model/blog.go +++ b/model/blog.go @@ -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 +} \ No newline at end of file