接口开发
This commit is contained in:
@ -93,7 +93,7 @@ func UserRegister(orm *gorm.DB, registerInfo sysmodel.FrontedUserRegisterReq) (i
|
||||
Password: registerInfo.Password,
|
||||
Salt: inttostring.GenerateRandomString(6),
|
||||
Email: registerInfo.Email,
|
||||
InviteCode: inttostring.NewInvite().Encode(int(time.Now().Unix())),
|
||||
InviteCode: inttostring.NewNumberInvite().Encode(int(time.Now().Unix())),
|
||||
Loginip: registerInfo.IP,
|
||||
Mobile: registerInfo.Phone,
|
||||
Area: registerInfo.PhoneAreaCode,
|
||||
@ -484,205 +484,222 @@ func GenerateToken(uid, source int, nickname, phone, email, ip, deviceID string)
|
||||
return jwtToken, expire, statuscode.OK
|
||||
}
|
||||
|
||||
// // 用户多端互踢
|
||||
//
|
||||
//// 用户多端互踢
|
||||
//func wsLoginKick(devId string, userId int) {
|
||||
// if devId == "" {
|
||||
// return
|
||||
// }
|
||||
// // 校验是否存在已经其他端登录
|
||||
// key := fmt.Sprintf("user-%v", userId)
|
||||
// // 读取原存储的设备号
|
||||
// preDevId, _ := helper.DefaultRedis.HGetField(rediskey.UserLoginWsClient, key)
|
||||
// // 将本次登录的设备号存储
|
||||
// _ = helper.DefaultRedis.HSetField(rediskey.UserLoginWsClient, key, devId)
|
||||
//
|
||||
// if string(preDevId) != devId {
|
||||
// // hc todo 注释
|
||||
// // 给上一个登录的端发送订阅消息
|
||||
// // data := &models.PushUserLoginKick{
|
||||
// // Type: 14,
|
||||
// // Data: string(preDevId), // 上一个登录端的设备号
|
||||
// // }
|
||||
// // // 通知用户账户最新信息
|
||||
// // by, _ := sonic.Marshal(data)
|
||||
// // log.Info("通知用户其他端已登录", zap.String("key", key), zap.ByteString("by", by))
|
||||
// // kafkahelper.SendKafkaMsg(kafkatopic.LoginKick, key, by)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//// ResetPwdBefore 1 重置密码前校验
|
||||
//func ResetPwdBefore(orm *gorm.DB, resetPwd sysmodel.ResetPwdReq) (user models.AdUser, code int) {
|
||||
// var err error
|
||||
//
|
||||
// if resetPwd.RetrieveType == 1 {
|
||||
// user, err = aduserdb.GetUserByPhone(orm, resetPwd.PhoneAreaCode, resetPwd.Phone)
|
||||
// if err != nil {
|
||||
// return user, statuscode.ServerError
|
||||
// func wsLoginKick(devId string, userId int) {
|
||||
// if devId == "" {
|
||||
// return
|
||||
// }
|
||||
// } else if resetPwd.RetrieveType == 2 {
|
||||
// user, err = aduserdb.GetUserByEmail(orm, resetPwd.Email) //GetUser("useremail", resetPwd.Email)
|
||||
// if err != nil {
|
||||
// return user, statuscode.ServerError
|
||||
// // 校验是否存在已经其他端登录
|
||||
// key := fmt.Sprintf("user-%v", userId)
|
||||
// // 读取原存储的设备号
|
||||
// preDevId, _ := helper.DefaultRedis.HGetField(rediskey.UserLoginWsClient, key)
|
||||
// // 将本次登录的设备号存储
|
||||
// _ = helper.DefaultRedis.HSetField(rediskey.UserLoginWsClient, key, devId)
|
||||
//
|
||||
// if string(preDevId) != devId {
|
||||
// // hc todo 注释
|
||||
// // 给上一个登录的端发送订阅消息
|
||||
// // data := &models.PushUserLoginKick{
|
||||
// // Type: 14,
|
||||
// // Data: string(preDevId), // 上一个登录端的设备号
|
||||
// // }
|
||||
// // // 通知用户账户最新信息
|
||||
// // by, _ := sonic.Marshal(data)
|
||||
// // log.Info("通知用户其他端已登录", zap.String("key", key), zap.ByteString("by", by))
|
||||
// // kafkahelper.SendKafkaMsg(kafkatopic.LoginKick, key, by)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if user.Id == 0 {
|
||||
// return user, statuscode.TheAccountIsNotRegistered
|
||||
// // ResetPwdBefore 1 重置密码前校验
|
||||
//
|
||||
// func ResetPwdBefore(orm *gorm.DB, resetPwd sysmodel.ResetPwdReq) (user models.AdUser, code int) {
|
||||
// var err error
|
||||
//
|
||||
// if resetPwd.RetrieveType == 1 {
|
||||
// user, err = aduserdb.GetUserByPhone(orm, resetPwd.PhoneAreaCode, resetPwd.Phone)
|
||||
// if err != nil {
|
||||
// return user, statuscode.ServerError
|
||||
// }
|
||||
// } else if resetPwd.RetrieveType == 2 {
|
||||
// user, err = aduserdb.GetUserByEmail(orm, resetPwd.Email) //GetUser("useremail", resetPwd.Email)
|
||||
// if err != nil {
|
||||
// return user, statuscode.ServerError
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if user.Id == 0 {
|
||||
// return user, statuscode.TheAccountIsNotRegistered
|
||||
// }
|
||||
//
|
||||
// return user, statuscode.OK
|
||||
// }
|
||||
//
|
||||
// return user, statuscode.OK
|
||||
//}
|
||||
// // ResetPwdCheck 2 重置密码安全验证
|
||||
//
|
||||
//// ResetPwdCheck 2 重置密码安全验证
|
||||
//func ResetPwdCheck(orm *gorm.DB, rpc sysmodel.ResetPwdCheck) (string, int) {
|
||||
// var (
|
||||
// user models.AdUser
|
||||
// err error
|
||||
// )
|
||||
// func ResetPwdCheck(orm *gorm.DB, rpc sysmodel.ResetPwdCheck) (string, int) {
|
||||
// var (
|
||||
// user models.AdUser
|
||||
// err error
|
||||
// )
|
||||
//
|
||||
// if rpc.RetrieveType == 1 {
|
||||
// user, err = aduserdb.GetUserByPhone(orm, rpc.PhoneAreaCode, rpc.Phone)
|
||||
// if rpc.RetrieveType == 1 {
|
||||
// user, err = aduserdb.GetUserByPhone(orm, rpc.PhoneAreaCode, rpc.Phone)
|
||||
// if err != nil {
|
||||
// return "", statuscode.ServerError
|
||||
// }
|
||||
// } else if rpc.RetrieveType == 2 {
|
||||
// user, err = aduserdb.GetUserByEmail(orm, rpc.Email) //GetUser("useremail", rpc.Email)
|
||||
// if err != nil {
|
||||
// return "", statuscode.ServerError
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if user.Id == 0 {
|
||||
// return "", statuscode.TheAccountIsNotRegistered
|
||||
// }
|
||||
//
|
||||
// // 获取用户验证器开启状态
|
||||
// authSwitch, err := aduserdb.GetUserAuthSwitch(orm, user.Id)
|
||||
// if err != nil {
|
||||
// return "", statuscode.ServerError
|
||||
// }
|
||||
// } else if rpc.RetrieveType == 2 {
|
||||
// user, err = aduserdb.GetUserByEmail(orm, rpc.Email) //GetUser("useremail", rpc.Email)
|
||||
// if err != nil {
|
||||
// return "", statuscode.ServerError
|
||||
// // 验证器校验
|
||||
// validator := sysmodel.Authenticator{
|
||||
// UserID: user.Id,
|
||||
// PhoneAuth: authSwitch.PhoneAuth,
|
||||
// EmailAuth: authSwitch.EmailAuth,
|
||||
// GoogleAuth: authSwitch.GoogleAuth,
|
||||
// Phone: user.Phone,
|
||||
// Email: user.UserEmail,
|
||||
// GoogleSecret: authSwitch.GoogleSecret,
|
||||
// SmsCaptcha: rpc.SmsCaptcha,
|
||||
// EmailCaptcha: rpc.EmailCaptcha,
|
||||
// GoogleCaptcha: rpc.GoogleCaptcha,
|
||||
// BusinessType: businesstype.ResetPass,
|
||||
// }
|
||||
//
|
||||
// if code := AuthenticatorVerify(orm, validator); code != statuscode.OK {
|
||||
// return "", code
|
||||
// }
|
||||
//
|
||||
// // 校验验证码通过,生成下一步操作的凭证
|
||||
// cre := sysmodel.Credential{
|
||||
// BusinessType: int(businesstype.ResetPass),
|
||||
// UserID: user.Id,
|
||||
// Phone: user.Phone,
|
||||
// Email: user.UserEmail,
|
||||
// Time: time.Now().Unix(),
|
||||
// Rand: rand.NewSource(time.Now().UnixNano()).Int63(),
|
||||
// }
|
||||
// creJ, _ := sonic.Marshal(cre)
|
||||
// credentials := aeshelper.Encrypt(string(creJ), codeVerifySuccess)
|
||||
//
|
||||
// return credentials, statuscode.OK
|
||||
// }
|
||||
//
|
||||
// if user.Id == 0 {
|
||||
// return "", statuscode.TheAccountIsNotRegistered
|
||||
// // ResetPwd 3 重置密码
|
||||
//
|
||||
// func ResetPwd(orm *gorm.DB, user models.AdUser, resetPwd sysmodel.ResetPwdReq) int {
|
||||
// // 校验凭证
|
||||
// cre := sysmodel.Credential{
|
||||
// BusinessType: int(businesstype.ResetPass),
|
||||
// UserID: user.Id,
|
||||
// Phone: user.Phone,
|
||||
// Email: user.UserEmail,
|
||||
// Time: time.Now().Unix(),
|
||||
// }
|
||||
// if !CheckCredentials(cre, resetPwd.Credentials) {
|
||||
// log.Error("business credentials error")
|
||||
// return statuscode.BusinessCredentialsError
|
||||
// }
|
||||
//
|
||||
// // 更新密码
|
||||
// if err := aduserdb.UpdateUserPwd(orm, resetPwd.UserID, resetPwd.Password); err != nil {
|
||||
// return statuscode.ServerError
|
||||
// }
|
||||
//
|
||||
// return statuscode.OK
|
||||
// }
|
||||
//
|
||||
// // 获取用户验证器开启状态
|
||||
// authSwitch, err := aduserdb.GetUserAuthSwitch(orm, user.Id)
|
||||
// if err != nil {
|
||||
// return "", statuscode.ServerError
|
||||
// }
|
||||
// // 验证器校验
|
||||
// validator := sysmodel.Authenticator{
|
||||
// UserID: user.Id,
|
||||
// PhoneAuth: authSwitch.PhoneAuth,
|
||||
// EmailAuth: authSwitch.EmailAuth,
|
||||
// GoogleAuth: authSwitch.GoogleAuth,
|
||||
// Phone: user.Phone,
|
||||
// Email: user.UserEmail,
|
||||
// GoogleSecret: authSwitch.GoogleSecret,
|
||||
// SmsCaptcha: rpc.SmsCaptcha,
|
||||
// EmailCaptcha: rpc.EmailCaptcha,
|
||||
// GoogleCaptcha: rpc.GoogleCaptcha,
|
||||
// BusinessType: businesstype.ResetPass,
|
||||
// // ChangePwdBefore 修改密码前校验
|
||||
// func ChangePwdBefore(orm *gorm.DB, params sysmodel.UserChangePwdReq) (user models.AdUser, code int) {
|
||||
//
|
||||
// user, err := aduserdb.GetUserById(orm, params.UserId) //"id", params.UserId)
|
||||
//
|
||||
// if err != nil {
|
||||
// return user, statuscode.ServerError
|
||||
// }
|
||||
// if user.UserPassword != params.OldPassword {
|
||||
// return user, statuscode.OriginalPasswordError
|
||||
// }
|
||||
//
|
||||
// return user, statuscode.OK
|
||||
// }
|
||||
//
|
||||
// if code := AuthenticatorVerify(orm, validator); code != statuscode.OK {
|
||||
// return "", code
|
||||
// // ChangePwd 修改密码
|
||||
//
|
||||
// func ChangePwd(orm *gorm.DB, params sysmodel.UserChangePwdReq, user models.AdUser) int {
|
||||
// // 获取用户验证器开关状态
|
||||
// authSwitch, err := GetUserAuthSwitch(orm, user.Id)
|
||||
// if err != nil {
|
||||
// return statuscode.ServerError
|
||||
// }
|
||||
//
|
||||
// // 验证器验证
|
||||
// auth := sysmodel.Authenticator{
|
||||
// UserID: params.UserId,
|
||||
// PhoneAuth: authSwitch.PhoneAuth,
|
||||
// EmailAuth: authSwitch.EmailAuth,
|
||||
// GoogleAuth: authSwitch.GoogleAuth,
|
||||
// Phone: user.Phone,
|
||||
// Email: user.UserEmail,
|
||||
// GoogleSecret: authSwitch.GoogleSecret,
|
||||
// SmsCaptcha: params.SmsCaptcha,
|
||||
// EmailCaptcha: params.EmailCaptcha,
|
||||
// GoogleCaptcha: params.GoogleCaptcha,
|
||||
// BusinessType: businesstype.ChangePassword,
|
||||
// }
|
||||
// if code := AuthenticatorVerify(orm, auth); code != statuscode.OK {
|
||||
// return code
|
||||
// }
|
||||
//
|
||||
// // 更新密码
|
||||
// if err = aduserdb.UpdateUserPwd(orm, params.UserId, params.NewPassword); err != nil {
|
||||
// return statuscode.ServerError
|
||||
// }
|
||||
//
|
||||
// return statuscode.OK
|
||||
// }
|
||||
//
|
||||
// // 校验验证码通过,生成下一步操作的凭证
|
||||
// cre := sysmodel.Credential{
|
||||
// BusinessType: int(businesstype.ResetPass),
|
||||
// UserID: user.Id,
|
||||
// Phone: user.Phone,
|
||||
// Email: user.UserEmail,
|
||||
// Time: time.Now().Unix(),
|
||||
// Rand: rand.NewSource(time.Now().UnixNano()).Int63(),
|
||||
// // GetUserRealName 获取用户真实姓名
|
||||
//
|
||||
// func GetUserRealName(orm *gorm.DB, uid int) string {
|
||||
// buyerIdent, err := aduserdb.GetIdentification(orm, uid)
|
||||
// if err != nil {
|
||||
// return ""
|
||||
// }
|
||||
// realName := buyerIdent.Name
|
||||
//
|
||||
// if buyerIdent.CountryId == 40 || buyerIdent.CountryId == 73 ||
|
||||
// buyerIdent.CountryId == 115 || buyerIdent.CountryId == 179 {
|
||||
// realName = buyerIdent.Name // 中国大陆,港澳台
|
||||
// } else {
|
||||
// // 名字-中间名-姓
|
||||
// realName = buyerIdent.Name + " " + buyerIdent.MiddleName + " " + buyerIdent.Surname
|
||||
// }
|
||||
//
|
||||
// return realName
|
||||
// }
|
||||
// creJ, _ := sonic.Marshal(cre)
|
||||
// credentials := aeshelper.Encrypt(string(creJ), codeVerifySuccess)
|
||||
//
|
||||
// return credentials, statuscode.OK
|
||||
//}
|
||||
//
|
||||
//// ResetPwd 3 重置密码
|
||||
//func ResetPwd(orm *gorm.DB, user models.AdUser, resetPwd sysmodel.ResetPwdReq) int {
|
||||
// // 校验凭证
|
||||
// cre := sysmodel.Credential{
|
||||
// BusinessType: int(businesstype.ResetPass),
|
||||
// UserID: user.Id,
|
||||
// Phone: user.Phone,
|
||||
// Email: user.UserEmail,
|
||||
// Time: time.Now().Unix(),
|
||||
// }
|
||||
// if !CheckCredentials(cre, resetPwd.Credentials) {
|
||||
// log.Error("business credentials error")
|
||||
// return statuscode.BusinessCredentialsError
|
||||
// }
|
||||
//
|
||||
// // 更新密码
|
||||
// if err := aduserdb.UpdateUserPwd(orm, resetPwd.UserID, resetPwd.Password); err != nil {
|
||||
// return statuscode.ServerError
|
||||
// }
|
||||
//
|
||||
// return statuscode.OK
|
||||
//}
|
||||
//
|
||||
//// ChangePwdBefore 修改密码前校验
|
||||
//func ChangePwdBefore(orm *gorm.DB, params sysmodel.UserChangePwdReq) (user models.AdUser, code int) {
|
||||
//
|
||||
// user, err := aduserdb.GetUserById(orm, params.UserId) //"id", params.UserId)
|
||||
//
|
||||
// if err != nil {
|
||||
// return user, statuscode.ServerError
|
||||
// }
|
||||
// if user.UserPassword != params.OldPassword {
|
||||
// return user, statuscode.OriginalPasswordError
|
||||
// }
|
||||
//
|
||||
// return user, statuscode.OK
|
||||
//}
|
||||
//
|
||||
//// ChangePwd 修改密码
|
||||
//func ChangePwd(orm *gorm.DB, params sysmodel.UserChangePwdReq, user models.AdUser) int {
|
||||
// // 获取用户验证器开关状态
|
||||
// authSwitch, err := GetUserAuthSwitch(orm, user.Id)
|
||||
// if err != nil {
|
||||
// return statuscode.ServerError
|
||||
// }
|
||||
//
|
||||
// // 验证器验证
|
||||
// auth := sysmodel.Authenticator{
|
||||
// UserID: params.UserId,
|
||||
// PhoneAuth: authSwitch.PhoneAuth,
|
||||
// EmailAuth: authSwitch.EmailAuth,
|
||||
// GoogleAuth: authSwitch.GoogleAuth,
|
||||
// Phone: user.Phone,
|
||||
// Email: user.UserEmail,
|
||||
// GoogleSecret: authSwitch.GoogleSecret,
|
||||
// SmsCaptcha: params.SmsCaptcha,
|
||||
// EmailCaptcha: params.EmailCaptcha,
|
||||
// GoogleCaptcha: params.GoogleCaptcha,
|
||||
// BusinessType: businesstype.ChangePassword,
|
||||
// }
|
||||
// if code := AuthenticatorVerify(orm, auth); code != statuscode.OK {
|
||||
// return code
|
||||
// }
|
||||
//
|
||||
// // 更新密码
|
||||
// if err = aduserdb.UpdateUserPwd(orm, params.UserId, params.NewPassword); err != nil {
|
||||
// return statuscode.ServerError
|
||||
// }
|
||||
//
|
||||
// return statuscode.OK
|
||||
//}
|
||||
//
|
||||
//// GetUserRealName 获取用户真实姓名
|
||||
//func GetUserRealName(orm *gorm.DB, uid int) string {
|
||||
// buyerIdent, err := aduserdb.GetIdentification(orm, uid)
|
||||
// if err != nil {
|
||||
// return ""
|
||||
// }
|
||||
// realName := buyerIdent.Name
|
||||
//
|
||||
// if buyerIdent.CountryId == 40 || buyerIdent.CountryId == 73 ||
|
||||
// buyerIdent.CountryId == 115 || buyerIdent.CountryId == 179 {
|
||||
// realName = buyerIdent.Name // 中国大陆,港澳台
|
||||
// } else {
|
||||
// // 名字-中间名-姓
|
||||
// realName = buyerIdent.Name + " " + buyerIdent.MiddleName + " " + buyerIdent.Surname
|
||||
// }
|
||||
//
|
||||
// return realName
|
||||
//}
|
||||
|
||||
// 退出登录
|
||||
func Logout(userId, source int) error {
|
||||
key := fmt.Sprintf(rediskey.AppLoginUserToken, userId)
|
||||
if source == 3 {
|
||||
key = fmt.Sprintf(rediskey.PCLoginUserToken, userId)
|
||||
}
|
||||
|
||||
err := helper.DefaultRedis.DeleteString(key)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user