feat:完善信息
This commit is contained in:
@ -8,10 +8,10 @@ import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Login struct{}
|
||||
type Login struct{ local uint64 }
|
||||
|
||||
type (
|
||||
LoginHandle func() *Login
|
||||
LoginHandle func(local uint64) *Login
|
||||
)
|
||||
|
||||
type (
|
||||
@ -38,12 +38,12 @@ const (
|
||||
LoginModeForQQ // QQ登陆
|
||||
)
|
||||
|
||||
var loginHandle = map[LoginMode]func(*LoginParams) (*InstanceLoginParams, error){
|
||||
var loginHandle = map[LoginMode]func(*LoginParams, uint64) (*InstanceLoginParams, error){
|
||||
LoginModeForSmsCaptcha: loginForSmsCaptcha, LoginModeForPassword: loginForPassword,
|
||||
}
|
||||
|
||||
// loginForSmsCaptcha 短信验证码登陆
|
||||
func loginForSmsCaptcha(params *LoginParams) (*InstanceLoginParams, error) {
|
||||
func loginForSmsCaptcha(params *LoginParams, local uint64) (*InstanceLoginParams, error) {
|
||||
if !utils.ValidateMobile(params.Captcha.Mobile) {
|
||||
return nil, errors.New("手机号码格式异常")
|
||||
}
|
||||
@ -56,18 +56,18 @@ func loginForSmsCaptcha(params *LoginParams) (*InstanceLoginParams, error) {
|
||||
return nil, errors.New("验证码错误或已过期")
|
||||
}
|
||||
var isExist bool
|
||||
|
||||
// 查询账号信息
|
||||
mUserInstance := model.NewUserInstance()
|
||||
|
||||
if isExist, err = model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "name", "mobile", "status"},
|
||||
model2.NewWhere("mobile", params.Captcha.Mobile)); err != nil {
|
||||
model2.NewWhere("mobile", params.Captcha.Mobile), model2.NewWhere("local", local)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mUserTenant := model.NewUserTenant()
|
||||
mUserManage := model.NewUserManage()
|
||||
|
||||
if isExist {
|
||||
if err = mUserTenant.LastChooseInfo(mUserInstance.UUID); err != nil {
|
||||
// 查询该区域下最后一次选中的信息
|
||||
if err = mUserManage.LastChooseInfo(mUserInstance.UUID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
goto RETURNS
|
||||
@ -79,22 +79,22 @@ func loginForSmsCaptcha(params *LoginParams) (*InstanceLoginParams, error) {
|
||||
}
|
||||
RETURNS:
|
||||
return &InstanceLoginParams{
|
||||
UID: mUserInstance.UUID, TenantID: mUserTenant.TenantID, TenantUID: mUserTenant.UUID,
|
||||
UID: mUserInstance.UUID, TenantID: mUserManage.TenantID, TenantUID: mUserManage.UUID,
|
||||
Name: mUserInstance.Name, Mobile: mUserInstance.Mobile,
|
||||
Identity: mUserInstance.Identity, SelectIdentity: mUserTenant.Identity,
|
||||
Identity: mUserInstance.Identity, SelectIdentity: mUserManage.Identity,
|
||||
Status: mUserInstance.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// loginForPassword 密码登陆
|
||||
func loginForPassword(params *LoginParams) (*InstanceLoginParams, error) {
|
||||
func loginForPassword(params *LoginParams, local uint64) (*InstanceLoginParams, error) {
|
||||
if !utils.ValidateMobile(params.Password.Mobile) {
|
||||
return nil, errors.New("手机号码格式异常")
|
||||
}
|
||||
mUserInstance := model.NewUserInstance()
|
||||
|
||||
isExist, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "mobile", "password", "salt", "status"},
|
||||
model2.NewWhere("mobile", params.Password.Mobile))
|
||||
model2.NewWhere("mobile", params.Password.Mobile), model2.NewWhere("local", local))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -105,15 +105,15 @@ func loginForPassword(params *LoginParams) (*InstanceLoginParams, error) {
|
||||
return nil, errors.New("账户或密码错误")
|
||||
}
|
||||
// 最后一次选中的身份信息
|
||||
mUserTenant := model.NewUserTenant()
|
||||
mUserManage := model.NewUserManage()
|
||||
|
||||
if err = mUserTenant.LastChooseInfo(mUserInstance.UUID); err != nil {
|
||||
if err = mUserManage.LastChooseInfo(mUserInstance.UUID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &InstanceLoginParams{
|
||||
UID: mUserInstance.UUID, TenantID: mUserTenant.TenantID, TenantUID: mUserTenant.UUID,
|
||||
UID: mUserInstance.UUID, TenantID: mUserManage.TenantID, TenantUID: mUserManage.UUID,
|
||||
Name: mUserInstance.Name, Mobile: mUserInstance.Mobile,
|
||||
Identity: mUserInstance.Identity, SelectIdentity: mUserTenant.Identity,
|
||||
Identity: mUserInstance.Identity, SelectIdentity: mUserManage.Identity,
|
||||
Status: mUserInstance.Status,
|
||||
}, nil
|
||||
}
|
||||
@ -128,7 +128,7 @@ func (c *Login) Launch(mode LoginMode, params *LoginParams) (*InstanceLoginRetur
|
||||
if !has {
|
||||
return nil, errors.New("未知的登陆模式")
|
||||
}
|
||||
ret, err := _handle(params)
|
||||
ret, err := _handle(params, c.local)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -140,7 +140,7 @@ func (c *Login) Launch(mode LoginMode, params *LoginParams) (*InstanceLoginRetur
|
||||
}
|
||||
|
||||
func NewLogin() LoginHandle {
|
||||
return func() *Login {
|
||||
return &Login{}
|
||||
return func(local uint64) *Login {
|
||||
return &Login{local: local}
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,12 @@ import (
|
||||
"SciencesServer/utils"
|
||||
)
|
||||
|
||||
type Logout struct{ *service.SessionEnterprise }
|
||||
type Logout struct {
|
||||
*service.SessionEnterprise
|
||||
local uint64
|
||||
}
|
||||
|
||||
type LogoutHandle func(*service.SessionEnterprise) *Logout
|
||||
type LogoutHandle func(enterprise *service.SessionEnterprise, local uint64) *Logout
|
||||
|
||||
func (c *Logout) Launch() error {
|
||||
service.Publish(config.EventForRedisHashDestroy, config.RedisKeyForAccount, utils.UintToString(c.UID))
|
||||
@ -16,7 +19,7 @@ func (c *Logout) Launch() error {
|
||||
}
|
||||
|
||||
func NewLogout() LogoutHandle {
|
||||
return func(enterprise *service.SessionEnterprise) *Logout {
|
||||
return &Logout{enterprise}
|
||||
return func(enterprise *service.SessionEnterprise, local uint64) *Logout {
|
||||
return &Logout{enterprise, local}
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Register struct{}
|
||||
type Register struct{ local uint64 }
|
||||
|
||||
type RegisterHandle func() *Register
|
||||
type RegisterHandle func(local uint64) *Register
|
||||
|
||||
type (
|
||||
RegisterParams struct {
|
||||
@ -25,65 +25,70 @@ func (c *RegisterParams) checkPassword() bool {
|
||||
return c.Password == c.RepeatPass
|
||||
}
|
||||
|
||||
func (c *RegisterParams) checkUserExist(mUserInstance *model2.UserInstance) (bool, error) {
|
||||
var count int64
|
||||
|
||||
if err := model2.Count(mUserInstance, &count, model2.NewWhere("mobile", c.Mobile)); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (c *RegisterParams) checkCaptcha() (bool, error) {
|
||||
return handle.NewCaptcha().Validate(&handle.CaptchaSms{Captcha: c.Captcha, Mobile: c.Mobile})
|
||||
}
|
||||
|
||||
func (c *RegisterParams) checkUserExist(mUserInstance *model2.UserInstance, local uint64) (bool, error) {
|
||||
var count int64
|
||||
|
||||
if err := model2.Count(mUserInstance, &count, model2.NewWhere("mobile", c.Mobile),
|
||||
model2.NewWhere("local", local)); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count <= 0, nil
|
||||
}
|
||||
|
||||
// Launch 发起注册
|
||||
func (c *Register) Launch(params *RegisterParams) (*InstanceLoginReturn, error) {
|
||||
// 验证密码
|
||||
if params.checkPassword() {
|
||||
return nil, errors.New("两次密码不一致")
|
||||
}
|
||||
mUserInstance := model.NewUserInstance()
|
||||
|
||||
pass, err := params.checkUserExist(mUserInstance.UserInstance)
|
||||
// 验证验证码
|
||||
pass, err := params.checkCaptcha()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if pass {
|
||||
return nil, errors.New("当前手机号码已注册")
|
||||
}
|
||||
if pass, err = params.checkCaptcha(); err != nil {
|
||||
return nil, err
|
||||
} else if !pass {
|
||||
return nil, errors.New("验证码错误或已过期")
|
||||
}
|
||||
// 验证账号信息
|
||||
mUserInstance := model.NewUserInstance()
|
||||
|
||||
if pass, err = params.checkUserExist(mUserInstance.UserInstance, c.local); err != nil {
|
||||
return nil, err
|
||||
} else if !pass {
|
||||
return nil, errors.New("当前手机号码已注册")
|
||||
}
|
||||
mUserInstance.Local.Local = c.local
|
||||
mUserInstance.Password = utils.GetRandomString(12)
|
||||
mUserInstance.Mobile = params.Mobile
|
||||
mUserInstance.Password = params.Password
|
||||
mUserInstance.Identity = params.Identity
|
||||
|
||||
mUserTenant := model.NewUserTenant()
|
||||
mUserManage := model.NewUserManage()
|
||||
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.Create(mUserInstance.UserInstance, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
mUserTenant.UID = mUserInstance.UUID
|
||||
mUserTenant.Name = params.Name
|
||||
mUserTenant.Identity = params.Identity
|
||||
mUserTenant.Selected = model2.UserTenantSelectedForYes
|
||||
return model2.Create(mUserTenant.UserTenant, tx)
|
||||
mUserManage.UID = mUserInstance.UUID
|
||||
mUserManage.Name = params.Name
|
||||
mUserManage.Identity = params.Identity
|
||||
mUserManage.Selected = model2.UserManageSelectedForYes
|
||||
return model2.Create(mUserManage.UserManage, tx)
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewInstance()().Login()(&InstanceLoginParams{
|
||||
UID: mUserTenant.UUID, Name: mUserTenant.Name, Mobile: mUserInstance.Mobile,
|
||||
UID: mUserManage.UUID, Name: mUserManage.Name, Mobile: mUserInstance.Mobile,
|
||||
Identity: mUserInstance.Identity, SelectIdentity: params.Identity,
|
||||
}), err
|
||||
}
|
||||
|
||||
func NewRegister() RegisterHandle {
|
||||
return func() *Register {
|
||||
return &Register{}
|
||||
return func(local uint64) *Register {
|
||||
return &Register{local: local}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,17 @@
|
||||
package technology
|
||||
|
||||
import "SciencesServer/app/service"
|
||||
|
||||
// Patent 专利管理
|
||||
type Patent struct{}
|
||||
type Patent struct {
|
||||
*service.SessionEnterprise
|
||||
local uint64
|
||||
}
|
||||
|
||||
type PatentHandle func(enterprise *service.SessionEnterprise, local uint64) *Patent
|
||||
|
||||
func NewPatent() PatentHandle {
|
||||
return func(enterprise *service.SessionEnterprise, local uint64) *Patent {
|
||||
return &Patent{SessionEnterprise: enterprise, local: local}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user