实现用户注册/审核功能

This commit is contained in:
GoEdgeLab
2022-01-05 10:45:19 +08:00
parent 07857ab231
commit d7fd2e39e5
3 changed files with 189 additions and 58 deletions

View File

@@ -104,7 +104,18 @@ func (this *UserDAO) FindUserFullname(tx *dbs.Tx, userId int64) (string, error)
}
// CreateUser 创建用户
func (this *UserDAO) CreateUser(tx *dbs.Tx, username string, password string, fullname string, mobile string, tel string, email string, remark string, source string, clusterId int64) (int64, error) {
func (this *UserDAO) CreateUser(tx *dbs.Tx, username string,
password string,
fullname string,
mobile string,
tel string,
email string,
remark string,
source string,
clusterId int64,
features []string,
registeredIP string,
isVerified bool) (int64, error) {
op := NewUserOperator()
op.Username = username
op.Password = stringutil.Md5(password)
@@ -112,10 +123,24 @@ func (this *UserDAO) CreateUser(tx *dbs.Tx, username string, password string, fu
op.Mobile = mobile
op.Tel = tel
op.Email = email
op.EmailIsVerified = false
op.Remark = remark
op.Source = source
op.ClusterId = clusterId
op.Day = timeutil.Format("Ymd")
op.IsVerified = isVerified
op.RegisteredIP = registeredIP
// features
if len(features) == 0 {
op.Features = "[]"
} else {
featuresJSON, err := json.Marshal(features)
if err != nil {
return 0, err
}
op.Features = featuresJSON
}
op.IsOn = true
op.State = UserStateEnabled
@@ -149,13 +174,15 @@ func (this *UserDAO) UpdateUser(tx *dbs.Tx, userId int64, username string, passw
}
// UpdateUserInfo 修改用户基本信息
func (this *UserDAO) UpdateUserInfo(tx *dbs.Tx, userId int64, fullname string) error {
func (this *UserDAO) UpdateUserInfo(tx *dbs.Tx, userId int64, fullname string, mobile string, email string) error {
if userId <= 0 {
return errors.New("invalid userId")
}
op := NewUserOperator()
op.Id = userId
op.Fullname = fullname
op.Mobile = mobile
op.Email = email
return this.Save(tx, op)
}
@@ -355,3 +382,16 @@ func (this *UserDAO) CountDailyUsers(tx *dbs.Tx, dayFrom string, dayTo string) (
return result, nil
}
// UpdateUserIsVerified 审核用户
func (this *UserDAO) UpdateUserIsVerified(tx *dbs.Tx, userId int64, isRejected bool, rejectReason string) error {
if userId <= 0 {
return errors.New("invalid userId")
}
var op = NewUserOperator()
op.Id = userId
op.IsRejected = isRejected
op.RejectReason = rejectReason
op.IsVerified = true
return this.Save(tx, op)
}

View File

@@ -2,43 +2,55 @@ package models
// User 用户
type User struct {
Id uint32 `field:"id"` // ID
IsOn uint8 `field:"isOn"` // 是否启用
Username string `field:"username"` // 用户名
Password string `field:"password"` // 密码
Fullname string `field:"fullname"` // 真实姓名
Mobile string `field:"mobile"` // 手机号
Tel string `field:"tel"` // 联系电话
Remark string `field:"remark"` // 备注
Email string `field:"email"` // 邮箱地址
AvatarFileId uint64 `field:"avatarFileId"` // 头像文件ID
CreatedAt uint64 `field:"createdAt"` // 创建时间
Day string `field:"day"` // YYYYMMDD
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
State uint8 `field:"state"` // 状态
Source string `field:"source"` // 来源
ClusterId uint32 `field:"clusterId"` // 集群ID
Features string `field:"features"` // 允许操作的特征
Id uint32 `field:"id"` // ID
IsOn uint8 `field:"isOn"` // 是否启用
Username string `field:"username"` // 用户名
Password string `field:"password"` // 密码
Fullname string `field:"fullname"` // 真实姓名
Mobile string `field:"mobile"` // 手机号
Tel string `field:"tel"` // 联系电话
Remark string `field:"remark"` // 备注
Email string `field:"email"` // 邮箱地址
EmailIsVerified uint8 `field:"emailIsVerified"` // 邮箱是否已验证
AvatarFileId uint64 `field:"avatarFileId"` // 头像文件ID
CreatedAt uint64 `field:"createdAt"` // 创建时间
Day string `field:"day"` // YYYYMMDD
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
State uint8 `field:"state"` // 状态
Source string `field:"source"` // 来源
ClusterId uint32 `field:"clusterId"` // 集群ID
Features string `field:"features"` // 允许操作的特征
RegisteredIP string `field:"registeredIP"` // 注册使用的IP
IsRejected uint8 `field:"isRejected"` // 是否已拒绝
RejectReason string `field:"rejectReason"` // 拒绝理由
IsVerified uint8 `field:"isVerified"` // 是否验证通过
RequirePlans uint8 `field:"requirePlans"` // 是否需要购买套餐
}
type UserOperator struct {
Id interface{} // ID
IsOn interface{} // 是否启用
Username interface{} // 用户名
Password interface{} // 密码
Fullname interface{} // 真实姓名
Mobile interface{} // 手机号
Tel interface{} // 联系电话
Remark interface{} // 备注
Email interface{} // 邮箱地址
AvatarFileId interface{} // 头像文件ID
CreatedAt interface{} // 创建时间
Day interface{} // YYYYMMDD
UpdatedAt interface{} // 修改时间
State interface{} // 状态
Source interface{} // 来源
ClusterId interface{} // 集群ID
Features interface{} // 允许操作的特征
Id interface{} // ID
IsOn interface{} // 是否启用
Username interface{} // 用户名
Password interface{} // 密码
Fullname interface{} // 真实姓名
Mobile interface{} // 手机号
Tel interface{} // 联系电话
Remark interface{} // 备注
Email interface{} // 邮箱地址
EmailIsVerified interface{} // 邮箱是否已验证
AvatarFileId interface{} // 头像文件ID
CreatedAt interface{} // 创建时间
Day interface{} // YYYYMMDD
UpdatedAt interface{} // 修改时间
State interface{} // 状态
Source interface{} // 来源
ClusterId interface{} // 集群ID
Features interface{} // 允许操作的特征
RegisteredIP interface{} // 注册使用的IP
IsRejected interface{} // 是否已拒绝
RejectReason interface{} // 拒绝理由
IsVerified interface{} // 是否验证通过
RequirePlans interface{} // 是否需要购买套餐
}
func NewUserOperator() *UserOperator {