diff --git a/src/modules/common/common.go b/src/modules/common/common.go index a8090847..13f0b9cf 100644 --- a/src/modules/common/common.go +++ b/src/modules/common/common.go @@ -63,7 +63,7 @@ func Setup(router *gin.Engine) { Count: 10, Type: middleware.LIMIT_IP, }), - controller.NewRegister.UserName, + controller.NewRegister.Register, ) } @@ -71,6 +71,7 @@ func Setup(router *gin.Engine) { commonGroup := router.Group("/common") { commonGroup.GET("/hash", middleware.PreAuthorize(nil), controller.NewCommont.Hash) + indexGroup.GET("/sysConf", controller.NewCommont.SysConfig) } // 文件操作处理 diff --git a/src/modules/common/controller/register.go b/src/modules/common/controller/register.go index b83cb5dd..3e177e03 100644 --- a/src/modules/common/controller/register.go +++ b/src/modules/common/controller/register.go @@ -1,8 +1,6 @@ package controller import ( - "strings" - commonConstants "ems.agt/src/framework/constants/common" ctxUtils "ems.agt/src/framework/utils/ctx" "ems.agt/src/framework/utils/regular" @@ -32,8 +30,8 @@ type RegisterController struct { // 账号注册 // -// GET /captchaImage -func (s *RegisterController) UserName(c *gin.Context) { +// GET /register +func (s *RegisterController) Register(c *gin.Context) { var registerBody commonModel.RegisterBody if err := c.ShouldBindJSON(®isterBody); err != nil { c.JSON(400, result.ErrMsg("参数错误")) @@ -74,9 +72,9 @@ func (s *RegisterController) UserName(c *gin.Context) { return } - infoStr := s.registerService.ByUserName(registerBody.Username, registerBody.Password, registerBody.UserType) - if !strings.HasPrefix(infoStr, "注册") { - msg := registerBody.Username + " 注册成功 " + infoStr + userID, err := s.registerService.ByUserName(registerBody.Username, registerBody.Password, registerBody.UserType) + if err == nil { + msg := registerBody.Username + " 注册成功 " + userID s.sysLogLoginService.CreateSysLogLogin( registerBody.Username, commonConstants.STATUS_YES, msg, ipaddr, location, os, browser, @@ -84,5 +82,5 @@ func (s *RegisterController) UserName(c *gin.Context) { c.JSON(200, result.OkMsg("注册成功")) return } - c.JSON(200, result.ErrMsg(infoStr)) + c.JSON(200, result.ErrMsg(err.Error())) } diff --git a/src/modules/common/service/register.go b/src/modules/common/service/register.go index 6570c50a..dc986835 100644 --- a/src/modules/common/service/register.go +++ b/src/modules/common/service/register.go @@ -6,5 +6,5 @@ type IRegister interface { ValidateCaptcha(code, uuid string) error // ByUserName 账号注册 - ByUserName(username, password, userType string) string + ByUserName(username, password, userType string) (string, error) } diff --git a/src/modules/common/service/register.impl.go b/src/modules/common/service/register.impl.go index 5d536fcd..25f77656 100644 --- a/src/modules/common/service/register.impl.go +++ b/src/modules/common/service/register.impl.go @@ -52,11 +52,18 @@ func (s *RegisterImpl) ValidateCaptcha(code, uuid string) error { } // ByUserName 账号注册 -func (s *RegisterImpl) ByUserName(username, password, userType string) string { +func (s *RegisterImpl) ByUserName(username, password, userType string) (string, error) { + // 是否开启用户注册功能 true开启,false关闭 + registerUserStr := s.sysConfigService.SelectConfigValueByKey("sys.account.registerUser") + captchaEnabled := parse.Boolean(registerUserStr) + if !captchaEnabled { + return "", fmt.Errorf("注册用户【%s】失败,很抱歉,系统已关闭外部用户注册通道", username) + } + // 检查用户登录账号是否唯一 uniqueUserName := s.sysUserService.CheckUniqueUserName(username, "") if !uniqueUserName { - return fmt.Sprintf("注册用户【%s】失败,注册账号已存在", username) + return "", fmt.Errorf("注册用户【%s】失败,注册账号已存在", username) } sysUser := systemModel.SysUser{ @@ -78,9 +85,9 @@ func (s *RegisterImpl) ByUserName(username, password, userType string) string { insertId := s.sysUserService.InsertUser(sysUser) if insertId != "" { - return insertId + return insertId, nil } - return "注册失败,请联系系统管理人员" + return "", fmt.Errorf("注册用户【%s】失败,请联系系统管理人员", username) } // registerRoleInit 注册初始角色