perf: 通用模块分出认证模块
This commit is contained in:
@@ -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)
|
||||
// 网元数据模块
|
||||
|
||||
73
src/modules/auth/auth.go
Normal file
73
src/modules/auth/auth.go
Normal file
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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))
|
||||
}
|
||||
@@ -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")
|
||||
{
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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 // 账号身份操作服务
|
||||
}
|
||||
|
||||
// 系统登录日志列表
|
||||
|
||||
Reference in New Issue
Block a user