mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 19:16:35 +08:00
add reset pwd
This commit is contained in:
@@ -21,6 +21,7 @@ type paramsVerificationCode struct {
|
||||
Email string `json:"email"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UsedFor int `json:"usedFor" binding:"required"`
|
||||
}
|
||||
|
||||
func SendVerificationCode(c *gin.Context) {
|
||||
@@ -36,25 +37,32 @@ func SendVerificationCode(c *gin.Context) {
|
||||
} else {
|
||||
account = params.PhoneNumber
|
||||
}
|
||||
_, err := im_mysql_model.GetRegister(account)
|
||||
if err == nil {
|
||||
log.NewError(params.OperationID, "The phone number has been registered", params)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.HasRegistered, "errMsg": ""})
|
||||
return
|
||||
var accountKey string
|
||||
switch params.UsedFor {
|
||||
case constant.VerificationCodeForRegister:
|
||||
_, err := im_mysql_model.GetRegister(account)
|
||||
if err == nil {
|
||||
log.NewError(params.OperationID, "The phone number has been registered", params)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.HasRegistered, "errMsg": ""})
|
||||
return
|
||||
}
|
||||
ok, err := db.DB.JudgeAccountEXISTS(account)
|
||||
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": ""})
|
||||
return
|
||||
}
|
||||
accountKey = account + "_" + constant.VerificationCodeForRegisterSuffix
|
||||
|
||||
case constant.VerificationCodeForReset:
|
||||
accountKey = account + "_" + constant.VerificationCodeForResetSuffix
|
||||
}
|
||||
ok, err := db.DB.JudgeAccountEXISTS(account)
|
||||
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": ""})
|
||||
return
|
||||
}
|
||||
log.InfoByKv("begin sendSms", account)
|
||||
log.NewInfo(params.OperationID, params.UsedFor,"begin store redis", accountKey)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
code := 100000 + rand.Intn(900000)
|
||||
log.NewInfo(params.OperationID, "begin store redis", account)
|
||||
err = db.DB.SetAccountCode(account, code, config.Config.Demo.CodeTTL)
|
||||
err := db.DB.SetAccountCode(accountKey, code, config.Config.Demo.CodeTTL)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "set redis error", account, "err", err.Error())
|
||||
log.NewError(params.OperationID, "set redis error", accountKey, "err", err.Error())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.SmsSendCodeErr, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user