mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 07:50:25 +08:00
* fix: 保存 LastResult 时截断字符串过长部分,以避免数据库报错 * refactor: 新增 entity.DbTaskBase 和 persistence.dbTaskBase, 用于实现数据库备份和恢复任务处理相关部分 * fix: aeskey变更后,解密密码出现数组越界访问错误 * fix: 时间属性为零值时,保存到 mysql 数据库报错 * refactor db.infrastructure.service.scheduler * feat: 实现立即备份功能 * refactor db.infrastructure.service.db_instance * refactor: 从数据库中获取数据库备份目录、mysql文件路径等配置信息 * fix: 数据库备份和恢复问题 * fix: 修改 .gitignore 文件,忽略数据库备份目录和数据库程序目录
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package entity
|
|
|
|
import (
|
|
"errors"
|
|
"mayfly-go/internal/common/utils"
|
|
"mayfly-go/pkg/model"
|
|
"time"
|
|
)
|
|
|
|
type Account struct {
|
|
model.Model
|
|
|
|
Name string `json:"name"`
|
|
Username string `json:"username"`
|
|
Password string `json:"-"`
|
|
Status int8 `json:"status"`
|
|
LastLoginTime *time.Time `json:"lastLoginTime"`
|
|
LastLoginIp string `json:"lastLoginIp"`
|
|
OtpSecret string `json:"-"`
|
|
}
|
|
|
|
func (a *Account) TableName() string {
|
|
return "t_sys_account"
|
|
}
|
|
|
|
// 是否可用
|
|
func (a *Account) IsEnable() bool {
|
|
return a.Status == AccountEnableStatus
|
|
}
|
|
|
|
func (a *Account) OtpSecretEncrypt() error {
|
|
secret, err := utils.PwdAesEncrypt(a.OtpSecret)
|
|
if err != nil {
|
|
return errors.New("加密账户密码失败")
|
|
}
|
|
a.OtpSecret = secret
|
|
return nil
|
|
}
|
|
|
|
func (a *Account) OtpSecretDecrypt() error {
|
|
if a.OtpSecret == "-" {
|
|
return nil
|
|
}
|
|
secret, err := utils.PwdAesDecrypt(a.OtpSecret)
|
|
if err != nil {
|
|
return errors.New("解密账户密码失败")
|
|
}
|
|
a.OtpSecret = secret
|
|
return nil
|
|
}
|
|
|
|
const (
|
|
AccountEnableStatus int8 = 1 // 启用状态
|
|
AccountDisableStatus int8 = -1 // 禁用状态
|
|
)
|