diff --git a/src/app.go b/src/app.go index 9fa2fe10..5c53da1f 100644 --- a/src/app.go +++ b/src/app.go @@ -8,6 +8,7 @@ import ( "be.ems/src/framework/middleware" "be.ems/src/framework/middleware/security" "be.ems/src/framework/utils/machine" + "be.ems/src/modules/auth" "be.ems/src/modules/chart" "be.ems/src/modules/common" "be.ems/src/modules/crontask" @@ -96,10 +97,12 @@ func initDefeat(app *gin.Engine) { // 初始模块路由 func initModulesRoute(app *gin.Engine) { - // 通用模块 - common.Setup(app) // 系统模块 system.Setup(app) + // 认证模块 + auth.Setup(app) + // 通用模块 + common.Setup(app) // 网元功能模块 networkelement.Setup(app) // 网元数据模块 diff --git a/src/modules/auth/auth.go b/src/modules/auth/auth.go new file mode 100644 index 00000000..704d2c2e --- /dev/null +++ b/src/modules/auth/auth.go @@ -0,0 +1,73 @@ +package auth + +import ( + "be.ems/src/framework/logger" + "be.ems/src/framework/middleware" + "be.ems/src/modules/auth/controller" + + "github.com/gin-gonic/gin" +) + +// 模块路由注册 +func Setup(router *gin.Engine) { + logger.Infof("开始加载 ====> auth 模块路由") + + // 系统可暴露的配置信息 + router.GET("/sys-conf", controller.NewSysConf.Handler) + + // 系统引导初始化 + guideGroup := router.Group("/bootloader") + { + guideGroup.POST("", controller.NewBootloader.Start) + guideGroup.PUT("", middleware.PreAuthorize(nil), controller.NewBootloader.Done) + guideGroup.DELETE("", middleware.PreAuthorize(nil), controller.NewBootloader.Reset) + guideGroup.PUT("/account", middleware.PreAuthorize(nil), controller.NewBootloader.Account) + } + + // 验证码操作 + router.GET("/captcha-image", + middleware.RateLimit(middleware.LimitOption{ + Time: 300, + Count: 60, + Type: middleware.LIMIT_IP, + }), + controller.NewCaptcha.Image, + ) + + // 账号身份操作处理 + { + router.POST("/login", + middleware.RateLimit(middleware.LimitOption{ + Time: 180, + Count: 15, + Type: middleware.LIMIT_IP, + }), + middleware.CryptoApi(true, true), + controller.NewAccount.Login, + ) + router.GET("/me", middleware.PreAuthorize(nil), controller.NewAccount.Me) + router.GET("/router", middleware.PreAuthorize(nil), controller.NewAccount.Router) + router.POST("/logout", + middleware.RateLimit(middleware.LimitOption{ + Time: 120, + Count: 15, + Type: middleware.LIMIT_IP, + }), + controller.NewAccount.Logout, + ) + } + + // 账号注册操作 + { + router.POST("/register", + middleware.RateLimit(middleware.LimitOption{ + Time: 300, + Count: 10, + Type: middleware.LIMIT_IP, + }), + middleware.CryptoApi(true, true), + controller.NewRegister.Register, + ) + } + +} diff --git a/src/modules/common/controller/account.go b/src/modules/auth/controller/account.go similarity index 98% rename from src/modules/common/controller/account.go rename to src/modules/auth/controller/account.go index 2e018dd6..a89bf6af 100644 --- a/src/modules/common/controller/account.go +++ b/src/modules/auth/controller/account.go @@ -10,8 +10,8 @@ import ( "be.ems/src/framework/reqctx" "be.ems/src/framework/resp" "be.ems/src/framework/token" - "be.ems/src/modules/common/model" - "be.ems/src/modules/common/service" + "be.ems/src/modules/auth/model" + "be.ems/src/modules/auth/service" systemModelVO "be.ems/src/modules/system/model/vo" systemService "be.ems/src/modules/system/service" diff --git a/src/modules/common/controller/bootloader.go b/src/modules/auth/controller/bootloader.go similarity index 99% rename from src/modules/common/controller/bootloader.go rename to src/modules/auth/controller/bootloader.go index 9ce9f64a..f68f19ed 100644 --- a/src/modules/common/controller/bootloader.go +++ b/src/modules/auth/controller/bootloader.go @@ -10,7 +10,7 @@ import ( "be.ems/src/framework/token" "be.ems/src/framework/utils/machine" "be.ems/src/framework/utils/regular" - "be.ems/src/modules/common/service" + "be.ems/src/modules/auth/service" systemService "be.ems/src/modules/system/service" "github.com/gin-gonic/gin" diff --git a/src/modules/common/controller/captcha.go b/src/modules/auth/controller/captcha.go similarity index 100% rename from src/modules/common/controller/captcha.go rename to src/modules/auth/controller/captcha.go diff --git a/src/modules/common/controller/register.go b/src/modules/auth/controller/register.go similarity index 97% rename from src/modules/common/controller/register.go rename to src/modules/auth/controller/register.go index 1280e457..bde7b9d4 100644 --- a/src/modules/common/controller/register.go +++ b/src/modules/auth/controller/register.go @@ -8,8 +8,8 @@ import ( "be.ems/src/framework/reqctx" "be.ems/src/framework/resp" "be.ems/src/framework/utils/regular" - "be.ems/src/modules/common/model" - "be.ems/src/modules/common/service" + "be.ems/src/modules/auth/model" + "be.ems/src/modules/auth/service" systemService "be.ems/src/modules/system/service" "github.com/gin-gonic/gin" diff --git a/src/modules/common/service/commont.go b/src/modules/auth/controller/sys_conf.go similarity index 73% rename from src/modules/common/service/commont.go rename to src/modules/auth/controller/sys_conf.go index 9f1a9b49..579474c7 100644 --- a/src/modules/common/service/commont.go +++ b/src/modules/auth/controller/sys_conf.go @@ -1,32 +1,49 @@ -package service +package controller import ( "fmt" "be.ems/src/framework/config" "be.ems/src/framework/constants" + "be.ems/src/framework/i18n" + "be.ems/src/framework/reqctx" + "be.ems/src/framework/resp" "be.ems/src/framework/utils/machine" systemService "be.ems/src/modules/system/service" + "github.com/gin-gonic/gin" ) -// 实例化服务层 Commont 结构体 -var NewCommont = &Commont{ +// 实例化控制层 SysConfController 结构体 +var NewSysConf = &SysConfController{ sysUserService: systemService.NewSysUser, sysConfigService: systemService.NewSysConfig, } -// 通用请求 服务层处理 -type Commont struct { +// 系统的配置信息 +// +// PATH /sys-conf +type SysConfController struct { sysUserService *systemService.SysUser // 用户信息服务 sysConfigService *systemService.SysConfig // 参数配置服务 } -// SystemConfigInfo 系统配置信息 -func (s *Commont) SystemConfigInfo() map[string]string { +// 系统的配置信息 +// +// GET / +// +// @Tags common +// @Accept json +// @Produce json +// @Success 200 {object} object "Response Results" +// @Summary Configuration information for the system +// @Description Configuration information for the system +// @Router /sys-conf [get] +func (s SysConfController) Handler(c *gin.Context) { + language := reqctx.AcceptLanguage(c) + infoMap := map[string]string{} // 获取打包注入的全局变量信息 infoMap["version"] = config.Version - infoMap["buildTime"] = config.BuildTime // 系统首次使用标记 launchInfo := machine.LaunchInfo if launchInfo != nil { @@ -38,6 +55,8 @@ func (s *Commont) SystemConfigInfo() map[string]string { } else { infoMap[constants.LAUNCH_BOOTLOADER] = "true" } + // 服务版本 + infoMap["serverVersion"] = fmt.Sprint(config.Get("serverVersion")) // 用户登录认证 infoMap["loginAuth"] = fmt.Sprint(config.Get("serverLoginAuth")) // 用户接口加密 @@ -54,10 +73,10 @@ func (s *Commont) SystemConfigInfo() map[string]string { infoMap["filePathBrand"] = filePathBrand // 获取系统名称 title := s.sysConfigService.FindValueByKey("sys.title") - infoMap["title"] = title + infoMap["title"] = i18n.TKey(language, title) // 获取版权声明 copyright := s.sysConfigService.FindValueByKey("sys.copyright") - infoMap["copyright"] = copyright + infoMap["copyright"] = i18n.TKey(language, copyright) // 获取是否开启用户注册功能 registerUser := s.sysConfigService.FindValueByKey("sys.account.registerUser") infoMap["registerUser"] = registerUser @@ -76,5 +95,6 @@ func (s *Commont) SystemConfigInfo() map[string]string { // 国际化默认语言 i18nDefault := s.sysConfigService.FindValueByKey("sys.i18n.default") infoMap["i18nDefault"] = i18nDefault - return infoMap + + c.JSON(200, resp.OkData(infoMap)) } diff --git a/src/modules/common/model/login_body.go b/src/modules/auth/model/login_body.go similarity index 100% rename from src/modules/common/model/login_body.go rename to src/modules/auth/model/login_body.go diff --git a/src/modules/common/model/register_body.go b/src/modules/auth/model/register_body.go similarity index 100% rename from src/modules/common/model/register_body.go rename to src/modules/auth/model/register_body.go diff --git a/src/modules/common/service/account.go b/src/modules/auth/service/account.go similarity index 100% rename from src/modules/common/service/account.go rename to src/modules/auth/service/account.go diff --git a/src/modules/common/service/register.go b/src/modules/auth/service/register.go similarity index 100% rename from src/modules/common/service/register.go rename to src/modules/auth/service/register.go diff --git a/src/modules/common/common.go b/src/modules/common/common.go index 4b43a267..9c497c4e 100644 --- a/src/modules/common/common.go +++ b/src/modules/common/common.go @@ -22,63 +22,6 @@ func Setup(router *gin.Engine) { controller.NewIndex.Handler, ) - // 系统可暴露的配置信息 - router.GET("/sys-conf", controller.NewCommon.SysConfig) - // 系统引导初始化 - guideGroup := router.Group("/bootloader") - { - guideGroup.POST("", controller.NewBootloader.Start) - guideGroup.PUT("", middleware.PreAuthorize(nil), controller.NewBootloader.Done) - guideGroup.DELETE("", middleware.PreAuthorize(nil), controller.NewBootloader.Reset) - guideGroup.PUT("/account", middleware.PreAuthorize(nil), controller.NewBootloader.Account) - } - - // 验证码操作 - router.GET("/captcha-image", - middleware.RateLimit(middleware.LimitOption{ - Time: 300, - Count: 60, - Type: middleware.LIMIT_IP, - }), - controller.NewCaptcha.Image, - ) - - // 账号身份操作处理 - { - router.POST("/login", - middleware.RateLimit(middleware.LimitOption{ - Time: 180, - Count: 15, - Type: middleware.LIMIT_IP, - }), - middleware.CryptoApi(true, true), - controller.NewAccount.Login, - ) - router.GET("/me", middleware.PreAuthorize(nil), controller.NewAccount.Me) - router.GET("/router", middleware.PreAuthorize(nil), controller.NewAccount.Router) - router.POST("/logout", - middleware.RateLimit(middleware.LimitOption{ - Time: 120, - Count: 15, - Type: middleware.LIMIT_IP, - }), - controller.NewAccount.Logout, - ) - } - - // 账号注册操作 - { - router.POST("/register", - middleware.RateLimit(middleware.LimitOption{ - Time: 300, - Count: 10, - Type: middleware.LIMIT_IP, - }), - middleware.CryptoApi(true, true), - controller.NewRegister.Register, - ) - } - // 通用请求 commonGroup := router.Group("/common") { diff --git a/src/modules/common/controller/common.go b/src/modules/common/controller/common.go index 5d7d4745..77fe67db 100644 --- a/src/modules/common/controller/common.go +++ b/src/modules/common/controller/common.go @@ -11,22 +11,16 @@ import ( "be.ems/src/framework/i18n" "be.ems/src/framework/reqctx" - "be.ems/src/framework/resp" - commonService "be.ems/src/modules/common/service" "github.com/gin-gonic/gin" ) // 实例化控制层 CommonController 结构体 -var NewCommon = &CommonController{ - commontService: commonService.NewCommont, -} +var NewCommon = &CommonController{} // 通用请求 // // PATH / -type CommonController struct { - commontService *commonService.Commont // 通用请求服务 -} +type CommonController struct{} // Hash 哈希编码 // @@ -100,29 +94,3 @@ func (s *CommonController) I18n(c *gin.Context) { "errorFields": errorFields, }) } - -// 系统的配置信息 -// -// GET /sys-conf -// -// @Tags common -// @Accept json -// @Produce json -// @Success 200 {object} object "Response Results" -// @Summary Configuration information for the system -// @Description Configuration information for the system -// @Router /sys-conf [get] -func (s CommonController) SysConfig(c *gin.Context) { - data := s.commontService.SystemConfigInfo() - - // 闭包函数处理多语言 - language := reqctx.AcceptLanguage(c) - converI18n := func(language string, arr *map[string]string) { - for k, v := range *arr { - (*arr)[k] = i18n.TKey(language, v) - } - } - converI18n(language, &data) - - c.JSON(200, resp.OkData(data)) -} diff --git a/src/modules/system/controller/sys_log_login.go b/src/modules/system/controller/sys_log_login.go index 229d85ea..41a8197d 100644 --- a/src/modules/system/controller/sys_log_login.go +++ b/src/modules/system/controller/sys_log_login.go @@ -10,7 +10,7 @@ import ( "be.ems/src/framework/resp" "be.ems/src/framework/utils/date" "be.ems/src/framework/utils/file" - commonService "be.ems/src/modules/common/service" + authService "be.ems/src/modules/auth/service" "be.ems/src/modules/system/model" "be.ems/src/modules/system/service" @@ -20,15 +20,15 @@ import ( // 实例化控制层 SysLogLoginController 结构体 var NewSysLogLogin = &SysLogLoginController{ sysLogLoginService: service.NewSysLogLogin, - accountService: commonService.NewAccount, + accountService: authService.NewAccount, } // 系统登录日志信息 // // PATH /system/log/login type SysLogLoginController struct { - sysLogLoginService *service.SysLogLogin // 系统登录日志服务 - accountService *commonService.Account // 账号身份操作服务 + sysLogLoginService *service.SysLogLogin // 系统登录日志服务 + accountService *authService.Account // 账号身份操作服务 } // 系统登录日志列表