add reset pwd

This commit is contained in:
wangchuxiao
2022-02-21 16:24:25 +08:00
parent a2cd7c8007
commit 4d28ccebad
10 changed files with 119 additions and 29 deletions
+23 -15
View File
@@ -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
}