feat:完善信息
This commit is contained in:
@ -54,8 +54,6 @@ func (c *Account) Login(account, password, captchaKey, captchaValue, equipment,
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("当前不属于任何租户,不可登录")
|
||||
} else if mSysUserTenant.Status != model2.AccountStatusForEnable {
|
||||
return nil, errors.New("当前账号已禁用,不可登录,请联系管理员!")
|
||||
}
|
||||
if mSysUserTenant.TenantID <= 0 {
|
||||
goto Complete
|
||||
|
@ -432,9 +432,7 @@ func (c *Instance) MemberBind(id uint64, status int) error {
|
||||
} else if !isExist {
|
||||
return errors.New("用户信息不存在")
|
||||
}
|
||||
if model2.AccountStatusKind(status) == mSysUserTenant.Status {
|
||||
return errors.New("状态异常,不可操作")
|
||||
}
|
||||
|
||||
if err := model2.Updates(mSysUserTenant.SysUserTenant, map[string]interface{}{
|
||||
"status": status, "updated_at": time.Now(),
|
||||
}); err != nil {
|
||||
|
@ -7,7 +7,6 @@ type SysUserTenant struct {
|
||||
Department string `gorm:"column:department;type:varchar(100);default:null;comment:部门信息" json:"department"`
|
||||
Role string `gorm:"column:role;type:varchar(100);default:null;comment:角色信息" json:"role"`
|
||||
Identity SysUserTenantIdentity `gorm:"column:identity;type:tinyint(1);default:0;comment:用户身份(1:管理员,2:用户)" json:"-"`
|
||||
AccountStatus
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
type UserInstance struct {
|
||||
Model
|
||||
UUID uint64 `gorm:"column:uuid;uniqueIndex:idx_tenant_user_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
|
||||
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
|
||||
Mobile string `gorm:"column:mobile;index:idx_user_instance_mobile;type:varchar(15);default:null;comment:联系方式" json:"mobile"`
|
||||
Identity int `gorm:"column:identity;type:int(8);default:0;comment:身份信息" json:"-"`
|
||||
Password string `gorm:"column:password;type:varchar(100);default:null;comment:密码" json:"-"`
|
||||
|
@ -1,16 +1,9 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/utils"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UserTenant struct {
|
||||
Model
|
||||
ModelTenant
|
||||
UID uint64 `gorm:"column:uid;index:idx_tenant_user_uuid;type:int;default:0;comment:用户表UUID" json:"-"`
|
||||
UUID uint64 `gorm:"column:uuid;uniqueIndex:idx_tenant_user_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255);default:null;comment:头像" json:"avatar"`
|
||||
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
|
||||
Email string `gorm:"column:email;type:varchar(50);default:null;comment:邮箱" json:"email"`
|
||||
@ -18,7 +11,7 @@ type UserTenant struct {
|
||||
Area
|
||||
Selected UserTenantSelected `gorm:"column:selected;type:tinyint(1);default:0;comment:最后一次选中的身份状态,用于下次登陆展示" json:"-"`
|
||||
Other string `gorm:"column:other;type:varchar(255);default:null;comment:其他信息" json:"-"`
|
||||
Status int `gorm:"column:status;type:tinyint(0);default:0;comment:状态-未使用" json:"-"`
|
||||
Status UserTenantStatus `gorm:"column:status;type:tinyint(0);default:0;comment:状态" json:"-"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
@ -32,17 +25,23 @@ const (
|
||||
UserTenantSelectedForYes
|
||||
)
|
||||
|
||||
type UserTenantStatus int
|
||||
|
||||
const (
|
||||
// UserTenantStatusForInit 初始化
|
||||
UserTenantStatusForInit UserTenantStatus = iota
|
||||
// UserTenantStatusForExamining 审核中
|
||||
UserTenantStatusForExamining
|
||||
// UserTenantStatusForExamineRefuse 审核拒绝
|
||||
UserTenantStatusForExamineRefuse
|
||||
// UserTenantStatusForExaminePass 审核通过
|
||||
UserTenantStatusForExaminePass
|
||||
)
|
||||
|
||||
func (m *UserTenant) TableName() string {
|
||||
return m.NewTableName("user_tenant")
|
||||
}
|
||||
|
||||
func (m *UserTenant) BeforeCreate(db *gorm.DB) error {
|
||||
snowflake, _ := utils.NewSnowflake(1)
|
||||
m.UUID = uint64(snowflake.GetID())
|
||||
m.CreatedAt = time.Now()
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewUserTenant() *UserTenant {
|
||||
return &UserTenant{}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ type InstanceLoginCallback func(params *InstanceLoginParams) *InstanceLoginRetur
|
||||
type (
|
||||
InstanceLoginParams struct {
|
||||
UID uint64
|
||||
Name, Mobile string
|
||||
Name, Mobile, Avatar string
|
||||
Identity, SelectIdentity int
|
||||
Status model.AccountStatusKind
|
||||
}
|
||||
@ -34,10 +34,11 @@ func (c *Instance) Login() InstanceLoginCallback {
|
||||
session := service.NewSessionEnterprise()
|
||||
session.Token = token
|
||||
session.UID = params.UID
|
||||
session.Avatar = params.Avatar
|
||||
session.Name = params.Name
|
||||
session.Mobile = params.Mobile
|
||||
session.Identity = params.Identity
|
||||
session.CurrentIdentity = params.SelectIdentity
|
||||
session.SelectIdentity = params.SelectIdentity
|
||||
|
||||
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, utils.UintToString(params.UID), session)
|
||||
|
||||
|
@ -4,10 +4,8 @@ import (
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/enterprise/model"
|
||||
"SciencesServer/app/handle"
|
||||
"SciencesServer/serve/orm"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Login struct{}
|
||||
@ -61,43 +59,28 @@ func loginForSmsCaptcha(params *LoginParams) (*InstanceLoginParams, error) {
|
||||
|
||||
mUserInstance := model.NewUserInstance()
|
||||
|
||||
mUserTenant := model.NewUserTenant()
|
||||
|
||||
if isExist, err = model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "name", "mobile", "status"},
|
||||
model2.NewWhere("mobile", params.Captcha.Mobile)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mUserTenant := model.NewUserTenant()
|
||||
|
||||
if isExist {
|
||||
// TODO:未处理删除用户身份的管理信息
|
||||
// 最后一次选中的身份信息
|
||||
if isExist, err = model2.FirstField(mUserTenant.UserTenant, []string{"id", "uid", "uuid", "name", "identity"},
|
||||
model2.NewWhere("uid", mUserInstance.UUID),
|
||||
model2.NewWhere("selected", model2.UserTenantSelectedForYes)); err != nil {
|
||||
if err = mUserTenant.LastChooseInfo(mUserInstance.UUID); err != nil {
|
||||
return nil, err
|
||||
} else if isExist {
|
||||
goto RETURNS
|
||||
}
|
||||
goto RETURNS
|
||||
}
|
||||
mUserInstance.Password = utils.GetRandomString(12)
|
||||
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if mUserInstance.ID <= 0 {
|
||||
if err = model2.Create(mUserInstance.UserInstance, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
mUserTenant.UID = mUserInstance.UUID
|
||||
mUserTenant.Name = params.Captcha.Mobile
|
||||
mUserTenant.Selected = model2.UserTenantSelectedForYes
|
||||
return model2.Create(mUserTenant.UserTenant, tx)
|
||||
}); err != nil {
|
||||
if err = model2.Create(mUserInstance.UserInstance); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
RETURNS:
|
||||
return &InstanceLoginParams{
|
||||
UID: mUserTenant.UUID, Name: mUserTenant.Name, Mobile: mUserInstance.Mobile,
|
||||
Identity: mUserInstance.Identity, SelectIdentity: mUserTenant.Identity,
|
||||
Status: mUserInstance.Status,
|
||||
UID: mUserInstance.UUID, Name: mUserInstance.Name, Mobile: mUserInstance.Mobile, Avatar: mUserTenant.Avatar,
|
||||
Identity: mUserInstance.Identity, SelectIdentity: mUserTenant.Identity, Status: mUserInstance.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -119,24 +102,15 @@ func loginForPassword(params *LoginParams) (*InstanceLoginParams, error) {
|
||||
if !mUserInstance.ValidatePassword(params.Password.Password) {
|
||||
return nil, errors.New("账户或密码错误")
|
||||
}
|
||||
mUserTenant := model.NewUserTenant()
|
||||
// 最后一次选中的身份信息
|
||||
if isExist, err = model2.FirstField(mUserTenant.UserTenant, []string{"id", "uid", "uuid", "name", "identity"},
|
||||
model2.NewWhere("uid", mUserInstance.UUID),
|
||||
model2.NewWhere("selected", model2.UserTenantSelectedForYes)); err != nil {
|
||||
mUserTenant := model.NewUserTenant()
|
||||
|
||||
if err = mUserTenant.LastChooseInfo(mUserInstance.UUID); err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
mUserTenant.UID = mUserInstance.UUID
|
||||
mUserTenant.Name = params.Password.Mobile
|
||||
mUserTenant.Selected = model2.UserTenantSelectedForYes
|
||||
if err = model2.Create(mUserTenant.UserTenant); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &InstanceLoginParams{
|
||||
UID: mUserTenant.UUID, Name: mUserTenant.Name, Mobile: mUserInstance.Mobile,
|
||||
Identity: mUserInstance.Identity, SelectIdentity: mUserTenant.Identity,
|
||||
Status: mUserInstance.Status,
|
||||
UID: mUserInstance.UUID, Name: mUserInstance.Name, Mobile: mUserInstance.Mobile, Avatar: mUserTenant.Avatar,
|
||||
Identity: mUserInstance.Identity, SelectIdentity: mUserTenant.Identity, Status: mUserInstance.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -145,12 +119,12 @@ func loginForPlatform(params *LoginParams) error {
|
||||
}
|
||||
|
||||
func (c *Login) Launch(mode LoginMode, params *LoginParams) (*InstanceLoginReturn, error) {
|
||||
handle, has := loginHandle[mode]
|
||||
_handle, has := loginHandle[mode]
|
||||
|
||||
if !has {
|
||||
return nil, errors.New("未知的登陆模式")
|
||||
}
|
||||
ret, err := handle(params)
|
||||
ret, err := _handle(params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -31,8 +31,19 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Instance) User() {
|
||||
type (
|
||||
// InstanceInfoReturn 基本信息返回
|
||||
InstanceInfoReturn struct {
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
Identity string `json:"identity"`
|
||||
SelectIdentity string `json:"select_identity"` // 最后一次选中的身份信息
|
||||
}
|
||||
)
|
||||
|
||||
// Info 基本信息
|
||||
func (c *Instance) Info() *InstanceInfoReturn {
|
||||
return &InstanceInfoReturn{Name: c.Name}
|
||||
}
|
||||
|
||||
// Perfect 完善信息
|
||||
@ -49,9 +60,10 @@ func (c *Instance) Perfect(params *InstancePerfectParams) error {
|
||||
mUserTenant.Name = params.Name
|
||||
mUserTenant.Email = params.Email
|
||||
mUserTenant.Area = model2.Area{Province: params.Province, City: params.City, District: params.District, Address: params.Address}
|
||||
// 更新身份信息
|
||||
// 更新身份信息,提交审核
|
||||
if mUserTenant.Identity == 0 {
|
||||
mUserTenant.Identity = c.CurrentIdentity
|
||||
mUserTenant.Status = model2.UserTenantStatusForExamining
|
||||
}
|
||||
orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
return nil
|
||||
@ -77,7 +89,7 @@ func (c *Instance) ChangeIdentity(identity int) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.UID = mUserTenant.UUID
|
||||
//c.UID = mUserTenant.UUID
|
||||
|
||||
now := time.Now()
|
||||
|
||||
|
@ -8,6 +8,13 @@ type UserTenant struct {
|
||||
*model.UserTenant
|
||||
}
|
||||
|
||||
func (m *UserTenant) LastChooseInfo(uid uint64) error {
|
||||
_, err := model.FirstField(m.UserTenant, []string{"id", "uuid", "avatar", "identity"},
|
||||
model.NewWhere("uid", uid),
|
||||
model.NewWhere("selected", model.UserTenantSelectedForYes))
|
||||
return err
|
||||
}
|
||||
|
||||
func NewUserTenant() *UserTenant {
|
||||
return &UserTenant{UserTenant: model.NewUserTenant()}
|
||||
}
|
||||
|
@ -29,12 +29,13 @@ func NewSession() *Session {
|
||||
|
||||
// SessionEnterprise 企业用户
|
||||
type SessionEnterprise struct {
|
||||
UID uint64 `json:"uid"` // 唯一标识ID
|
||||
Token string `json:"token"` // token
|
||||
Name string `json:"name"` // 名称
|
||||
Mobile string `json:"mobile"` // 手机号码
|
||||
Identity int `json:"identity"` // 总身份信息
|
||||
CurrentIdentity int `json:"current_identity"` // 当前身份信息
|
||||
UID uint64 `json:"uid"` // 唯一标识ID
|
||||
Token string `json:"token"` // token
|
||||
Name string `json:"name"` // 名称
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
Mobile string `json:"mobile"` // 手机号码
|
||||
Identity int `json:"identity"` // 总身份信息
|
||||
SelectIdentity int `json:"select_identity"` // 选中身份信息
|
||||
}
|
||||
|
||||
func (this *SessionEnterprise) MarshalBinary() ([]byte, error) {
|
||||
|
Reference in New Issue
Block a user