feat:完善入驻信息管理
This commit is contained in:
@ -19,7 +19,7 @@ type (
|
||||
Password string `json:"password" form:"password"`
|
||||
}
|
||||
accountRegisterForm struct {
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Name string `json:"name" form:"name"`
|
||||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||||
Captcha string `json:"captcha" form:"captcha" binding:"required"`
|
||||
Password string `json:"password" form:"password" binding:"required"`
|
||||
|
@ -33,7 +33,7 @@ type (
|
||||
|
||||
func (*User) Info(c *gin.Context) {
|
||||
data := user.NewInstance()(api.GetSession()(c).(*session.Enterprise)).Info()
|
||||
api.APISuccess(data)
|
||||
api.APISuccess(data)(c)
|
||||
}
|
||||
|
||||
func (*User) BindMobile(c *gin.Context) {
|
||||
|
@ -3,8 +3,10 @@ package account
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/app/service"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/utils"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Instance struct{}
|
||||
@ -29,17 +31,17 @@ type (
|
||||
func (c *Instance) Login() InstanceLoginCallback {
|
||||
return func(params *InstanceLoginParams) *InstanceLoginReturn {
|
||||
token := utils.JWTEncrypt(config.SettingInfo.TokenEffectTime, map[string]interface{}{
|
||||
config.TokenForUID: params.UID,
|
||||
config.TokenForUID: fmt.Sprintf("%d", params.UID),
|
||||
})
|
||||
session := service.NewSessionEnterprise()
|
||||
session.Token = token
|
||||
session.UID = params.UID
|
||||
session.Name = params.Name
|
||||
session.Mobile = params.Mobile
|
||||
session.Identity = params.Identity
|
||||
session.SelectIdentity = params.SelectIdentity
|
||||
_session := session.NewEnterprise()
|
||||
_session.Token = token
|
||||
_session.UID = params.UID
|
||||
_session.Name = params.Name
|
||||
_session.Mobile = params.Mobile
|
||||
_session.Identity = params.Identity
|
||||
_session.SelectIdentity = params.SelectIdentity
|
||||
|
||||
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, session.UIDToString(), session)
|
||||
service.Publish(config.EventForRedisHashProduce, config.RedisKeyForAccount, _session.UIDToString(), _session)
|
||||
|
||||
return &InstanceLoginReturn{Token: token, EffectTime: config.SettingInfo.TokenEffectTime}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ var loginHandle = map[LoginMode]func(*LoginParams, string) (*InstanceLoginParams
|
||||
// loginForSmsCaptcha 短信验证码登陆
|
||||
func loginForSmsCaptcha(params *LoginParams, local string) (*InstanceLoginParams, error) {
|
||||
if !utils.ValidateMobile(params.Captcha.Mobile) {
|
||||
return nil, errors.New("手机号码格式异常")
|
||||
return nil, errors.New("操作错误,手机号码格式异常")
|
||||
}
|
||||
pass, err := handle.NewCaptcha().Validate(&handle.CaptchaSms{
|
||||
Mobile: params.Captcha.Mobile, Captcha: params.Captcha.Captcha,
|
||||
@ -53,14 +53,14 @@ func loginForSmsCaptcha(params *LoginParams, local string) (*InstanceLoginParams
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !pass {
|
||||
return nil, errors.New("验证码错误或已过期")
|
||||
return nil, errors.New("操作错误,验证码错误或已过期")
|
||||
}
|
||||
var isExist bool
|
||||
// 查询账号信息
|
||||
mUserInstance := model3.NewUserInstance()
|
||||
|
||||
if isExist, err = model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "name", "mobile", "status"},
|
||||
model2.NewWhere("mobile", params.Captcha.Mobile), model2.NewWhere("local", local)); err != nil {
|
||||
model2.NewWhere("mobile", params.Captcha.Mobile)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mUserIdentity := model3.NewUserIdentity()
|
||||
@ -72,6 +72,8 @@ func loginForSmsCaptcha(params *LoginParams, local string) (*InstanceLoginParams
|
||||
}
|
||||
goto RETURNS
|
||||
}
|
||||
mUserInstance.Name = params.Captcha.Mobile
|
||||
mUserInstance.Mobile = params.Captcha.Mobile
|
||||
mUserInstance.Password = utils.GetRandomString(12)
|
||||
|
||||
if err = model2.Create(mUserInstance.UserInstance); err != nil {
|
||||
@ -89,20 +91,20 @@ RETURNS:
|
||||
// loginForPassword 密码登陆
|
||||
func loginForPassword(params *LoginParams, local string) (*InstanceLoginParams, error) {
|
||||
if !utils.ValidateMobile(params.Password.Account) {
|
||||
return nil, errors.New("手机号码格式异常")
|
||||
return nil, errors.New("操作错误,手机号码格式异常")
|
||||
}
|
||||
mUserInstance := model3.NewUserInstance()
|
||||
|
||||
isExist, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "mobile", "password", "salt", "status"},
|
||||
model2.NewWhere("mobile", params.Password.Account), model2.NewWhere("local", local))
|
||||
isExist, err := model2.FirstField(mUserInstance.UserInstance, []string{"id", "uuid", "name", "mobile", "password", "salt", "status"},
|
||||
model2.NewWhere("mobile", params.Password.Account))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if isExist {
|
||||
return nil, errors.New("当前手机号码未注册")
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,当前手机号码未注册")
|
||||
}
|
||||
if !mUserInstance.ValidatePassword(params.Password.Password) {
|
||||
return nil, errors.New("账户或密码错误")
|
||||
return nil, errors.New("操作错误,账户或密码错误")
|
||||
}
|
||||
// 最后一次选中的身份信息
|
||||
mUserIdentity := model3.NewUserIdentity()
|
||||
@ -110,7 +112,6 @@ func loginForPassword(params *LoginParams, local string) (*InstanceLoginParams,
|
||||
if err = mUserIdentity.LastChooseInfo(mUserInstance.UUID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &InstanceLoginParams{
|
||||
UID: mUserInstance.UUID,
|
||||
Name: mUserInstance.Name, Mobile: mUserInstance.Mobile,
|
||||
@ -127,7 +128,7 @@ func (c *Login) Launch(mode LoginMode, params *LoginParams) (*InstanceLoginRetur
|
||||
_handle, has := loginHandle[mode]
|
||||
|
||||
if !has {
|
||||
return nil, errors.New("未知的登陆模式")
|
||||
return nil, errors.New("操作错误,未知的登陆模式")
|
||||
}
|
||||
ret, err := _handle(params, c.local)
|
||||
|
||||
@ -135,7 +136,7 @@ func (c *Login) Launch(mode LoginMode, params *LoginParams) (*InstanceLoginRetur
|
||||
return nil, err
|
||||
}
|
||||
if ret.Status != model2.AccountStatusForEnable {
|
||||
return nil, errors.New("该账号已禁止登陆,请联系管理员")
|
||||
return nil, errors.New("操作错误,该账号已禁止登陆,请联系管理员")
|
||||
}
|
||||
return NewInstance()().Login()(ret), err
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func (c *RegisterParams) checkUserExist(mUserInstance *model2.UserInstance, loca
|
||||
// Launch 发起注册
|
||||
func (c *Register) Launch(params *RegisterParams) (*InstanceLoginReturn, error) {
|
||||
// 验证密码
|
||||
if params.checkPassword() {
|
||||
if !params.checkPassword() {
|
||||
return nil, errors.New("两次密码不一致")
|
||||
}
|
||||
// 验证验证码
|
||||
@ -60,9 +60,13 @@ func (c *Register) Launch(params *RegisterParams) (*InstanceLoginReturn, error)
|
||||
} else if !pass {
|
||||
return nil, errors.New("当前手机号码已注册")
|
||||
}
|
||||
if params.Name == "" {
|
||||
params.Name = params.Mobile
|
||||
}
|
||||
mUserInstance.Source = model2.UserInstanceSourceForLocal
|
||||
mUserInstance.Password = utils.GetRandomString(12)
|
||||
mUserInstance.Mobile = params.Mobile
|
||||
mUserInstance.Name = params.Name
|
||||
mUserInstance.Password = params.Password
|
||||
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
|
Reference in New Issue
Block a user