Browse Source

Merge pull request 'fix-2775-v1' (#3275) from fix-2775-v1 into V20221130

Reviewed-on: https://openi.pcl.ac.cn/OpenI/aiforge/pulls/3275
Reviewed-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.11.3^2
zouap 3 years ago
parent
commit
0fcc657184
8 changed files with 104 additions and 2 deletions
  1. +21
    -0
      models/user_mail.go
  2. +4
    -0
      modules/auth/user_form.go
  3. +4
    -1
      options/locale/locale_en-US.ini
  4. +3
    -0
      options/locale/locale_zh-CN.ini
  5. +1
    -0
      routers/routes/routes.go
  6. +28
    -0
      routers/user/auth.go
  7. +29
    -1
      templates/user/auth/activate.tmpl
  8. +14
    -0
      web_src/less/openi.less

+ 21
- 0
models/user_mail.go View File

@@ -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", "avatar_email")
}

// DeleteEmailAddress deletes an email address of given user.
func DeleteEmailAddress(email *EmailAddress) (err error) {
var deleted int64


+ 4
- 0
modules/auth/user_form.go View File

@@ -88,6 +88,10 @@ type RegisterForm struct {
Agree bool
}

type UpdateEmailForm struct {
NewEmail string `binding:"Required;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)


+ 4
- 1
options/locale/locale_en-US.ini View File

@@ -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.


+ 3
- 0
options/locale/locale_zh-CN.ini View File

@@ -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=查询手机号失败,请稍后再试。


+ 1
- 0
routers/routes/routes.go View File

@@ -518,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", bindIgnErr(auth.UpdateEmailForm{}), user.UpdateEmailPost)
m.Get("/avatar/:username/:size", user.Avatar)
m.Get("/email2user", user.Email2User)
m.Get("/recover_account", user.ResetPasswd)


+ 28
- 0
routers/user/auth.go View File

@@ -1413,6 +1413,34 @@ 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 := 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
func Activate(ctx *context.Context) {
code := ctx.Query("code")


+ 29
- 1
templates/user/auth/activate.tmpl View File

@@ -15,7 +15,7 @@
{{else if .ResendLimited}}
<p class="center">{{.i18n.Tr "auth.resent_limit_prompt"}}</p>
{{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}}
{{else}}
{{if .IsSendRegisterMail}}
@@ -26,6 +26,7 @@
<p>{{.i18n.Tr "auth.has_unconfirmed_mail" .SignedUser.Name .SignedUser.Email | Str2html}}</p>
<div class="ui divider"></div>
<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>
</div>
{{end}}
@@ -34,5 +35,32 @@
</form>
</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>
{{template "base/footer" .}}
<script>
$('.ui.blue.button.change').on('click',function(){
$('.ui.modal').modal('show')
})
</script>

+ 14
- 0
web_src/less/openi.less View File

@@ -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;
}

Loading…
Cancel
Save