1
0

feat: 合并代码

This commit is contained in:
TsMask
2023-10-26 09:33:51 +08:00
parent d63db9dd6c
commit 08a908c3f4
38 changed files with 780 additions and 203 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,7 @@
package service
// 通用请求 服务层接口
type ICommont interface {
// SystemConfigInfo 系统配置信息
SystemConfigInfo() map[string]any
}

View 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
}

View File

@@ -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)
}

View File

@@ -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 注册初始角色