Reviewed-on: https://openi.pcl.ac.cn/OpenI/aiforge/pulls/3275 Reviewed-by: zouap <zouap@pcl.ac.cn>tags/v1.22.11.3^2
| @@ -216,6 +216,27 @@ func (email *EmailAddress) updateActivation(e Engine, activate bool) error { | |||||
| return updateUserCols(e, user, "rands") | 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", "avatar_email") | |||||
| } | |||||
| // DeleteEmailAddress deletes an email address of given user. | // DeleteEmailAddress deletes an email address of given user. | ||||
| func DeleteEmailAddress(email *EmailAddress) (err error) { | func DeleteEmailAddress(email *EmailAddress) (err error) { | ||||
| var deleted int64 | var deleted int64 | ||||
| @@ -88,6 +88,10 @@ type RegisterForm struct { | |||||
| Agree bool | Agree bool | ||||
| } | } | ||||
| type UpdateEmailForm struct { | |||||
| NewEmail string `binding:"Required;MaxSize(254)"` | |||||
| } | |||||
| // Validate valideates the fields | // Validate valideates the fields | ||||
| func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { | ||||
| return validate(errs, ctx.Data, f, ctx.Locale) | return validate(errs, ctx.Data, f, ctx.Locale) | ||||
| @@ -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_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? | authorize_title = Authorize "%s" to access your account? | ||||
| authorization_failed = Authorization failed | 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. | disable_forgot_password_mail = Account recovery is disabled. Please contact your site administrator. | ||||
| sspi_auth_failed = SSPI authentication failed | sspi_auth_failed = SSPI authentication failed | ||||
| change_email = Change email | |||||
| change_email_address = Change email address | |||||
| new_email_address = New email address | |||||
| [phone] | [phone] | ||||
| format_err=The format of phone number is wrong. | format_err=The format of phone number is wrong. | ||||
| query_err=Fail to query phone number, please try again later. | query_err=Fail to query phone number, please try again later. | ||||
| @@ -396,6 +396,9 @@ authorization_failed=授权失败 | |||||
| authorization_failed_desc=授权失败,这是一个无效的请求。请联系尝试授权应用的管理员。 | authorization_failed_desc=授权失败,这是一个无效的请求。请联系尝试授权应用的管理员。 | ||||
| disable_forgot_password_mail = Account recovery is disabled. Please contact your site administrator. | disable_forgot_password_mail = Account recovery is disabled. Please contact your site administrator. | ||||
| sspi_auth_failed=SSPI 认证失败 | sspi_auth_failed=SSPI 认证失败 | ||||
| change_email=修改邮箱 | |||||
| change_email_address=修改邮箱地址 | |||||
| new_email_address=新邮箱地址 | |||||
| [phone] | [phone] | ||||
| format_err=手机号格式错误。 | format_err=手机号格式错误。 | ||||
| query_err=查询手机号失败,请稍后再试。 | query_err=查询手机号失败,请稍后再试。 | ||||
| @@ -518,6 +518,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| // r.Get("/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) | // r.Get("/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds) | ||||
| m.Any("/activate", user.Activate, reqSignIn) | m.Any("/activate", user.Activate, reqSignIn) | ||||
| m.Any("/activate_email", user.ActivateEmail) | m.Any("/activate_email", user.ActivateEmail) | ||||
| m.Post("/update_email", bindIgnErr(auth.UpdateEmailForm{}), user.UpdateEmailPost) | |||||
| m.Get("/avatar/:username/:size", user.Avatar) | m.Get("/avatar/:username/:size", user.Avatar) | ||||
| m.Get("/email2user", user.Email2User) | m.Get("/email2user", user.Email2User) | ||||
| m.Get("/recover_account", user.ResetPasswd) | m.Get("/recover_account", user.ResetPasswd) | ||||
| @@ -1413,6 +1413,34 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo | |||||
| handleSignInFull(ctx, u, false, true) | handleSignInFull(ctx, u, false, true) | ||||
| } | } | ||||
| //update user emailAddress | |||||
| func UpdateEmailPost(ctx *context.Context, form auth.UpdateEmailForm) { | |||||
| 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 | |||||
| email, err := models.GetEmailAddressByIDAndEmail(user.ID, user.Email) | |||||
| if err != nil { | |||||
| ctx.ServerError("GetEmailAddressByIDAndEmail failed", err) | |||||
| return | |||||
| } | |||||
| err = email.UpdateEmailAddress(newEmailAddress) | |||||
| if err != nil { | |||||
| ctx.ServerError("UpdateEmailAddress failed", err) | |||||
| return | |||||
| } | |||||
| ctx.Data["Email"] = newEmailAddress | |||||
| ctx.User.Email = newEmailAddress | |||||
| Activate(ctx) | |||||
| } | |||||
| // Activate render activate user page | // Activate render activate user page | ||||
| func Activate(ctx *context.Context) { | func Activate(ctx *context.Context) { | ||||
| code := ctx.Query("code") | code := ctx.Query("code") | ||||
| @@ -15,7 +15,7 @@ | |||||
| {{else if .ResendLimited}} | {{else if .ResendLimited}} | ||||
| <p class="center">{{.i18n.Tr "auth.resent_limit_prompt"}}</p> | <p class="center">{{.i18n.Tr "auth.resent_limit_prompt"}}</p> | ||||
| {{else}} | {{else}} | ||||
| <p>{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .SignedUser.Email .ActiveCodeLives | Str2html}}</p> | |||||
| <p>{{.i18n.Tr "auth.confirmation_mail_sent_prompt" .Email .ActiveCodeLives | Str2html}}</p> | |||||
| {{end}} | {{end}} | ||||
| {{else}} | {{else}} | ||||
| {{if .IsSendRegisterMail}} | {{if .IsSendRegisterMail}} | ||||
| @@ -26,6 +26,7 @@ | |||||
| <p>{{.i18n.Tr "auth.has_unconfirmed_mail" .SignedUser.Name .SignedUser.Email | Str2html}}</p> | <p>{{.i18n.Tr "auth.has_unconfirmed_mail" .SignedUser.Name .SignedUser.Email | Str2html}}</p> | ||||
| <div class="ui divider"></div> | <div class="ui divider"></div> | ||||
| <div class="text right"> | <div class="text right"> | ||||
| <button type="button" class="ui blue button change">{{.i18n.Tr "auth.change_email"}}</button> | |||||
| <button class="ui blue button">{{.i18n.Tr "auth.resend_mail"}}</button> | <button class="ui blue button">{{.i18n.Tr "auth.resend_mail"}}</button> | ||||
| </div> | </div> | ||||
| {{end}} | {{end}} | ||||
| @@ -34,5 +35,32 @@ | |||||
| </form> | </form> | ||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| <div> | |||||
| <div class="ui modal chang-email"> | |||||
| <div class="header" style="padding: 1rem;background-color: rgba(240, 240, 240, 100);"> | |||||
| <h4>{{.i18n.Tr "auth.change_email_address"}}</h4> | |||||
| </div> | |||||
| <form id="formId" action="{{AppSubUrl}}/user/update_email" method="POST" class="ui form"> | |||||
| <div class="content content-padding"> | |||||
| <div class="ui error message"> | |||||
| </div> | |||||
| {{$.CsrfTokenHtml}} | |||||
| <div class="inline required field"> | |||||
| <label>{{.i18n.Tr "auth.new_email_address"}}</label> | |||||
| <input style="width: 80%;" id="label" name="NewEmail" maxlength="255" value="{{.SignedUser.Email}}"> | |||||
| </div> | |||||
| </div> | |||||
| <div class="center actions"> | |||||
| <button class="ui green button">{{.i18n.Tr "repo.confirm_choice"}}</button> | |||||
| <div class="ui deny button">{{.i18n.Tr "cancel"}}</div> | |||||
| </div> | |||||
| </form> | |||||
| </div> | |||||
| </div> | |||||
| </div> | </div> | ||||
| {{template "base/footer" .}} | {{template "base/footer" .}} | ||||
| <script> | |||||
| $('.ui.blue.button.change').on('click',function(){ | |||||
| $('.ui.modal').modal('show') | |||||
| }) | |||||
| </script> | |||||
| @@ -1301,3 +1301,17 @@ i.SUCCEEDED { | |||||
| max-height: 500px; | max-height: 500px; | ||||
| overflow: auto; | 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; | |||||
| } | |||||