feat: 合并代码
This commit is contained in:
@@ -10,6 +10,9 @@ type IAccount interface {
|
||||
// LoginByUsername 登录生成token
|
||||
LoginByUsername(username, password string) (vo.LoginUser, error)
|
||||
|
||||
// UpdateLoginDateAndIP 更新登录时间和IP
|
||||
UpdateLoginDateAndIP(loginUser *vo.LoginUser) bool
|
||||
|
||||
// ClearLoginRecordCache 清除错误记录次数
|
||||
ClearLoginRecordCache(username string) bool
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"ems.agt/src/framework/utils/crypto"
|
||||
"ems.agt/src/framework/utils/parse"
|
||||
"ems.agt/src/framework/vo"
|
||||
"ems.agt/src/modules/system/model"
|
||||
systemService "ems.agt/src/modules/system/service"
|
||||
)
|
||||
|
||||
@@ -105,6 +106,19 @@ func (s *AccountImpl) LoginByUsername(username, password string) (vo.LoginUser,
|
||||
return loginUser, nil
|
||||
}
|
||||
|
||||
// UpdateLoginDateAndIP 更新登录时间和IP
|
||||
func (s *AccountImpl) UpdateLoginDateAndIP(loginUser *vo.LoginUser) bool {
|
||||
sysUser := loginUser.User
|
||||
userInfo := model.SysUser{
|
||||
UserID: sysUser.UserID,
|
||||
LoginIP: sysUser.LoginIP,
|
||||
LoginDate: sysUser.LoginDate,
|
||||
UpdateBy: sysUser.UserName,
|
||||
}
|
||||
rows := s.sysUserService.UpdateUser(userInfo)
|
||||
return rows > 0
|
||||
}
|
||||
|
||||
// ClearLoginRecordCache 清除错误记录次数
|
||||
func (s *AccountImpl) ClearLoginRecordCache(username string) bool {
|
||||
cacheKey := cachekey.PWD_ERR_CNT_KEY + username
|
||||
|
||||
7
src/modules/common/service/commont.go
Normal file
7
src/modules/common/service/commont.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package service
|
||||
|
||||
// 通用请求 服务层接口
|
||||
type ICommont interface {
|
||||
// SystemConfigInfo 系统配置信息
|
||||
SystemConfigInfo() map[string]any
|
||||
}
|
||||
45
src/modules/common/service/commont.impl.go
Normal file
45
src/modules/common/service/commont.impl.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
systemService "ems.agt/src/modules/system/service"
|
||||
)
|
||||
|
||||
// 实例化服务层 CommontImpl 结构体
|
||||
var NewCommontImpl = &CommontImpl{
|
||||
sysUserService: systemService.NewSysUserImpl,
|
||||
sysConfigService: systemService.NewSysConfigImpl,
|
||||
}
|
||||
|
||||
// 通用请求 服务层处理
|
||||
type CommontImpl struct {
|
||||
// 用户信息服务
|
||||
sysUserService systemService.ISysUser
|
||||
// 参数配置服务
|
||||
sysConfigService systemService.ISysConfig
|
||||
}
|
||||
|
||||
// SystemConfigInfo 系统配置信息
|
||||
func (s *CommontImpl) SystemConfigInfo() map[string]any {
|
||||
infoMap := map[string]any{}
|
||||
// 获取LOGO类型
|
||||
logoType := s.sysConfigService.SelectConfigValueByKey("sys.logo.type")
|
||||
infoMap["logoType"] = logoType
|
||||
// 获取LOGO文件
|
||||
filePathIcon := s.sysConfigService.SelectConfigValueByKey("sys.logo.filePathIcon")
|
||||
infoMap["filePathIcon"] = filePathIcon
|
||||
filePathBrand := s.sysConfigService.SelectConfigValueByKey("sys.logo.filePathBrand")
|
||||
infoMap["filePathBrand"] = filePathBrand
|
||||
// 获取系统名称
|
||||
title := s.sysConfigService.SelectConfigValueByKey("sys.title")
|
||||
infoMap["title"] = title
|
||||
// 获取版权声明
|
||||
copyright := s.sysConfigService.SelectConfigValueByKey("sys.copyright")
|
||||
infoMap["copyright"] = copyright
|
||||
// 获取是否开启用户注册功能
|
||||
registerUser := s.sysConfigService.SelectConfigValueByKey("sys.account.registerUser")
|
||||
infoMap["registerUser"] = registerUser
|
||||
// 获取登录界面背景
|
||||
loginBackground := s.sysConfigService.SelectConfigValueByKey("sys.loginBackground")
|
||||
infoMap["loginBackground"] = loginBackground
|
||||
return infoMap
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 注册初始角色
|
||||
|
||||
Reference in New Issue
Block a user