mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
finish all new user settings UI
This commit is contained in:
@@ -132,6 +132,40 @@ func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/settings")
|
||||
}
|
||||
|
||||
func SettingsPassword(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsPassword"] = true
|
||||
ctx.HTML(200, SETTINGS_PASSWORD)
|
||||
}
|
||||
|
||||
func SettingsPasswordPost(ctx *middleware.Context, form auth.ChangePasswordForm) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsPassword"] = true
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, SETTINGS_PASSWORD)
|
||||
return
|
||||
}
|
||||
|
||||
if !ctx.User.ValidatePassword(form.OldPassword) {
|
||||
ctx.Flash.Error(ctx.Tr("settings.password_incorrect"))
|
||||
} else if form.Password != form.Retype {
|
||||
ctx.Flash.Error(ctx.Tr("form.password_not_match"))
|
||||
} else {
|
||||
ctx.User.Passwd = form.Password
|
||||
ctx.User.Salt = models.GetUserSalt()
|
||||
ctx.User.EncodePasswd()
|
||||
if err := models.UpdateUser(ctx.User); err != nil {
|
||||
ctx.Handle(500, "UpdateUser", err)
|
||||
return
|
||||
}
|
||||
log.Trace("User password updated: %s", ctx.User.Name)
|
||||
ctx.Flash.Success(ctx.Tr("settings.change_password_success"))
|
||||
}
|
||||
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/settings/password")
|
||||
}
|
||||
|
||||
func SettingsEmails(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsEmails"] = true
|
||||
@@ -150,6 +184,19 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsEmails"] = true
|
||||
|
||||
// Make emailaddress primary.
|
||||
if ctx.Query("_method") == "PRIMARY" {
|
||||
if err := models.MakeEmailPrimary(&models.EmailAddress{ID: ctx.QueryInt64("id")}); err != nil {
|
||||
ctx.Handle(500, "MakeEmailPrimary", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Trace("Email made primary: %s", ctx.User.Name)
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/settings/email")
|
||||
return
|
||||
}
|
||||
|
||||
// Add Email address.
|
||||
emails, err := models.GetEmailAddresses(ctx.User.Id)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetEmailAddresses", err)
|
||||
@@ -157,51 +204,16 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) {
|
||||
}
|
||||
ctx.Data["Emails"] = emails
|
||||
|
||||
// Delete E-mail address.
|
||||
if ctx.Query("_method") == "DELETE" {
|
||||
id := ctx.QueryInt64("id")
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if err = models.DeleteEmailAddress(&models.EmailAddress{Id: id}); err != nil {
|
||||
ctx.Handle(500, "DeleteEmail", err)
|
||||
} else {
|
||||
log.Trace("Email address deleted: %s", ctx.User.Name)
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/settings/email")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Make emailaddress primary.
|
||||
if ctx.Query("_method") == "PRIMARY" {
|
||||
id := ctx.QueryInt64("id")
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if err = models.MakeEmailPrimary(&models.EmailAddress{Id: id}); err != nil {
|
||||
ctx.Handle(500, "MakeEmailPrimary", err)
|
||||
} else {
|
||||
log.Trace("Email made primary: %s", ctx.User.Name)
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/settings/email")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Add Email address.
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, SETTINGS_EMAILS)
|
||||
return
|
||||
}
|
||||
|
||||
cleanEmail := strings.Replace(form.Email, "\n", "", -1)
|
||||
e := &models.EmailAddress{
|
||||
Uid: ctx.User.Id,
|
||||
Email: cleanEmail,
|
||||
UID: ctx.User.Id,
|
||||
Email: strings.TrimSpace(form.Email),
|
||||
IsActivated: !setting.Service.RegisterEmailConfirm,
|
||||
}
|
||||
|
||||
if err := models.AddEmailAddress(e); err != nil {
|
||||
if models.IsErrEmailAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), SETTINGS_EMAILS, &form)
|
||||
@@ -209,64 +221,35 @@ func SettingsEmailPost(ctx *middleware.Context, form auth.AddEmailForm) {
|
||||
}
|
||||
ctx.Handle(500, "AddEmailAddress", err)
|
||||
return
|
||||
} else {
|
||||
// Send confirmation e-mail
|
||||
if setting.Service.RegisterEmailConfirm {
|
||||
mailer.SendActivateEmail(ctx.Render, ctx.User, e)
|
||||
|
||||
if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
|
||||
log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
|
||||
}
|
||||
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", cleanEmail, setting.Service.ActiveCodeLives/60))
|
||||
} else {
|
||||
ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
|
||||
}
|
||||
|
||||
log.Trace("Email address added: %s", e.Email)
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/settings/email")
|
||||
return
|
||||
}
|
||||
|
||||
ctx.HTML(200, SETTINGS_EMAILS)
|
||||
// Send confirmation e-mail
|
||||
if setting.Service.RegisterEmailConfirm {
|
||||
mailer.SendActivateEmail(ctx.Render, ctx.User, e)
|
||||
|
||||
if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil {
|
||||
log.Error(4, "Set cache(MailResendLimit) fail: %v", err)
|
||||
}
|
||||
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", e.Email, setting.Service.ActiveCodeLives/60))
|
||||
} else {
|
||||
ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
|
||||
}
|
||||
|
||||
log.Trace("Email address added: %s", e.Email)
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/settings/email")
|
||||
}
|
||||
|
||||
func SettingsPassword(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsPassword"] = true
|
||||
ctx.HTML(200, SETTINGS_PASSWORD)
|
||||
}
|
||||
|
||||
func SettingsPasswordPost(ctx *middleware.Context, form auth.ChangePasswordForm) {
|
||||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsPassword"] = true
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, SETTINGS_PASSWORD)
|
||||
func DeleteEmail(ctx *middleware.Context) {
|
||||
if err := models.DeleteEmailAddress(&models.EmailAddress{ID: ctx.QueryInt64("id")}); err != nil {
|
||||
ctx.Handle(500, "DeleteEmail", err)
|
||||
return
|
||||
}
|
||||
log.Trace("Email address deleted: %s", ctx.User.Name)
|
||||
|
||||
tmpUser := &models.User{
|
||||
Passwd: form.OldPassword,
|
||||
Salt: ctx.User.Salt,
|
||||
}
|
||||
tmpUser.EncodePasswd()
|
||||
if ctx.User.Passwd != tmpUser.Passwd {
|
||||
ctx.Flash.Error(ctx.Tr("settings.password_incorrect"))
|
||||
} else if form.Password != form.Retype {
|
||||
ctx.Flash.Error(ctx.Tr("form.password_not_match"))
|
||||
} else {
|
||||
ctx.User.Passwd = form.Password
|
||||
ctx.User.Salt = models.GetUserSalt()
|
||||
ctx.User.EncodePasswd()
|
||||
if err := models.UpdateUser(ctx.User); err != nil {
|
||||
ctx.Handle(500, "UpdateUser", err)
|
||||
return
|
||||
}
|
||||
log.Trace("User password updated: %s", ctx.User.Name)
|
||||
ctx.Flash.Success(ctx.Tr("settings.change_password_success"))
|
||||
}
|
||||
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/settings/password")
|
||||
ctx.Flash.Success(ctx.Tr("settings.email_deletion_success"))
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
"redirect": setting.AppSubUrl + "/user/settings/email",
|
||||
})
|
||||
}
|
||||
|
||||
func SettingsSSHKeys(ctx *middleware.Context) {
|
||||
|
Reference in New Issue
Block a user