mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-28 16:36:37 +08:00
初步完成用户电子邮箱绑定(激活)
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -172,6 +173,21 @@ func (this *SysSettingDAO) ReadAdminUIConfig(tx *dbs.Tx, cacheMap *utils.CacheMa
|
||||
return &systemconfigs.AdminUIConfig{}, nil
|
||||
}
|
||||
|
||||
// ReadProductName 读取设置的产品名称
|
||||
func (this *SysSettingDAO) ReadProductName(tx *dbs.Tx) (string, error) {
|
||||
productName, err := this.Query(tx).
|
||||
Attr("code", systemconfigs.SettingCodeAdminUIConfig).
|
||||
Result("JSON_EXTRACT(value, '$.productName')").
|
||||
FindStringCol("")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(productName) > 0 {
|
||||
return strconv.Unquote(productName)
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// ReadUserUIConfig 读取用户UI配置
|
||||
func (this *SysSettingDAO) ReadUserUIConfig(tx *dbs.Tx) (*systemconfigs.UserUIConfig, error) {
|
||||
valueJSON, err := this.ReadSetting(tx, systemconfigs.SettingCodeUserUIConfig)
|
||||
@@ -228,3 +244,21 @@ func (this *SysSettingDAO) ReadUserServerConfig(tx *dbs.Tx) (*userconfigs.UserSe
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// ReadUserRegisterConfig 读取用户注册配置
|
||||
func (this *SysSettingDAO) ReadUserRegisterConfig(tx *dbs.Tx) (*userconfigs.UserRegisterConfig, error) {
|
||||
valueJSON, err := this.ReadSetting(tx, systemconfigs.SettingCodeUserRegisterConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(valueJSON) == 0 {
|
||||
return userconfigs.DefaultUserRegisterConfig(), nil
|
||||
}
|
||||
|
||||
var config = userconfigs.DefaultUserRegisterConfig()
|
||||
err = json.Unmarshal(valueJSON, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
||||
@@ -42,3 +42,8 @@ func TestSysSettingDAO_CompareInt64Setting(t *testing.T) {
|
||||
}
|
||||
t.Log("result:", i)
|
||||
}
|
||||
|
||||
func TestSysSettingDAO_ReadProductName(t *testing.T) {
|
||||
var tx *dbs.Tx
|
||||
t.Log(NewSysSettingDAO().ReadProductName(tx))
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ func (this *UserDAO) ListEnabledUserIds(tx *dbs.Tx, offset, size int64) ([]int64
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CheckUserPassword 检查用户名、密码
|
||||
// CheckUserPassword 检查用户名+密码
|
||||
func (this *UserDAO) CheckUserPassword(tx *dbs.Tx, username string, encryptedPassword string) (int64, error) {
|
||||
if len(username) == 0 || len(encryptedPassword) == 0 {
|
||||
return 0, nil
|
||||
@@ -354,6 +354,20 @@ func (this *UserDAO) CheckUserPassword(tx *dbs.Tx, username string, encryptedPas
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// CheckUserEmailPassword 检查邮箱+密码
|
||||
func (this *UserDAO) CheckUserEmailPassword(tx *dbs.Tx, verifiedEmail string, encryptedPassword string) (int64, error) {
|
||||
if len(verifiedEmail) == 0 || len(encryptedPassword) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return this.Query(tx).
|
||||
Attr("verifiedEmail", verifiedEmail).
|
||||
Attr("password", encryptedPassword).
|
||||
Attr("state", UserStateEnabled).
|
||||
Attr("isOn", true).
|
||||
ResultPk().
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// FindUserClusterId 查找用户所在集群
|
||||
func (this *UserDAO) FindUserClusterId(tx *dbs.Tx, userId int64) (int64, error) {
|
||||
return this.Query(tx).
|
||||
@@ -586,6 +600,30 @@ func (this *UserDAO) RenewUserServersState(tx *dbs.Tx, userId int64) (bool, erro
|
||||
return newServersEnabled, nil
|
||||
}
|
||||
|
||||
// FindUserIdWithVerifiedEmail 使用验证后Email查找用户ID
|
||||
func (this *UserDAO) FindUserIdWithVerifiedEmail(tx *dbs.Tx, verifiedEmail string) (int64, error) {
|
||||
if len(verifiedEmail) == 0 {
|
||||
|
||||
}
|
||||
return this.Query(tx).
|
||||
ResultPk().
|
||||
State(UserStateEnabled).
|
||||
Attr("verifiedEmail", verifiedEmail).
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// UpdateUserVerifiedEmail 修改已激活邮箱
|
||||
func (this *UserDAO) UpdateUserVerifiedEmail(tx *dbs.Tx, userId int64, verifiedEmail string) error {
|
||||
if userId <= 0 {
|
||||
return nil
|
||||
}
|
||||
return this.Query(tx).
|
||||
Pk(userId).
|
||||
Set("verifiedEmail", verifiedEmail).
|
||||
Set("emailIsVerified", true).
|
||||
UpdateQuickly()
|
||||
}
|
||||
|
||||
// NotifyUpdate 用户变更通知
|
||||
func (this *UserDAO) NotifyUpdate(tx *dbs.Tx, userId int64) error {
|
||||
if userId <= 0 {
|
||||
|
||||
28
internal/db/models/user_email_verification_dao.go
Normal file
28
internal/db/models/user_email_verification_dao.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
type UserEmailVerificationDAO dbs.DAO
|
||||
|
||||
func NewUserEmailVerificationDAO() *UserEmailVerificationDAO {
|
||||
return dbs.NewDAO(&UserEmailVerificationDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeUserEmailVerifications",
|
||||
Model: new(UserEmailVerification),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*UserEmailVerificationDAO)
|
||||
}
|
||||
|
||||
var SharedUserEmailVerificationDAO *UserEmailVerificationDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedUserEmailVerificationDAO = NewUserEmailVerificationDAO()
|
||||
})
|
||||
}
|
||||
6
internal/db/models/user_email_verification_dao_test.go
Normal file
6
internal/db/models/user_email_verification_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package models_test
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/iwind/TeaGo/bootstrap"
|
||||
)
|
||||
28
internal/db/models/user_email_verification_model.go
Normal file
28
internal/db/models/user_email_verification_model.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package models
|
||||
|
||||
// UserEmailVerification 邮箱激活邮件队列
|
||||
type UserEmailVerification struct {
|
||||
Id uint64 `field:"id"` // ID
|
||||
Email string `field:"email"` // 邮箱
|
||||
UserId uint64 `field:"userId"` // 用户ID
|
||||
Code string `field:"code"` // 激活码
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
IsSent bool `field:"isSent"` // 是否已发送
|
||||
IsVerified bool `field:"isVerified"` // 是否已激活
|
||||
Day string `field:"day"` // YYYYMMDD
|
||||
}
|
||||
|
||||
type UserEmailVerificationOperator struct {
|
||||
Id any // ID
|
||||
Email any // 邮箱
|
||||
UserId any // 用户ID
|
||||
Code any // 激活码
|
||||
CreatedAt any // 创建时间
|
||||
IsSent any // 是否已发送
|
||||
IsVerified any // 是否已激活
|
||||
Day any // YYYYMMDD
|
||||
}
|
||||
|
||||
func NewUserEmailVerificationOperator() *UserEmailVerificationOperator {
|
||||
return &UserEmailVerificationOperator{}
|
||||
}
|
||||
1
internal/db/models/user_email_verification_model_ext.go
Normal file
1
internal/db/models/user_email_verification_model_ext.go
Normal file
@@ -0,0 +1 @@
|
||||
package models
|
||||
@@ -13,6 +13,7 @@ type User struct {
|
||||
Tel string `field:"tel"` // 联系电话
|
||||
Remark string `field:"remark"` // 备注
|
||||
Email string `field:"email"` // 邮箱地址
|
||||
VerifiedEmail string `field:"verifiedEmail"` // 激活后的邮箱
|
||||
EmailIsVerified uint8 `field:"emailIsVerified"` // 邮箱是否已验证
|
||||
AvatarFileId uint64 `field:"avatarFileId"` // 头像文件ID
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
@@ -43,6 +44,7 @@ type UserOperator struct {
|
||||
Tel any // 联系电话
|
||||
Remark any // 备注
|
||||
Email any // 邮箱地址
|
||||
VerifiedEmail any // 激活后的邮箱
|
||||
EmailIsVerified any // 邮箱是否已验证
|
||||
AvatarFileId any // 头像文件ID
|
||||
CreatedAt any // 创建时间
|
||||
|
||||
Reference in New Issue
Block a user