From 215a6665a7d09c2ba48cab56a82a95177d97b0f0 Mon Sep 17 00:00:00 2001 From: liuzx Date: Wed, 23 Nov 2022 12:09:38 +0800 Subject: [PATCH 1/6] fix-2775 --- models/user_mail.go | 21 +++++++++++++++++++++ modules/auth/user_form.go | 4 ++++ routers/routes/routes.go | 2 ++ routers/user/auth.go | 15 +++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/models/user_mail.go b/models/user_mail.go index 8bf74b81b..d0547d589 100755 --- a/models/user_mail.go +++ b/models/user_mail.go @@ -216,6 +216,27 @@ func (email *EmailAddress) updateActivation(e Engine, activate bool) error { return updateUserCols(e, user, "rands") } +// UpdateEmailAddress update an email address of given user. +func (email *EmailAddress) UpdateEmailAddress(newEmailAddress string) error { + return email.updateEmailAddress(x, newEmailAddress) +} +func (email *EmailAddress) updateEmailAddress(e Engine, newEmailAddress string) error { + user, err := getUserByID(e, email.UID) + if err != nil { + return err + } + if user.Rands, err = GetUserSalt(); err != nil { + return err + } + user.Email = newEmailAddress + user.AvatarEmail = newEmailAddress + email.Email = newEmailAddress + if _, err := e.ID(email.ID).Cols("email").Update(email); err != nil { + return err + } + return updateUserCols(e, user, "email", "avartar_email") +} + // DeleteEmailAddress deletes an email address of given user. func DeleteEmailAddress(email *EmailAddress) (err error) { var deleted int64 diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go index ad78607ab..13dbd8155 100755 --- a/modules/auth/user_form.go +++ b/modules/auth/user_form.go @@ -88,6 +88,10 @@ type RegisterForm struct { Agree bool } +type UpdateEmailForm struct { + NewEmail string `binding:"Required;NewEmail;MaxSize(254)"` +} + // Validate valideates the fields func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { return validate(errs, ctx.Data, f, ctx.Locale) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 2b361b507..cdbf11be6 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -417,6 +417,8 @@ func RegisterRoutes(m *macaron.Macaron) { }, openIDSignInEnabled) m.Get("/sign_up", user.SignUp) m.Post("/sign_up", bindIgnErr(auth.RegisterForm{}), user.SignUpPost) + m.Post("/sign_up/update_email", bindIgnErr(auth.UpdateEmailForm{}), user.UpdateEmailPost) + m.Post("/sign_up/resend_email", user.ResendEmailPost) m.Group("/oauth2", func() { m.Get("/:provider", user.SignInOAuth) m.Get("/:provider/callback", user.SignInOAuthCallback) diff --git a/routers/user/auth.go b/routers/user/auth.go index 57ffb1710..586b278e6 100755 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -1413,6 +1413,21 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo handleSignInFull(ctx, u, false, true) } +func UpdateEmailPost(ctx *context.Context, form auth.UpdateEmailForm) { + newEmailAddress := form.NewEmail + if used, err := models.IsEmailUsed(newEmailAddress); used { + ctx.ServerError(ctx.Tr("form.email_been_used"), err) + return + } + user := ctx.User + email, err := models.GetEmailAddressByIDAndEmail(user.ID, user.Email) + if err != nil { + ctx.ServerError("GetEmailAddressByIDAndEmail failed", err) + return + } + email.UpdateEmailAddress(newEmailAddress) +} + // Activate render activate user page func Activate(ctx *context.Context) { code := ctx.Query("code") From c52642750f31eb6fd9d282eee6748c4fde2a1737 Mon Sep 17 00:00:00 2001 From: liuzx Date: Wed, 23 Nov 2022 18:10:10 +0800 Subject: [PATCH 2/6] fix-2775 --- routers/routes/routes.go | 3 +-- routers/user/auth.go | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index cdbf11be6..4f7cacbf3 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -417,8 +417,6 @@ func RegisterRoutes(m *macaron.Macaron) { }, openIDSignInEnabled) m.Get("/sign_up", user.SignUp) m.Post("/sign_up", bindIgnErr(auth.RegisterForm{}), user.SignUpPost) - m.Post("/sign_up/update_email", bindIgnErr(auth.UpdateEmailForm{}), user.UpdateEmailPost) - m.Post("/sign_up/resend_email", user.ResendEmailPost) m.Group("/oauth2", func() { m.Get("/:provider", user.SignInOAuth) m.Get("/:provider/callback", user.SignInOAuthCallback) @@ -520,6 +518,7 @@ func RegisterRoutes(m *macaron.Macaron) { // r.Get("/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) m.Any("/activate", user.Activate, reqSignIn) m.Any("/activate_email", user.ActivateEmail) + m.Post("/update_email", reqSignIn, bindIgnErr(auth.UpdateEmailForm{}), user.UpdateEmailPost) m.Get("/avatar/:username/:size", user.Avatar) m.Get("/email2user", user.Email2User) m.Get("/recover_account", user.ResetPasswd) diff --git a/routers/user/auth.go b/routers/user/auth.go index 586b278e6..022913e25 100755 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -1413,6 +1413,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo handleSignInFull(ctx, u, false, true) } +//update user emailAddress func UpdateEmailPost(ctx *context.Context, form auth.UpdateEmailForm) { newEmailAddress := form.NewEmail if used, err := models.IsEmailUsed(newEmailAddress); used { @@ -1425,7 +1426,12 @@ func UpdateEmailPost(ctx *context.Context, form auth.UpdateEmailForm) { ctx.ServerError("GetEmailAddressByIDAndEmail failed", err) return } - email.UpdateEmailAddress(newEmailAddress) + err = email.UpdateEmailAddress(newEmailAddress) + if err != nil { + ctx.ServerError("UpdateEmailAddress failed", err) + return + } + Activate(ctx) } // Activate render activate user page From caf41ff330783acc02f2bf5e40c4d5aa35dd14f7 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Thu, 24 Nov 2022 16:47:27 +0800 Subject: [PATCH 3/6] fix issue --- templates/user/auth/activate.tmpl | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/templates/user/auth/activate.tmpl b/templates/user/auth/activate.tmpl index 92b85a137..db64f7911 100644 --- a/templates/user/auth/activate.tmpl +++ b/templates/user/auth/activate.tmpl @@ -26,6 +26,7 @@

