diff --git a/controller/kefu.go b/controller/kefu.go index 4442dc1..aa9ac9d 100644 --- a/controller/kefu.go +++ b/controller/kefu.go @@ -1,12 +1,11 @@ package controller import ( - "github.com/dchest/captcha" - "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" "github.com/taoshihan1991/imaptool/models" "github.com/taoshihan1991/imaptool/tools" "github.com/taoshihan1991/imaptool/ws" + "net/http" ) func PostKefuAvator(c *gin.Context) { @@ -161,74 +160,45 @@ func GetKefuInfoSetting(c *gin.Context) { }) } func PostKefuRegister(c *gin.Context) { - name := c.PostForm("name") + name := c.PostForm("username") password := c.PostForm("password") - rePassword := c.PostForm("rePassword") - avator := "/static/images/4.jpg" - nickname := c.PostForm("nickname") - captchaCode := c.PostForm("captcha") - roleId := 1 - if name == "" || password == "" || rePassword == "" || nickname == "" || captchaCode == "" { - c.JSON(200, gin.H{ - "code": 400, - "msg": "参数不能为空", - "result": "", - }) - return - } - if password != rePassword { - c.JSON(200, gin.H{ - "code": 400, - "msg": "密码不一致", - "result": "", - }) - return - } - oldUser := models.FindUser(name) - if oldUser.Name != "" { - c.JSON(200, gin.H{ + avatar := "/static/images/4.jpg" + + if name == "" || password == "" { + c.JSON(http.StatusOK, gin.H{ "code": 400, - "msg": "用户名已经存在", - "result": "", + "msg": "All fields are required", + "result": nil, }) return } - session := sessions.Default(c) - if captchaId := session.Get("captcha"); captchaId != nil { - session.Delete("captcha") - _ = session.Save() - if !captcha.VerifyString(captchaId.(string), captchaCode) { - c.JSON(200, gin.H{ - "code": 400, - "msg": "验证码验证失败", - "result": "", - }) - return - } - } else { - c.JSON(200, gin.H{ - "code": 400, - "msg": "验证码失效", - "result": "", + + existingUser := models.FindUser(name) + if existingUser.Name != "" { + c.JSON(http.StatusOK, gin.H{ + "code": 409, + "msg": "Username already exists", + "result": nil, }) return } - //插入新用户 - uid := models.CreateUser(name, tools.Md5(password), avator, nickname) - if uid == 0 { - c.JSON(200, gin.H{ - "code": 400, - "msg": "增加用户失败", - "result": "", + + userID := models.CreateUser(name, tools.Md5(password), avatar, "") + if userID == 0 { + c.JSON(http.StatusInternalServerError, gin.H{ + "code": 500, + "msg": "Registration Failed", + "result": nil, }) return } - models.CreateUserRole(uid, uint(roleId)) - c.JSON(200, gin.H{ - "code": 200, - "msg": "注册完成", - "result": "", + c.JSON(http.StatusOK, gin.H{ + "code": 200, + "msg": "Registration successful", + "result": gin.H{ + "user_id": userID, + }, }) } func PostKefuInfo(c *gin.Context) { diff --git a/middleware/rbac.go b/middleware/rbac.go index 4ab2cff..f307ba4 100644 --- a/middleware/rbac.go +++ b/middleware/rbac.go @@ -1,50 +1,48 @@ package middleware import ( - "fmt" "github.com/gin-gonic/gin" - "github.com/taoshihan1991/imaptool/models" - "strings" ) func RbacAuth(c *gin.Context) { - roleId, _ := c.Get("role_id") - role := models.FindRole(roleId) - var flag bool - rPaths := strings.Split(c.Request.RequestURI, "?") - uriParam := fmt.Sprintf("%s:%s", c.Request.Method, rPaths[0]) - if role.Method != "*" || role.Path != "*" { - paths := strings.Split(role.Path, ",") - for _, p := range paths { - if uriParam == p { - flag = true - break - } - } - if !flag { - c.JSON(200, gin.H{ - "code": 403, - "msg": "没有权限:" + uriParam, - }) - c.Abort() - return - } - //methods := strings.Split(role.Method, ",") - //for _, m := range methods { - // if c.Request.Method == m { - // methodFlag = true - // break - // } - //} - //if !methodFlag { - // c.JSON(200, gin.H{ - // "code": 403, - // "msg": "没有权限:" + c.Request.Method + "," + rPaths[0], - // }) - // c.Abort() - // return - //} - } + return + //roleId, _ := c.Get("role_id") + //role := models.FindRole(roleId) + //var flag bool + //rPaths := strings.Split(c.Request.RequestURI, "?") + //uriParam := fmt.Sprintf("%s:%s", c.Request.Method, rPaths[0]) + //if role.Method != "*" || role.Path != "*" { + // paths := strings.Split(role.Path, ",") + // for _, p := range paths { + // if uriParam == p { + // flag = true + // break + // } + // } + // if !flag { + // c.JSON(200, gin.H{ + // "code": 403, + // "msg": "没有权限:" + uriParam, + // }) + // c.Abort() + // return + // } + //methods := strings.Split(role.Method, ",") + //for _, m := range methods { + // if c.Request.Method == m { + // methodFlag = true + // break + // } + //} + //if !methodFlag { + // c.JSON(200, gin.H{ + // "code": 403, + // "msg": "没有权限:" + c.Request.Method + "," + rPaths[0], + // }) + // c.Abort() + // return + //} + //} //var flag bool //if role.Path != "*" { // paths := strings.Split(role.Path, ",") diff --git a/static/templates/login.html b/static/templates/login.html index b26c991..f564940 100644 --- a/static/templates/login.html +++ b/static/templates/login.html @@ -1,9 +1,9 @@ - +
-Golang Open Source LiveChat Software
- +Go Open Source Live Chat Software
+