修复拦截问题,修改发送邮件接口
This commit is contained in:
parent
98f9424e77
commit
66f17ef709
|
|
@ -35,9 +35,9 @@ type GetFileListReq struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SendMailReq struct {
|
type SendMailReq struct {
|
||||||
Title string `json:"title" form:"title"`
|
Title string `json:"title" form:"title" binding:"required"`
|
||||||
Content string `json:"content" form:"content"`
|
Content string `json:"content" form:"content" binding:"required"`
|
||||||
To string `json:"to" form:"to"`
|
To string `json:"to" form:"to" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetUpToolGroup(router *gin.Engine) {
|
func SetUpToolGroup(router *gin.Engine) {
|
||||||
|
|
@ -457,37 +457,29 @@ func SendMail(title, content string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendMailTool(c *gin.Context) {
|
func RequestGetUserInfo(c *gin.Context) *dao.User {
|
||||||
id, _ := c.Get("id")
|
id, _ := c.Get("id")
|
||||||
id1 := int(id.(float64))
|
userId := int(id.(float64))
|
||||||
|
user := service.GetUserByIDWithCache(userId)
|
||||||
|
return &user
|
||||||
|
}
|
||||||
|
|
||||||
|
func SendMailTool(c *gin.Context) {
|
||||||
|
user := RequestGetUserInfo(c)
|
||||||
|
var resp proto.GeneralResp
|
||||||
var req SendMailReq
|
var req SendMailReq
|
||||||
if err := c.ShouldBind(&req); err == nil {
|
if err := c.ShouldBind(&req); err == nil {
|
||||||
user := dao.FindUserByUserID(id1)
|
|
||||||
if user.ID == 0 {
|
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "user not found", "code": proto.ParameterError, "message": "failed"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//目标邮箱地址是否合法
|
|
||||||
if !service.CheckEmail(req.To) {
|
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "email address is invalid", "code": proto.ParameterError, "message": "failed"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.Title == "" || req.Content == "" {
|
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "title or content is empty", "code": proto.ParameterError, "message": "failed"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//发送邮件
|
//发送邮件
|
||||||
if user.Role == "admin" {
|
if user.Role == "admin" {
|
||||||
go service.SendEmail(req.To, req.Title, req.Content)
|
go service.SendEmail(req.To, req.Title, req.Content)
|
||||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": "mail will be sent"})
|
resp.Code, resp.Data, resp.Message = proto.SuccessCode, "mail will be sent", "success"
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "no send mail permission", "code": proto.PermissionDenied, "message": "failed"})
|
resp.Code, resp.Data, resp.Message = proto.PermissionDenied, "mail will be sent", "error"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{"error": err.Error(), "code": proto.ParameterError, "message": "failed"})
|
resp.Data, resp.Data, resp.Message = proto.ParameterError, "toEmail or title or content request param error", "success"
|
||||||
}
|
}
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadProxyHandle 处理下载代理请求
|
// DownloadProxyHandle 处理下载代理请求
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -163,7 +163,7 @@ func JWTAuthMiddleware() gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
if tokenString == "" {
|
if tokenString == "" {
|
||||||
//c.AbortWithStatus(200)
|
//c.AbortWithStatus(200)
|
||||||
c.JSON(http.StatusOK, gin.H{"message": "Unauthorized", "error": "token is empty", "code": proto.TokenIsNull})
|
c.AbortWithStatusJSON(http.StatusOK, gin.H{"message": "Unauthorized", "error": "token is empty", "code": proto.TokenIsNull})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if proto.Config.TOKEN_USE_REDIS {
|
if proto.Config.TOKEN_USE_REDIS {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue