mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-12 13:05:58 +08:00
Merge remote-tracking branch 'origin/superGroup' into superGroup
This commit is contained in:
@@ -20,6 +20,7 @@ type ParamsLogin struct {
|
||||
Password string `json:"password"`
|
||||
Platform int32 `json:"platform"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
AreaCode string `json:"areaCode"`
|
||||
}
|
||||
|
||||
func Login(c *gin.Context) {
|
||||
@@ -35,7 +36,7 @@ func Login(c *gin.Context) {
|
||||
account = params.PhoneNumber
|
||||
}
|
||||
|
||||
r, err := im_mysql_model.GetRegister(account)
|
||||
r, err := im_mysql_model.GetRegister(account, params.AreaCode)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "user have not register", params.Password, account, err.Error())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.NotRegistered, "errMsg": "Mobile phone number is not registered"})
|
||||
|
||||
@@ -21,9 +21,9 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func onboardingProcess(operationID, userID, userName, faceURL string) {
|
||||
func onboardingProcess(operationID, userID, userName, faceURL, phoneNumber, email string) {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), userName, userID, faceURL)
|
||||
if err := createOrganizationUser(operationID, userID, userName); err != nil {
|
||||
if err := createOrganizationUser(operationID, userID, userName, phoneNumber, email); err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "createOrganizationUser failed", err.Error())
|
||||
}
|
||||
departmentID, err := imdb.GetRandomDepartmentID()
|
||||
@@ -45,7 +45,7 @@ func onboardingProcess(operationID, userID, userName, faceURL string) {
|
||||
oaNotification(operationID, userID)
|
||||
}
|
||||
|
||||
func createOrganizationUser(operationID, userID, userName string) error {
|
||||
func createOrganizationUser(operationID, userID, userName, phoneNumber, email string) error {
|
||||
defer func() {
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), userID)
|
||||
}()
|
||||
@@ -64,16 +64,15 @@ func createOrganizationUser(operationID, userID, userName string) error {
|
||||
EnglishName: randomEnglishName(),
|
||||
Gender: constant.Male,
|
||||
CreateTime: uint32(time.Now().Unix()),
|
||||
Telephone: phoneNumber,
|
||||
Mobile: phoneNumber,
|
||||
Email: email,
|
||||
},
|
||||
OperationID: operationID,
|
||||
OpUserID: config.Config.Manager.AppManagerUid[0],
|
||||
IsRegister: false,
|
||||
}
|
||||
if strings.Contains("@", userID) {
|
||||
req.OrganizationUser.Email = userID
|
||||
} else {
|
||||
req.OrganizationUser.Telephone = userID
|
||||
}
|
||||
|
||||
resp, err := client.CreateOrganizationUser(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
||||
|
||||
@@ -16,6 +16,7 @@ type resetPasswordRequest struct {
|
||||
Email string `json:"email"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
NewPassword string `json:"newPassword" binding:"required"`
|
||||
AreaCode string `json:"areaCode"`
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
@@ -34,7 +35,7 @@ func ResetPassword(c *gin.Context) {
|
||||
account = req.PhoneNumber
|
||||
}
|
||||
if req.VerificationCode != config.Config.Demo.SuperCode {
|
||||
accountKey := account + "_" + constant.VerificationCodeForResetSuffix
|
||||
accountKey := req.AreaCode + account + "_" + constant.VerificationCodeForResetSuffix
|
||||
v, err := db.DB.GetAccountCode(accountKey)
|
||||
if err != nil || v != req.VerificationCode {
|
||||
log.NewError(req.OperationID, "password Verification code error", account, req.VerificationCode, v)
|
||||
@@ -42,7 +43,7 @@ func ResetPassword(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
user, err := im_mysql_model.GetRegister(account)
|
||||
user, err := im_mysql_model.GetRegister(account, req.AreaCode)
|
||||
if err != nil || user.Account == "" {
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "get register error", err.Error())
|
||||
|
||||
@@ -27,6 +27,7 @@ type paramsVerificationCode struct {
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UsedFor int `json:"usedFor"`
|
||||
AreaCode string `json:"areaCode"`
|
||||
}
|
||||
|
||||
func SendVerificationCode(c *gin.Context) {
|
||||
@@ -42,28 +43,28 @@ func SendVerificationCode(c *gin.Context) {
|
||||
} else {
|
||||
account = params.PhoneNumber
|
||||
}
|
||||
var accountKey string
|
||||
var accountKey = params.AreaCode + account
|
||||
if params.UsedFor == 0 {
|
||||
params.UsedFor = constant.VerificationCodeForRegister
|
||||
}
|
||||
switch params.UsedFor {
|
||||
case constant.VerificationCodeForRegister:
|
||||
_, err := im_mysql_model.GetRegister(account)
|
||||
_, err := im_mysql_model.GetRegister(account, params.AreaCode)
|
||||
if err == nil {
|
||||
log.NewError(params.OperationID, "The phone number has been registered", params)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.HasRegistered, "errMsg": "The phone number has been registered"})
|
||||
return
|
||||
}
|
||||
ok, err := db.DB.JudgeAccountEXISTS(account)
|
||||
ok, err := db.DB.JudgeAccountEXISTS(accountKey)
|
||||
if ok || err != nil {
|
||||
log.NewError(params.OperationID, "The phone number has been registered", params)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.RepeatSendCode, "errMsg": "The phone number has been registered"})
|
||||
return
|
||||
}
|
||||
accountKey = account + "_" + constant.VerificationCodeForRegisterSuffix
|
||||
accountKey += "_" + constant.VerificationCodeForRegisterSuffix
|
||||
|
||||
case constant.VerificationCodeForReset:
|
||||
accountKey = account + "_" + constant.VerificationCodeForResetSuffix
|
||||
accountKey += "_" + constant.VerificationCodeForResetSuffix
|
||||
}
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
code := 100000 + rand.Intn(900000)
|
||||
@@ -95,7 +96,7 @@ func SendVerificationCode(c *gin.Context) {
|
||||
}
|
||||
|
||||
sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
|
||||
PhoneNumbers: tea.String(account),
|
||||
PhoneNumbers: tea.String(accountKey),
|
||||
SignName: tea.String(config.Config.Demo.AliSMSVerify.SignName),
|
||||
TemplateCode: tea.String(config.Config.Demo.AliSMSVerify.VerificationCodeTemplateCode),
|
||||
TemplateParam: tea.String(fmt.Sprintf("{\"code\":\"%d\"}", code)),
|
||||
|
||||
@@ -27,6 +27,7 @@ type ParamsSetPassword struct {
|
||||
Ex string `json:"ex"`
|
||||
FaceURL string `json:"faceURL"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
AreaCode string `json:"areaCode"`
|
||||
}
|
||||
|
||||
func SetPassword(c *gin.Context) {
|
||||
@@ -88,7 +89,7 @@ func SetPassword(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
log.Info(params.OperationID, "begin store mysql", account, params.Password, "info", params.FaceURL, params.Nickname)
|
||||
err = im_mysql_model.SetPassword(account, params.Password, params.Ex, userID)
|
||||
err = im_mysql_model.SetPassword(account, params.Password, params.Ex, userID, params.AreaCode)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "set phone number password error", account, "err", err.Error())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": err.Error()})
|
||||
@@ -96,7 +97,7 @@ func SetPassword(c *gin.Context) {
|
||||
}
|
||||
log.Info(params.OperationID, "end setPassword", account, params.Password)
|
||||
// demo onboarding
|
||||
onboardingProcess(params.OperationID, userID, params.Nickname, params.FaceURL)
|
||||
onboardingProcess(params.OperationID, userID, params.Nickname, params.FaceURL, params.AreaCode+params.PhoneNumber, params.Email)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": openIMRegisterResp.UserToken})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ type paramsCertification struct {
|
||||
VerificationCode string `json:"verificationCode"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UsedFor int `json:"usedFor"`
|
||||
AreaCode string `json:"areaCode"`
|
||||
}
|
||||
|
||||
func Verify(c *gin.Context) {
|
||||
@@ -31,7 +32,7 @@ func Verify(c *gin.Context) {
|
||||
if params.Email != "" {
|
||||
account = params.Email
|
||||
} else {
|
||||
account = params.PhoneNumber
|
||||
account = params.AreaCode + params.PhoneNumber
|
||||
}
|
||||
|
||||
if params.VerificationCode == config.Config.Demo.SuperCode {
|
||||
|
||||
Reference in New Issue
Block a user