{{.i18n.Tr "auth.has_unconfirmed_mail" .SignedUser.Name .SignedUser.Email | Str2html}}

+
{{end}} @@ -34,5 +35,37 @@ +
+ +
{{template "base/footer" .}} + From 9858614ebc67c017f95ea0a289537433e6084804 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Thu, 24 Nov 2022 17:47:34 +0800 Subject: [PATCH 4/6] fix issue --- templates/user/auth/activate.tmpl | 39 ++++++++++++++----------------- web_src/less/openi.less | 14 +++++++++++ 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/templates/user/auth/activate.tmpl b/templates/user/auth/activate.tmpl index db64f7911..9a3fbf0e3 100644 --- a/templates/user/auth/activate.tmpl +++ b/templates/user/auth/activate.tmpl @@ -35,37 +35,32 @@ -
- {{template "base/footer" .}} diff --git a/web_src/less/openi.less b/web_src/less/openi.less index fe002ceb7..329802d47 100644 --- a/web_src/less/openi.less +++ b/web_src/less/openi.less @@ -1301,3 +1301,17 @@ i.SUCCEEDED { max-height: 500px; overflow: auto; } +.chang-email .content { + display: block; + width: 100%; + font-size: 1em; + line-height: 1.4; + padding: 1.5rem; + background: #fff; +} +.chang-email .actions { + background: #f9fafb; + padding: 1rem 1rem; + border-top: 1px solid rgba(34,36,38,.15); + text-align: right; +} \ No newline at end of file From 104a44748af423b715fd7a3f3f652a84cd6afc11 Mon Sep 17 00:00:00 2001 From: liuzx Date: Thu, 24 Nov 2022 18:40:14 +0800 Subject: [PATCH 5/6] fix-2775 --- models/user_mail.go | 2 +- modules/auth/user_form.go | 2 +- routers/routes/routes.go | 2 +- routers/user/auth.go | 13 ++++++++++--- templates/user/auth/activate.tmpl | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/models/user_mail.go b/models/user_mail.go index d0547d589..8388da068 100755 --- a/models/user_mail.go +++ b/models/user_mail.go @@ -234,7 +234,7 @@ func (email *EmailAddress) updateEmailAddress(e Engine, newEmailAddress string) if _, err := e.ID(email.ID).Cols("email").Update(email); err != nil { return err } - return updateUserCols(e, user, "email", "avartar_email") + return updateUserCols(e, user, "email", "avatar_email") } // DeleteEmailAddress deletes an email address of given user. diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go index 13dbd8155..521585264 100755 --- a/modules/auth/user_form.go +++ b/modules/auth/user_form.go @@ -89,7 +89,7 @@ type RegisterForm struct { } type UpdateEmailForm struct { - NewEmail string `binding:"Required;NewEmail;MaxSize(254)"` + NewEmail string `binding:"Required;MaxSize(254)"` } // Validate valideates the fields diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 4f7cacbf3..a988e4849 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -518,7 +518,7 @@ func RegisterRoutes(m *macaron.Macaron) { // r.Get("/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) m.Any("/activate", user.Activate, reqSignIn) m.Any("/activate_email", user.ActivateEmail) - m.Post("/update_email", reqSignIn, bindIgnErr(auth.UpdateEmailForm{}), user.UpdateEmailPost) + m.Post("/update_email", bindIgnErr(auth.UpdateEmailForm{}), user.UpdateEmailPost) m.Get("/avatar/:username/:size", user.Avatar) m.Get("/email2user", user.Email2User) m.Get("/recover_account", user.ResetPasswd) diff --git a/routers/user/auth.go b/routers/user/auth.go index 022913e25..bf858706d 100755 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -1415,9 +1415,13 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo //update user emailAddress func UpdateEmailPost(ctx *context.Context, form auth.UpdateEmailForm) { - newEmailAddress := form.NewEmail - if used, err := models.IsEmailUsed(newEmailAddress); used { - ctx.ServerError(ctx.Tr("form.email_been_used"), err) + newEmailAddress := ctx.Query("NewEmail") + if newEmailAddress == "" { + log.Error("please input the newEmail") + return + } + if used, _ := models.IsEmailUsed(newEmailAddress); used { + ctx.RenderWithErr(ctx.Tr("form.email_been_used"), TplActivate, &form) return } user := ctx.User @@ -1431,7 +1435,10 @@ func UpdateEmailPost(ctx *context.Context, form auth.UpdateEmailForm) { ctx.ServerError("UpdateEmailAddress failed", err) return } + ctx.Data["Email"] = newEmailAddress + ctx.User.Email = newEmailAddress Activate(ctx) + } // Activate render activate user page diff --git a/templates/user/auth/activate.tmpl b/templates/user/auth/activate.tmpl index db64f7911..b8436e994 100644 --- a/templates/user/auth/activate.tmpl +++ b/templates/user/auth/activate.tmpl @@ -15,7 +15,7 @@ {{else if .ResendLimited}}

{{.i18n.Tr "auth.resent_limit_prompt"}}

{{else}} -

{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .SignedUser.Email .ActiveCodeLives | Str2html}}

