From e98bd6abc5e65ef35b2f852edb2d6b4d0aa51620 Mon Sep 17 00:00:00 2001 From: CJ Date: Sun, 13 Jun 2021 16:18:43 +0800 Subject: [PATCH] Fix reset password --- datatype/request/user.go | 4 ++-- manage/user.go | 3 +-- route/v1/user.go | 4 ++-- utils/mail/mail.go | 5 +++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/datatype/request/user.go b/datatype/request/user.go index d34c633..27a0099 100644 --- a/datatype/request/user.go +++ b/datatype/request/user.go @@ -144,8 +144,8 @@ func (rvm *RegisterVerifyMail) Validation() bool { } type ResetPasswordMail struct { - Mail string `json:"mail"` - AppName string `json:"app_id"` + Mail string `json:"mail"` + AppID string `json:"app_id"` } func (rpm *ResetPasswordMail) Validation() bool { diff --git a/manage/user.go b/manage/user.go index f3e3837..a6a4bf8 100644 --- a/manage/user.go +++ b/manage/user.go @@ -883,9 +883,8 @@ func parseAppleIDToken(idToken string) (*appleIdTokenInfo, *perror.PlutoError) { } func (m *Manager) ResetPasswordMail(rpm request.ResetPasswordMail) *perror.PlutoError { - identifyToken := b64.RawStdEncoding.EncodeToString([]byte(rpm.Mail)) - _, err := models.Bindings(qm.Where("app_id = ? and login_type = ? and identify_token = ?", rpm.AppName, MAILLOGIN, identifyToken)).One(m.db) + _, err := models.Bindings(qm.Where("app_id = ? and login_type = ? and identify_token = ?", rpm.AppID, MAILLOGIN, identifyToken)).One(m.db) if err != nil && err == sql.ErrNoRows { return perror.MailNotExist } else if err != nil { diff --git a/route/v1/user.go b/route/v1/user.go index 22e6dca..82f8ea8 100644 --- a/route/v1/user.go +++ b/route/v1/user.go @@ -237,12 +237,12 @@ func (router *Router) PasswordResetMail(w http.ResponseWriter, r *http.Request) return err } language := r.Header.Get("Accept-Language") - appI18nName, err := router.manager.ApplicationI18nName(rpm.AppName, language) + appI18nName, err := router.manager.ApplicationI18nName(rpm.AppID, language) if err != nil { router.logger.Error(err.LogError.Error()) return err } - if err := ml.SendResetPassword(rpm.Mail, routeUtils.GetBaseURL(r), language, appI18nName); err != nil { + if err := ml.SendResetPassword(rpm.AppID, rpm.Mail, routeUtils.GetBaseURL(r), language, appI18nName); err != nil { router.logger.Error(err.LogError.Error()) return perror.SendMailFailure } diff --git a/utils/mail/mail.go b/utils/mail/mail.go index f5c8bdd..64a6ba3 100644 --- a/utils/mail/mail.go +++ b/utils/mail/mail.go @@ -110,8 +110,9 @@ func (m *Mail) SendRegisterVerify(userID uint, address string, baseURL string, l return nil } -func (m *Mail) SendResetPassword(address string, baseURL string, userLanguage string, appName string) *perror.PlutoError { - prp := jwt.NewPasswordResetPayload(appName, address, m.config.Token.ResetPasswordTokenExpire) +// appName 是字符串名称,用于邮件模板 +func (m *Mail) SendResetPassword(appID, address string, baseURL string, userLanguage string, appName string) *perror.PlutoError { + prp := jwt.NewPasswordResetPayload(appID, address, m.config.Token.ResetPasswordTokenExpire) token, perr := jwt.GenerateRSA256JWT(prp) if perr != nil { return perr.Wrapper(errors.New("JWT token generate failed"))