实现用户系统手机号码绑定和登录(商业版)

This commit is contained in:
GoEdgeLab
2023-11-17 11:51:29 +08:00
parent 7e5c77af69
commit 1e2df532d3
9 changed files with 223 additions and 26 deletions

View File

@@ -428,6 +428,20 @@ func (this *UserDAO) CheckUserEmailPassword(tx *dbs.Tx, verifiedEmail string, en
FindInt64Col(0)
}
// CheckUserMobilePassword 检查邮箱+密码
func (this *UserDAO) CheckUserMobilePassword(tx *dbs.Tx, verifiedEmail string, encryptedPassword string) (int64, error) {
if len(verifiedEmail) == 0 || len(encryptedPassword) == 0 {
return 0, nil
}
return this.Query(tx).
Attr("verifiedMobile", 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).
@@ -663,7 +677,7 @@ func (this *UserDAO) RenewUserServersState(tx *dbs.Tx, userId int64) (bool, erro
// FindUserIdWithVerifiedEmail 使用验证后Email查找用户ID
func (this *UserDAO) FindUserIdWithVerifiedEmail(tx *dbs.Tx, verifiedEmail string) (int64, error) {
if len(verifiedEmail) == 0 {
return 0, nil
}
return this.Query(tx).
ResultPk().
@@ -672,6 +686,18 @@ func (this *UserDAO) FindUserIdWithVerifiedEmail(tx *dbs.Tx, verifiedEmail strin
FindInt64Col(0)
}
// FindUserIdWithVerifiedMobile 使用验证后手机号码查找用户ID
func (this *UserDAO) FindUserIdWithVerifiedMobile(tx *dbs.Tx, verifiedMobile string) (int64, error) {
if len(verifiedMobile) == 0 {
return 0, nil
}
return this.Query(tx).
ResultPk().
State(UserStateEnabled).
Attr("verifiedMobile", verifiedMobile).
FindInt64Col(0)
}
// UpdateUserVerifiedEmail 修改已激活邮箱
func (this *UserDAO) UpdateUserVerifiedEmail(tx *dbs.Tx, userId int64, verifiedEmail string) error {
if userId <= 0 {
@@ -684,6 +710,18 @@ func (this *UserDAO) UpdateUserVerifiedEmail(tx *dbs.Tx, userId int64, verifiedE
UpdateQuickly()
}
// UpdateUserVerifiedMobile 修改已激活手机号码
func (this *UserDAO) UpdateUserVerifiedMobile(tx *dbs.Tx, userId int64, verifiedMobile string) error {
if userId <= 0 {
return nil
}
return this.Query(tx).
Pk(userId).
Set("verifiedMobile", verifiedMobile).
Set("mobileIsVerified", true).
UpdateQuickly()
}
// FindUserBandwidthAlgoForView 获取用户浏览用的带宽算法
func (this *UserDAO) FindUserBandwidthAlgoForView(tx *dbs.Tx, userId int64, uiConfig *systemconfigs.UserUIConfig) (bandwidthAlgo string, err error) {
bandwidthAlgo, err = this.Query(tx).

View 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 UserMobileVerificationDAO dbs.DAO
func NewUserMobileVerificationDAO() *UserMobileVerificationDAO {
return dbs.NewDAO(&UserMobileVerificationDAO{
DAOObject: dbs.DAOObject{
DB: Tea.Env,
Table: "edgeUserMobileVerifications",
Model: new(UserMobileVerification),
PkName: "id",
},
}).(*UserMobileVerificationDAO)
}
var SharedUserMobileVerificationDAO *UserMobileVerificationDAO
func init() {
dbs.OnReady(func() {
SharedUserMobileVerificationDAO = NewUserMobileVerificationDAO()
})
}

View File

@@ -0,0 +1,6 @@
package models_test
import (
_ "github.com/go-sql-driver/mysql"
_ "github.com/iwind/TeaGo/bootstrap"
)

View File

@@ -0,0 +1,41 @@
package models
import "github.com/iwind/TeaGo/dbs"
const (
UserMobileVerificationField_Id dbs.FieldName = "id" // ID
UserMobileVerificationField_Mobile dbs.FieldName = "mobile" // 手机号码
UserMobileVerificationField_UserId dbs.FieldName = "userId" // 用户ID
UserMobileVerificationField_Code dbs.FieldName = "code" // 激活码
UserMobileVerificationField_CreatedAt dbs.FieldName = "createdAt" // 创建时间
UserMobileVerificationField_IsSent dbs.FieldName = "isSent" // 是否已发送
UserMobileVerificationField_IsVerified dbs.FieldName = "isVerified" // 是否已激活
UserMobileVerificationField_Day dbs.FieldName = "day" // YYYYMMDD
)
// UserMobileVerification 邮箱激活邮件队列
type UserMobileVerification struct {
Id uint64 `field:"id"` // ID
Mobile string `field:"mobile"` // 手机号码
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 UserMobileVerificationOperator struct {
Id any // ID
Mobile any // 手机号码
UserId any // 用户ID
Code any // 激活码
CreatedAt any // 创建时间
IsSent any // 是否已发送
IsVerified any // 是否已激活
Day any // YYYYMMDD
}
func NewUserMobileVerificationOperator() *UserMobileVerificationOperator {
return &UserMobileVerificationOperator{}
}

View File

@@ -0,0 +1 @@
package models

View File

@@ -10,6 +10,7 @@ const (
UserField_Fullname dbs.FieldName = "fullname" // 真实姓名
UserField_Mobile dbs.FieldName = "mobile" // 手机号
UserField_VerifiedMobile dbs.FieldName = "verifiedMobile" // 已验证手机号
UserField_MobileIsVerified dbs.FieldName = "mobileIsVerified" // 手机号是否已验证
UserField_Tel dbs.FieldName = "tel" // 联系电话
UserField_Remark dbs.FieldName = "remark" // 备注
UserField_Email dbs.FieldName = "email" // 邮箱地址
@@ -47,6 +48,7 @@ type User struct {
Fullname string `field:"fullname"` // 真实姓名
Mobile string `field:"mobile"` // 手机号
VerifiedMobile string `field:"verifiedMobile"` // 已验证手机号
MobileIsVerified uint8 `field:"mobileIsVerified"` // 手机号是否已验证
Tel string `field:"tel"` // 联系电话
Remark string `field:"remark"` // 备注
Email string `field:"email"` // 邮箱地址
@@ -83,6 +85,7 @@ type UserOperator struct {
Fullname any // 真实姓名
Mobile any // 手机号
VerifiedMobile any // 已验证手机号
MobileIsVerified any // 手机号是否已验证
Tel any // 联系电话
Remark any // 备注
Email any // 邮箱地址