+

{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .Email .ActiveCodeLives | Str2html}}

{{end}} {{else}} {{if .IsSendRegisterMail}} From 9911244cccf84f2757b8ab6f217afb22418b25e7 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Fri, 25 Nov 2022 09:28:49 +0800 Subject: [PATCH 6/6] fix issue --- options/locale/locale_en-US.ini | 5 ++++- options/locale/locale_zh-CN.ini | 3 +++ templates/user/auth/activate.tmpl | 10 +++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 9d097eeb0..1e03d5cd3 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -389,9 +389,12 @@ authorize_application_created_by = This application was created by %s. authorize_application_description = If you grant the access, it will be able to access and write to all your account information, including private repos and organisations. authorize_title = Authorize "%s" to access your account? authorization_failed = Authorization failed -authorization_failed_desc = The authorization failed because we detected an invalid request. Please contact the maintainer of the app you've tried to authorize. +authorization_failed_desc = The authorization failed because we detected an invalid request. Please contact the maintainer of the app you have tried to authorize. disable_forgot_password_mail = Account recovery is disabled. Please contact your site administrator. sspi_auth_failed = SSPI authentication failed +change_email = Change email +change_email_address = Change email address +new_email_address = New email address [phone] format_err=The format of phone number is wrong. query_err=Fail to query phone number, please try again later. diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index e2a4bd6c4..b01fbad01 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -396,6 +396,9 @@ authorization_failed=授权失败 authorization_failed_desc=授权失败,这是一个无效的请求。请联系尝试授权应用的管理员。 disable_forgot_password_mail = Account recovery is disabled. Please contact your site administrator. sspi_auth_failed=SSPI 认证失败 +change_email=修改邮箱 +change_email_address=修改邮箱地址 +new_email_address=新邮箱地址 [phone] format_err=手机号格式错误。 query_err=查询手机号失败,请稍后再试。 diff --git a/templates/user/auth/activate.tmpl b/templates/user/auth/activate.tmpl index 9b0aebb4a..bbeba8242 100644 --- a/templates/user/auth/activate.tmpl +++ b/templates/user/auth/activate.tmpl @@ -26,7 +26,7 @@

{{.i18n.Tr "auth.has_unconfirmed_mail" .SignedUser.Name .SignedUser.Email | Str2html}}

- +
{{end}} @@ -38,7 +38,7 @@
- -
取消
+ +
{{.i18n.Tr "cancel"}}