diff options
Diffstat (limited to 'routers/web/user/setting')
-rw-r--r-- | routers/web/user/setting/account.go | 62 | ||||
-rw-r--r-- | routers/web/user/setting/adopt.go | 2 | ||||
-rw-r--r-- | routers/web/user/setting/applications.go | 10 | ||||
-rw-r--r-- | routers/web/user/setting/keys.go | 44 | ||||
-rw-r--r-- | routers/web/user/setting/oauth2.go | 16 | ||||
-rw-r--r-- | routers/web/user/setting/profile.go | 60 | ||||
-rw-r--r-- | routers/web/user/setting/security/2fa.go | 16 | ||||
-rw-r--r-- | routers/web/user/setting/security/openid.go | 10 | ||||
-rw-r--r-- | routers/web/user/setting/security/security.go | 12 | ||||
-rw-r--r-- | routers/web/user/setting/security/webauthn.go | 12 |
10 files changed, 122 insertions, 122 deletions
diff --git a/routers/web/user/setting/account.go b/routers/web/user/setting/account.go index 492b4f82c8..468d5ca651 100644 --- a/routers/web/user/setting/account.go +++ b/routers/web/user/setting/account.go @@ -34,7 +34,7 @@ const ( func Account(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsSettingsAccount"] = true - ctx.Data["Email"] = ctx.User.Email + ctx.Data["Email"] = ctx.Doer.Email loadAccountData(ctx) @@ -56,7 +56,7 @@ func AccountPost(ctx *context.Context) { if len(form.Password) < setting.MinPasswordLength { ctx.Flash.Error(ctx.Tr("auth.password_too_short", setting.MinPasswordLength)) - } else if ctx.User.IsPasswordSet() && !ctx.User.ValidatePassword(form.OldPassword) { + } else if ctx.Doer.IsPasswordSet() && !ctx.Doer.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")) @@ -71,15 +71,15 @@ func AccountPost(ctx *context.Context) { ctx.Flash.Error(errMsg) } else { var err error - if err = ctx.User.SetPassword(form.Password); err != nil { + if err = ctx.Doer.SetPassword(form.Password); err != nil { ctx.ServerError("UpdateUser", err) return } - if err := user_model.UpdateUserCols(db.DefaultContext, ctx.User, "salt", "passwd_hash_algo", "passwd"); err != nil { + if err := user_model.UpdateUserCols(db.DefaultContext, ctx.Doer, "salt", "passwd_hash_algo", "passwd"); err != nil { ctx.ServerError("UpdateUser", err) return } - log.Trace("User password updated: %s", ctx.User.Name) + log.Trace("User password updated: %s", ctx.Doer.Name) ctx.Flash.Success(ctx.Tr("settings.change_password_success")) } @@ -99,50 +99,50 @@ func EmailPost(ctx *context.Context) { return } - log.Trace("Email made primary: %s", ctx.User.Name) + log.Trace("Email made primary: %s", ctx.Doer.Name) ctx.Redirect(setting.AppSubURL + "/user/settings/account") return } // Send activation Email if ctx.FormString("_method") == "SENDACTIVATION" { var address string - if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) { + if ctx.Cache.IsExist("MailResendLimit_" + ctx.Doer.LowerName) { log.Error("Send activation: activation still pending") ctx.Redirect(setting.AppSubURL + "/user/settings/account") return } id := ctx.FormInt64("id") - email, err := user_model.GetEmailAddressByID(ctx.User.ID, id) + email, err := user_model.GetEmailAddressByID(ctx.Doer.ID, id) if err != nil { - log.Error("GetEmailAddressByID(%d,%d) error: %v", ctx.User.ID, id, err) + log.Error("GetEmailAddressByID(%d,%d) error: %v", ctx.Doer.ID, id, err) ctx.Redirect(setting.AppSubURL + "/user/settings/account") return } if email == nil { - log.Warn("Send activation failed: EmailAddress[%d] not found for user: %-v", id, ctx.User) + log.Warn("Send activation failed: EmailAddress[%d] not found for user: %-v", id, ctx.Doer) ctx.Redirect(setting.AppSubURL + "/user/settings/account") return } if email.IsActivated { - log.Debug("Send activation failed: email %s is already activated for user: %-v", email.Email, ctx.User) + log.Debug("Send activation failed: email %s is already activated for user: %-v", email.Email, ctx.Doer) ctx.Redirect(setting.AppSubURL + "/user/settings/account") return } if email.IsPrimary { - if ctx.User.IsActive && !setting.Service.RegisterEmailConfirm { - log.Debug("Send activation failed: email %s is already activated for user: %-v", email.Email, ctx.User) + if ctx.Doer.IsActive && !setting.Service.RegisterEmailConfirm { + log.Debug("Send activation failed: email %s is already activated for user: %-v", email.Email, ctx.Doer) ctx.Redirect(setting.AppSubURL + "/user/settings/account") return } // Only fired when the primary email is inactive (Wrong state) - mailer.SendActivateAccountMail(ctx.Locale, ctx.User) + mailer.SendActivateAccountMail(ctx.Locale, ctx.Doer) } else { - mailer.SendActivateEmailMail(ctx.User, email) + mailer.SendActivateEmailMail(ctx.Doer, email) } address = email.Email - if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil { + if err := ctx.Cache.Put("MailResendLimit_"+ctx.Doer.LowerName, ctx.Doer.LowerName, 180); err != nil { log.Error("Set cache(MailResendLimit) fail: %v", err) } ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", address, timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()))) @@ -155,16 +155,16 @@ func EmailPost(ctx *context.Context) { if !(preference == user_model.EmailNotificationsEnabled || preference == user_model.EmailNotificationsOnMention || preference == user_model.EmailNotificationsDisabled) { - log.Error("Email notifications preference change returned unrecognized option %s: %s", preference, ctx.User.Name) + log.Error("Email notifications preference change returned unrecognized option %s: %s", preference, ctx.Doer.Name) ctx.ServerError("SetEmailPreference", errors.New("option unrecognized")) return } - if err := user_model.SetEmailNotifications(ctx.User, preference); err != nil { + if err := user_model.SetEmailNotifications(ctx.Doer, preference); err != nil { log.Error("Set Email Notifications failed: %v", err) ctx.ServerError("SetEmailNotifications", err) return } - log.Trace("Email notifications preference made %s: %s", preference, ctx.User.Name) + log.Trace("Email notifications preference made %s: %s", preference, ctx.Doer.Name) ctx.Flash.Success(ctx.Tr("settings.email_preference_set_success")) ctx.Redirect(setting.AppSubURL + "/user/settings/account") return @@ -178,7 +178,7 @@ func EmailPost(ctx *context.Context) { } email := &user_model.EmailAddress{ - UID: ctx.User.ID, + UID: ctx.Doer.ID, Email: form.Email, IsActivated: !setting.Service.RegisterEmailConfirm, } @@ -201,8 +201,8 @@ func EmailPost(ctx *context.Context) { // Send confirmation email if setting.Service.RegisterEmailConfirm { - mailer.SendActivateEmailMail(ctx.User, email) - if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil { + mailer.SendActivateEmailMail(ctx.Doer, email) + if err := ctx.Cache.Put("MailResendLimit_"+ctx.Doer.LowerName, ctx.Doer.LowerName, 180); err != nil { log.Error("Set cache(MailResendLimit) fail: %v", err) } ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", email.Email, timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()))) @@ -216,11 +216,11 @@ func EmailPost(ctx *context.Context) { // DeleteEmail response for delete user's email func DeleteEmail(ctx *context.Context) { - if err := user_model.DeleteEmailAddress(&user_model.EmailAddress{ID: ctx.FormInt64("id"), UID: ctx.User.ID}); err != nil { + if err := user_model.DeleteEmailAddress(&user_model.EmailAddress{ID: ctx.FormInt64("id"), UID: ctx.Doer.ID}); err != nil { ctx.ServerError("DeleteEmail", err) return } - log.Trace("Email address deleted: %s", ctx.User.Name) + log.Trace("Email address deleted: %s", ctx.Doer.Name) ctx.Flash.Success(ctx.Tr("settings.email_deletion_success")) ctx.JSON(http.StatusOK, map[string]interface{}{ @@ -233,7 +233,7 @@ func DeleteAccount(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsSettingsAccount"] = true - if _, _, err := auth.UserSignIn(ctx.User.Name, ctx.FormString("password")); err != nil { + if _, _, err := auth.UserSignIn(ctx.Doer.Name, ctx.FormString("password")); err != nil { if user_model.IsErrUserNotExist(err) { loadAccountData(ctx) @@ -244,7 +244,7 @@ func DeleteAccount(ctx *context.Context) { return } - if err := user.DeleteUser(ctx.User); err != nil { + if err := user.DeleteUser(ctx.Doer); err != nil { switch { case models.IsErrUserOwnRepos(err): ctx.Flash.Error(ctx.Tr("form.still_own_repo")) @@ -256,13 +256,13 @@ func DeleteAccount(ctx *context.Context) { ctx.ServerError("DeleteUser", err) } } else { - log.Trace("Account deleted: %s", ctx.User.Name) + log.Trace("Account deleted: %s", ctx.Doer.Name) ctx.Redirect(setting.AppSubURL + "/") } } func loadAccountData(ctx *context.Context) { - emlist, err := user_model.GetEmailAddresses(ctx.User.ID) + emlist, err := user_model.GetEmailAddresses(ctx.Doer.ID) if err != nil { ctx.ServerError("GetEmailAddresses", err) return @@ -271,7 +271,7 @@ func loadAccountData(ctx *context.Context) { user_model.EmailAddress CanBePrimary bool } - pendingActivation := ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) + pendingActivation := ctx.Cache.IsExist("MailResendLimit_" + ctx.Doer.LowerName) emails := make([]*UserEmail, len(emlist)) for i, em := range emlist { var email UserEmail @@ -280,12 +280,12 @@ func loadAccountData(ctx *context.Context) { emails[i] = &email } ctx.Data["Emails"] = emails - ctx.Data["EmailNotificationsPreference"] = ctx.User.EmailNotifications() + ctx.Data["EmailNotificationsPreference"] = ctx.Doer.EmailNotifications() ctx.Data["ActivationsPending"] = pendingActivation ctx.Data["CanAddEmails"] = !pendingActivation || !setting.Service.RegisterEmailConfirm if setting.Service.UserDeleteWithCommentsMaxTime != 0 { ctx.Data["UserDeleteWithCommentsMaxTime"] = setting.Service.UserDeleteWithCommentsMaxTime.String() - ctx.Data["UserDeleteWithComments"] = ctx.User.CreatedUnix.AsTime().Add(setting.Service.UserDeleteWithCommentsMaxTime).After(time.Now()) + ctx.Data["UserDeleteWithComments"] = ctx.Doer.CreatedUnix.AsTime().Add(setting.Service.UserDeleteWithCommentsMaxTime).After(time.Now()) } } diff --git a/routers/web/user/setting/adopt.go b/routers/web/user/setting/adopt.go index 348705b743..ce2377a997 100644 --- a/routers/web/user/setting/adopt.go +++ b/routers/web/user/setting/adopt.go @@ -28,7 +28,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) { dir := ctx.FormString("id") action := ctx.FormString("action") - ctxUser := ctx.User + ctxUser := ctx.Doer root := user_model.UserPath(ctxUser.LowerName) // check not a repo diff --git a/routers/web/user/setting/applications.go b/routers/web/user/setting/applications.go index 20ffdfaf84..b0f599fc45 100644 --- a/routers/web/user/setting/applications.go +++ b/routers/web/user/setting/applications.go @@ -45,7 +45,7 @@ func ApplicationsPost(ctx *context.Context) { } t := &models.AccessToken{ - UID: ctx.User.ID, + UID: ctx.Doer.ID, Name: form.Name, } @@ -73,7 +73,7 @@ func ApplicationsPost(ctx *context.Context) { // DeleteApplication response for delete user access token func DeleteApplication(ctx *context.Context) { - if err := models.DeleteAccessTokenByID(ctx.FormInt64("id"), ctx.User.ID); err != nil { + if err := models.DeleteAccessTokenByID(ctx.FormInt64("id"), ctx.Doer.ID); err != nil { ctx.Flash.Error("DeleteAccessTokenByID: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("settings.delete_token_success")) @@ -85,7 +85,7 @@ func DeleteApplication(ctx *context.Context) { } func loadApplicationsData(ctx *context.Context) { - tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{UserID: ctx.User.ID}) + tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{UserID: ctx.Doer.ID}) if err != nil { ctx.ServerError("ListAccessTokens", err) return @@ -93,12 +93,12 @@ func loadApplicationsData(ctx *context.Context) { ctx.Data["Tokens"] = tokens ctx.Data["EnableOAuth2"] = setting.OAuth2.Enable if setting.OAuth2.Enable { - ctx.Data["Applications"], err = auth.GetOAuth2ApplicationsByUserID(ctx.User.ID) + ctx.Data["Applications"], err = auth.GetOAuth2ApplicationsByUserID(ctx.Doer.ID) if err != nil { ctx.ServerError("GetOAuth2ApplicationsByUserID", err) return } - ctx.Data["Grants"], err = auth.GetOAuth2GrantsByUserID(ctx.User.ID) + ctx.Data["Grants"], err = auth.GetOAuth2GrantsByUserID(ctx.Doer.ID) if err != nil { ctx.ServerError("GetOAuth2GrantsByUserID", err) return diff --git a/routers/web/user/setting/keys.go b/routers/web/user/setting/keys.go index f926c1f311..2cc627ecde 100644 --- a/routers/web/user/setting/keys.go +++ b/routers/web/user/setting/keys.go @@ -52,7 +52,7 @@ func KeysPost(ctx *context.Context) { } switch form.Type { case "principal": - content, err := asymkey_model.CheckPrincipalKeyString(ctx.User, form.Content) + content, err := asymkey_model.CheckPrincipalKeyString(ctx.Doer, form.Content) if err != nil { if db.IsErrSSHDisabled(err) { ctx.Flash.Info(ctx.Tr("settings.ssh_disabled")) @@ -62,7 +62,7 @@ func KeysPost(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/user/settings/keys") return } - if _, err = asymkey_model.AddPrincipalKey(ctx.User.ID, content, 0); err != nil { + if _, err = asymkey_model.AddPrincipalKey(ctx.Doer.ID, content, 0); err != nil { ctx.Data["HasPrincipalError"] = true switch { case asymkey_model.IsErrKeyAlreadyExist(err), asymkey_model.IsErrKeyNameAlreadyUsed(err): @@ -78,12 +78,12 @@ func KeysPost(ctx *context.Context) { ctx.Flash.Success(ctx.Tr("settings.add_principal_success", form.Content)) ctx.Redirect(setting.AppSubURL + "/user/settings/keys") case "gpg": - token := asymkey_model.VerificationToken(ctx.User, 1) - lastToken := asymkey_model.VerificationToken(ctx.User, 0) + token := asymkey_model.VerificationToken(ctx.Doer, 1) + lastToken := asymkey_model.VerificationToken(ctx.Doer, 0) - keys, err := asymkey_model.AddGPGKey(ctx.User.ID, form.Content, token, form.Signature) + keys, err := asymkey_model.AddGPGKey(ctx.Doer.ID, form.Content, token, form.Signature) if err != nil && asymkey_model.IsErrGPGInvalidTokenSignature(err) { - keys, err = asymkey_model.AddGPGKey(ctx.User.ID, form.Content, lastToken, form.Signature) + keys, err = asymkey_model.AddGPGKey(ctx.Doer.ID, form.Content, lastToken, form.Signature) } if err != nil { ctx.Data["HasGPGError"] = true @@ -125,12 +125,12 @@ func KeysPost(ctx *context.Context) { ctx.Flash.Success(ctx.Tr("settings.add_gpg_key_success", keyIDs)) ctx.Redirect(setting.AppSubURL + "/user/settings/keys") case "verify_gpg": - token := asymkey_model.VerificationToken(ctx.User, 1) - lastToken := asymkey_model.VerificationToken(ctx.User, 0) + token := asymkey_model.VerificationToken(ctx.Doer, 1) + lastToken := asymkey_model.VerificationToken(ctx.Doer, 0) - keyID, err := asymkey_model.VerifyGPGKey(ctx.User.ID, form.KeyID, token, form.Signature) + keyID, err := asymkey_model.VerifyGPGKey(ctx.Doer.ID, form.KeyID, token, form.Signature) if err != nil && asymkey_model.IsErrGPGInvalidTokenSignature(err) { - keyID, err = asymkey_model.VerifyGPGKey(ctx.User.ID, form.KeyID, lastToken, form.Signature) + keyID, err = asymkey_model.VerifyGPGKey(ctx.Doer.ID, form.KeyID, lastToken, form.Signature) } if err != nil { ctx.Data["HasGPGVerifyError"] = true @@ -161,7 +161,7 @@ func KeysPost(ctx *context.Context) { return } - if _, err = asymkey_model.AddPublicKey(ctx.User.ID, form.Title, content, 0); err != nil { + if _, err = asymkey_model.AddPublicKey(ctx.Doer.ID, form.Title, content, 0); err != nil { ctx.Data["HasSSHError"] = true switch { case asymkey_model.IsErrKeyAlreadyExist(err): @@ -185,12 +185,12 @@ func KeysPost(ctx *context.Context) { ctx.Flash.Success(ctx.Tr("settings.add_key_success", form.Title)) ctx.Redirect(setting.AppSubURL + "/user/settings/keys") case "verify_ssh": - token := asymkey_model.VerificationToken(ctx.User, 1) - lastToken := asymkey_model.VerificationToken(ctx.User, 0) + token := asymkey_model.VerificationToken(ctx.Doer, 1) + lastToken := asymkey_model.VerificationToken(ctx.Doer, 0) - fingerprint, err := asymkey_model.VerifySSHKey(ctx.User.ID, form.Fingerprint, token, form.Signature) + fingerprint, err := asymkey_model.VerifySSHKey(ctx.Doer.ID, form.Fingerprint, token, form.Signature) if err != nil && asymkey_model.IsErrSSHInvalidTokenSignature(err) { - fingerprint, err = asymkey_model.VerifySSHKey(ctx.User.ID, form.Fingerprint, lastToken, form.Signature) + fingerprint, err = asymkey_model.VerifySSHKey(ctx.Doer.ID, form.Fingerprint, lastToken, form.Signature) } if err != nil { ctx.Data["HasSSHVerifyError"] = true @@ -217,7 +217,7 @@ func KeysPost(ctx *context.Context) { func DeleteKey(ctx *context.Context) { switch ctx.FormString("type") { case "gpg": - if err := asymkey_model.DeleteGPGKey(ctx.User, ctx.FormInt64("id")); err != nil { + if err := asymkey_model.DeleteGPGKey(ctx.Doer, ctx.FormInt64("id")); err != nil { ctx.Flash.Error("DeleteGPGKey: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("settings.gpg_key_deletion_success")) @@ -234,13 +234,13 @@ func DeleteKey(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/user/settings/keys") return } - if err := asymkey_service.DeletePublicKey(ctx.User, keyID); err != nil { + if err := asymkey_service.DeletePublicKey(ctx.Doer, keyID); err != nil { ctx.Flash.Error("DeletePublicKey: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("settings.ssh_key_deletion_success")) } case "principal": - if err := asymkey_service.DeletePublicKey(ctx.User, ctx.FormInt64("id")); err != nil { + if err := asymkey_service.DeletePublicKey(ctx.Doer, ctx.FormInt64("id")); err != nil { ctx.Flash.Error("DeletePublicKey: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("settings.ssh_principal_deletion_success")) @@ -255,7 +255,7 @@ func DeleteKey(ctx *context.Context) { } func loadKeysData(ctx *context.Context) { - keys, err := asymkey_model.ListPublicKeys(ctx.User.ID, db.ListOptions{}) + keys, err := asymkey_model.ListPublicKeys(ctx.Doer.ID, db.ListOptions{}) if err != nil { ctx.ServerError("ListPublicKeys", err) return @@ -269,18 +269,18 @@ func loadKeysData(ctx *context.Context) { } ctx.Data["ExternalKeys"] = externalKeys - gpgkeys, err := asymkey_model.ListGPGKeys(db.DefaultContext, ctx.User.ID, db.ListOptions{}) + gpgkeys, err := asymkey_model.ListGPGKeys(db.DefaultContext, ctx.Doer.ID, db.ListOptions{}) if err != nil { ctx.ServerError("ListGPGKeys", err) return } ctx.Data["GPGKeys"] = gpgkeys - tokenToSign := asymkey_model.VerificationToken(ctx.User, 1) + tokenToSign := asymkey_model.VerificationToken(ctx.Doer, 1) // generate a new aes cipher using the csrfToken ctx.Data["TokenToSign"] = tokenToSign - principals, err := asymkey_model.ListPrincipalKeys(ctx.User.ID, db.ListOptions{}) + principals, err := asymkey_model.ListPrincipalKeys(ctx.Doer.ID, db.ListOptions{}) if err != nil { ctx.ServerError("ListPrincipalKeys", err) return diff --git a/routers/web/user/setting/oauth2.go b/routers/web/user/setting/oauth2.go index 65d0924da0..76c50852a0 100644 --- a/routers/web/user/setting/oauth2.go +++ b/routers/web/user/setting/oauth2.go @@ -37,7 +37,7 @@ func OAuthApplicationsPost(ctx *context.Context) { app, err := auth.CreateOAuth2Application(auth.CreateOAuth2ApplicationOptions{ Name: form.Name, RedirectURIs: []string{form.RedirectURI}, - UserID: ctx.User.ID, + UserID: ctx.Doer.ID, }) if err != nil { ctx.ServerError("CreateOAuth2Application", err) @@ -71,7 +71,7 @@ func OAuthApplicationsEdit(ctx *context.Context) { ID: ctx.ParamsInt64("id"), Name: form.Name, RedirectURIs: []string{form.RedirectURI}, - UserID: ctx.User.ID, + UserID: ctx.Doer.ID, }); err != nil { ctx.ServerError("UpdateOAuth2Application", err) return @@ -94,7 +94,7 @@ func OAuthApplicationsRegenerateSecret(ctx *context.Context) { ctx.ServerError("GetOAuth2ApplicationByID", err) return } - if app.UID != ctx.User.ID { + if app.UID != ctx.Doer.ID { ctx.NotFound("Application not found", nil) return } @@ -119,7 +119,7 @@ func OAuth2ApplicationShow(ctx *context.Context) { ctx.ServerError("GetOAuth2ApplicationByID", err) return } - if app.UID != ctx.User.ID { + if app.UID != ctx.Doer.ID { ctx.NotFound("Application not found", nil) return } @@ -129,11 +129,11 @@ func OAuth2ApplicationShow(ctx *context.Context) { // DeleteOAuth2Application deletes the given oauth2 application func DeleteOAuth2Application(ctx *context.Context) { - if err := auth.DeleteOAuth2Application(ctx.FormInt64("id"), ctx.User.ID); err != nil { + if err := auth.DeleteOAuth2Application(ctx.FormInt64("id"), ctx.Doer.ID); err != nil { ctx.ServerError("DeleteOAuth2Application", err) return } - log.Trace("OAuth2 Application deleted: %s", ctx.User.Name) + log.Trace("OAuth2 Application deleted: %s", ctx.Doer.Name) ctx.Flash.Success(ctx.Tr("settings.remove_oauth2_application_success")) ctx.JSON(http.StatusOK, map[string]interface{}{ @@ -143,11 +143,11 @@ func DeleteOAuth2Application(ctx *context.Context) { // RevokeOAuth2Grant revokes the grant with the given id func RevokeOAuth2Grant(ctx *context.Context) { - if ctx.User.ID == 0 || ctx.FormInt64("id") == 0 { + if ctx.Doer.ID == 0 || ctx.FormInt64("id") == 0 { ctx.ServerError("RevokeOAuth2Grant", fmt.Errorf("user id or grant id is zero")) return } - if err := auth.RevokeOAuth2Grant(ctx.FormInt64("id"), ctx.User.ID); err != nil { + if err := auth.RevokeOAuth2Grant(ctx.FormInt64("id"), ctx.Doer.ID); err != nil { ctx.ServerError("RevokeOAuth2Grant", err) return } diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index e77e02348c..72cbf33e5f 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -106,24 +106,24 @@ func ProfilePost(ctx *context.Context) { return } - if len(form.Name) != 0 && ctx.User.Name != form.Name { - log.Debug("Changing name for %s to %s", ctx.User.Name, form.Name) - if err := HandleUsernameChange(ctx, ctx.User, form.Name); err != nil { + if len(form.Name) != 0 && ctx.Doer.Name != form.Name { + log.Debug("Changing name for %s to %s", ctx.Doer.Name, form.Name) + if err := HandleUsernameChange(ctx, ctx.Doer, form.Name); err != nil { ctx.Redirect(setting.AppSubURL + "/user/settings") return } - ctx.User.Name = form.Name - ctx.User.LowerName = strings.ToLower(form.Name) + ctx.Doer.Name = form.Name + ctx.Doer.LowerName = strings.ToLower(form.Name) } - ctx.User.FullName = form.FullName - ctx.User.KeepEmailPrivate = form.KeepEmailPrivate - ctx.User.Website = form.Website - ctx.User.Location = form.Location - ctx.User.Description = form.Description - ctx.User.KeepActivityPrivate = form.KeepActivityPrivate - ctx.User.Visibility = form.Visibility - if err := user_model.UpdateUserSetting(ctx.User); err != nil { + ctx.Doer.FullName = form.FullName + ctx.Doer.KeepEmailPrivate = form.KeepEmailPrivate + ctx.Doer.Website = form.Website + ctx.Doer.Location = form.Location + ctx.Doer.Description = form.Description + ctx.Doer.KeepActivityPrivate = form.KeepActivityPrivate + ctx.Doer.Visibility = form.Visibility + if err := user_model.UpdateUserSetting(ctx.Doer); err != nil { if _, ok := err.(user_model.ErrEmailAlreadyUsed); ok { ctx.Flash.Error(ctx.Tr("form.email_been_used")) ctx.Redirect(setting.AppSubURL + "/user/settings") @@ -134,10 +134,10 @@ func ProfilePost(ctx *context.Context) { } // Update the language to the one we just set - middleware.SetLocaleCookie(ctx.Resp, ctx.User.Language, 0) + middleware.SetLocaleCookie(ctx.Resp, ctx.Doer.Language, 0) - log.Trace("User settings updated: %s", ctx.User.Name) - ctx.Flash.Success(i18n.Tr(ctx.User.Language, "settings.update_profile_success")) + log.Trace("User settings updated: %s", ctx.Doer.Name) + ctx.Flash.Success(i18n.Tr(ctx.Doer.Language, "settings.update_profile_success")) ctx.Redirect(setting.AppSubURL + "/user/settings") } @@ -195,7 +195,7 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser * // AvatarPost response for change user's avatar request func AvatarPost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.AvatarForm) - if err := UpdateAvatarSetting(ctx, form, ctx.User); err != nil { + if err := UpdateAvatarSetting(ctx, form, ctx.Doer); err != nil { ctx.Flash.Error(err.Error()) } else { ctx.Flash.Success(ctx.Tr("settings.update_avatar_success")) @@ -206,7 +206,7 @@ func AvatarPost(ctx *context.Context) { // DeleteAvatar render delete avatar page func DeleteAvatar(ctx *context.Context) { - if err := user_service.DeleteAvatar(ctx.User); err != nil { + if err := user_service.DeleteAvatar(ctx.Doer); err != nil { ctx.Flash.Error(err.Error()) } @@ -223,7 +223,7 @@ func Organization(ctx *context.Context) { PageSize: setting.UI.Admin.UserPagingNum, Page: ctx.FormInt("page"), }, - UserID: ctx.User.ID, + UserID: ctx.Doer.ID, IncludePrivate: ctx.IsSigned, } @@ -268,7 +268,7 @@ func Repos(ctx *context.Context) { adoptOrDelete := ctx.IsUserSiteAdmin() || (setting.Repository.AllowAdoptionOfUnadoptedRepositories && setting.Repository.AllowDeleteOfUnadoptedRepositories) - ctxUser := ctx.User + ctxUser := ctx.Doer count := 0 if adoptOrDelete { @@ -360,7 +360,7 @@ func Appearance(ctx *context.Context) { ctx.Data["PageIsSettingsAppearance"] = true var hiddenCommentTypes *big.Int - val, err := user_model.GetUserSetting(ctx.User.ID, user_model.SettingsKeyHiddenCommentTypes) + val, err := user_model.GetUserSetting(ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes) if err != nil { ctx.ServerError("GetUserSetting", err) return @@ -391,13 +391,13 @@ func UpdateUIThemePost(ctx *context.Context) { return } - if err := user_model.UpdateUserTheme(ctx.User, form.Theme); err != nil { + if err := user_model.UpdateUserTheme(ctx.Doer, form.Theme); err != nil { ctx.Flash.Error(ctx.Tr("settings.theme_update_error")) ctx.Redirect(setting.AppSubURL + "/user/settings/appearance") return } - log.Trace("Update user theme: %s", ctx.User.Name) + log.Trace("Update user theme: %s", ctx.Doer.Name) ctx.Flash.Success(ctx.Tr("settings.theme_update_success")) ctx.Redirect(setting.AppSubURL + "/user/settings/appearance") } @@ -414,31 +414,31 @@ func UpdateUserLang(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/user/settings/appearance") return } - ctx.User.Language = form.Language + ctx.Doer.Language = form.Language } - if err := user_model.UpdateUserSetting(ctx.User); err != nil { + if err := user_model.UpdateUserSetting(ctx.Doer); err != nil { ctx.ServerError("UpdateUserSetting", err) return } // Update the language to the one we just set - middleware.SetLocaleCookie(ctx.Resp, ctx.User.Language, 0) + middleware.SetLocaleCookie(ctx.Resp, ctx.Doer.Language, 0) - log.Trace("User settings updated: %s", ctx.User.Name) - ctx.Flash.Success(i18n.Tr(ctx.User.Language, "settings.update_language_success")) + log.Trace("User settings updated: %s", ctx.Doer.Name) + ctx.Flash.Success(i18n.Tr(ctx.Doer.Language, "settings.update_language_success")) ctx.Redirect(setting.AppSubURL + "/user/settings/appearance") } // UpdateUserHiddenComments update a user's shown comment types func UpdateUserHiddenComments(ctx *context.Context) { - err := user_model.SetUserSetting(ctx.User.ID, user_model.SettingsKeyHiddenCommentTypes, forms.UserHiddenCommentTypesFromRequest(ctx).String()) + err := user_model.SetUserSetting(ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes, forms.UserHiddenCommentTypesFromRequest(ctx).String()) if err != nil { ctx.ServerError("SetUserSetting", err) return } - log.Trace("User settings updated: %s", ctx.User.Name) + log.Trace("User settings updated: %s", ctx.Doer.Name) ctx.Flash.Success(ctx.Tr("settings.saved_successfully")) ctx.Redirect(setting.AppSubURL + "/user/settings/appearance") } diff --git a/routers/web/user/setting/security/2fa.go b/routers/web/user/setting/security/2fa.go index 98e1f9b083..5fd81bae41 100644 --- a/routers/web/user/setting/security/2fa.go +++ b/routers/web/user/setting/security/2fa.go @@ -29,7 +29,7 @@ func RegenerateScratchTwoFactor(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsSettingsSecurity"] = true - t, err := auth.GetTwoFactorByUID(ctx.User.ID) + t, err := auth.GetTwoFactorByUID(ctx.Doer.ID) if err != nil { if auth.IsErrTwoFactorNotEnrolled(err) { ctx.Flash.Error(ctx.Tr("settings.twofa_not_enrolled")) @@ -59,7 +59,7 @@ func DisableTwoFactor(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsSettingsSecurity"] = true - t, err := auth.GetTwoFactorByUID(ctx.User.ID) + t, err := auth.GetTwoFactorByUID(ctx.Doer.ID) if err != nil { if auth.IsErrTwoFactorNotEnrolled(err) { ctx.Flash.Error(ctx.Tr("settings.twofa_not_enrolled")) @@ -69,7 +69,7 @@ func DisableTwoFactor(ctx *context.Context) { return } - if err = auth.DeleteTwoFactorByID(t.ID, ctx.User.ID); err != nil { + if err = auth.DeleteTwoFactorByID(t.ID, ctx.Doer.ID); err != nil { if auth.IsErrTwoFactorNotEnrolled(err) { // There is a potential DB race here - we must have been disabled by another request in the intervening period ctx.Flash.Success(ctx.Tr("settings.twofa_disabled")) @@ -100,7 +100,7 @@ func twofaGenerateSecretAndQr(ctx *context.Context) bool { otpKey, err = totp.Generate(totp.GenerateOpts{ SecretSize: 40, Issuer: issuer, - AccountName: ctx.User.Name, + AccountName: ctx.Doer.Name, }) if err != nil { ctx.ServerError("SettingsTwoFactor: totpGenerate Failed", err) @@ -146,10 +146,10 @@ func EnrollTwoFactor(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsSettingsSecurity"] = true - t, err := auth.GetTwoFactorByUID(ctx.User.ID) + t, err := auth.GetTwoFactorByUID(ctx.Doer.ID) if t != nil { // already enrolled - we should redirect back! - log.Warn("Trying to re-enroll %-v in twofa when already enrolled", ctx.User) + log.Warn("Trying to re-enroll %-v in twofa when already enrolled", ctx.Doer) ctx.Flash.Error(ctx.Tr("settings.twofa_is_enrolled")) ctx.Redirect(setting.AppSubURL + "/user/settings/security") return @@ -172,7 +172,7 @@ func EnrollTwoFactorPost(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsSettingsSecurity"] = true - t, err := auth.GetTwoFactorByUID(ctx.User.ID) + t, err := auth.GetTwoFactorByUID(ctx.Doer.ID) if t != nil { // already enrolled ctx.Flash.Error(ctx.Tr("settings.twofa_is_enrolled")) @@ -210,7 +210,7 @@ func EnrollTwoFactorPost(ctx *context.Context) { } t = &auth.TwoFactor{ - UID: ctx.User.ID, + UID: ctx.Doer.ID, } err = t.SetSecret(secret) if err != nil { diff --git a/routers/web/user/setting/security/openid.go b/routers/web/user/setting/security/openid.go index 1a15a2414c..2ecc9b0533 100644 --- a/routers/web/user/setting/security/openid.go +++ b/routers/web/user/setting/security/openid.go @@ -45,7 +45,7 @@ func OpenIDPost(ctx *context.Context) { form.Openid = id log.Trace("Normalized id: " + id) - oids, err := user_model.GetUserOpenIDs(ctx.User.ID) + oids, err := user_model.GetUserOpenIDs(ctx.Doer.ID) if err != nil { ctx.ServerError("GetUserOpenIDs", err) return @@ -89,7 +89,7 @@ func settingsOpenIDVerify(ctx *context.Context) { log.Trace("Verified ID: " + id) - oid := &user_model.UserOpenID{UID: ctx.User.ID, URI: id} + oid := &user_model.UserOpenID{UID: ctx.Doer.ID, URI: id} if err = user_model.AddUserOpenID(oid); err != nil { if user_model.IsErrOpenIDAlreadyUsed(err) { ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsSecurity, &forms.AddOpenIDForm{Openid: id}) @@ -98,7 +98,7 @@ func settingsOpenIDVerify(ctx *context.Context) { ctx.ServerError("AddUserOpenID", err) return } - log.Trace("Associated OpenID %s to user %s", id, ctx.User.Name) + log.Trace("Associated OpenID %s to user %s", id, ctx.Doer.Name) ctx.Flash.Success(ctx.Tr("settings.add_openid_success")) ctx.Redirect(setting.AppSubURL + "/user/settings/security") @@ -106,11 +106,11 @@ func settingsOpenIDVerify(ctx *context.Context) { // DeleteOpenID response for delete user's openid func DeleteOpenID(ctx *context.Context) { - if err := user_model.DeleteUserOpenID(&user_model.UserOpenID{ID: ctx.FormInt64("id"), UID: ctx.User.ID}); err != nil { + if err := user_model.DeleteUserOpenID(&user_model.UserOpenID{ID: ctx.FormInt64("id"), UID: ctx.Doer.ID}); err != nil { ctx.ServerError("DeleteUserOpenID", err) return } - log.Trace("OpenID address deleted: %s", ctx.User.Name) + log.Trace("OpenID address deleted: %s", ctx.Doer.Name) ctx.Flash.Success(ctx.Tr("settings.openid_deletion_success")) ctx.JSON(http.StatusOK, map[string]interface{}{ diff --git a/routers/web/user/setting/security/security.go b/routers/web/user/setting/security/security.go index 67bbbf8b31..a87012c480 100644 --- a/routers/web/user/setting/security/security.go +++ b/routers/web/user/setting/security/security.go @@ -43,7 +43,7 @@ func DeleteAccountLink(ctx *context.Context) { if id <= 0 { ctx.Flash.Error("Account link id is not given") } else { - if _, err := user_model.RemoveAccountLink(ctx.User, id); err != nil { + if _, err := user_model.RemoveAccountLink(ctx.Doer, id); err != nil { ctx.Flash.Error("RemoveAccountLink: " + err.Error()) } else { ctx.Flash.Success(ctx.Tr("settings.remove_account_link_success")) @@ -56,28 +56,28 @@ func DeleteAccountLink(ctx *context.Context) { } func loadSecurityData(ctx *context.Context) { - enrolled, err := auth.HasTwoFactorByUID(ctx.User.ID) + enrolled, err := auth.HasTwoFactorByUID(ctx.Doer.ID) if err != nil { ctx.ServerError("SettingsTwoFactor", err) return } ctx.Data["TOTPEnrolled"] = enrolled - credentials, err := auth.GetWebAuthnCredentialsByUID(ctx.User.ID) + credentials, err := auth.GetWebAuthnCredentialsByUID(ctx.Doer.ID) if err != nil { ctx.ServerError("GetWebAuthnCredentialsByUID", err) return } ctx.Data["WebAuthnCredentials"] = credentials - tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{UserID: ctx.User.ID}) + tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{UserID: ctx.Doer.ID}) if err != nil { ctx.ServerError("ListAccessTokens", err) return } ctx.Data["Tokens"] = tokens - accountLinks, err := user_model.ListAccountLinks(ctx.User) + accountLinks, err := user_model.ListAccountLinks(ctx.Doer) if err != nil { ctx.ServerError("ListAccountLinks", err) return @@ -109,7 +109,7 @@ func loadSecurityData(ctx *context.Context) { } ctx.Data["AccountLinks"] = sources - openid, err := user_model.GetUserOpenIDs(ctx.User.ID) + openid, err := user_model.GetUserOpenIDs(ctx.Doer.ID) if err != nil { ctx.ServerError("GetUserOpenIDs", err) return diff --git a/routers/web/user/setting/security/webauthn.go b/routers/web/user/setting/security/webauthn.go index 7e2fc7283b..bb2d1f733e 100644 --- a/routers/web/user/setting/security/webauthn.go +++ b/routers/web/user/setting/security/webauthn.go @@ -28,7 +28,7 @@ func WebAuthnRegister(ctx *context.Context) { return } - cred, err := auth.GetWebAuthnCredentialByName(ctx.User.ID, form.Name) + cred, err := auth.GetWebAuthnCredentialByName(ctx.Doer.ID, form.Name) if err != nil && !auth.IsErrWebAuthnCredentialNotExist(err) { ctx.ServerError("GetWebAuthnCredentialsByUID", err) return @@ -44,7 +44,7 @@ func WebAuthnRegister(ctx *context.Context) { return } - credentialOptions, sessionData, err := wa.WebAuthn.BeginRegistration((*wa.User)(ctx.User)) + credentialOptions, sessionData, err := wa.WebAuthn.BeginRegistration((*wa.User)(ctx.Doer)) if err != nil { ctx.ServerError("Unable to BeginRegistration", err) return @@ -78,7 +78,7 @@ func WebauthnRegisterPost(ctx *context.Context) { }() // Verify that the challenge succeeded - cred, err := wa.WebAuthn.FinishRegistration((*wa.User)(ctx.User), *sessionData, ctx.Req) + cred, err := wa.WebAuthn.FinishRegistration((*wa.User)(ctx.Doer), *sessionData, ctx.Req) if err != nil { if pErr, ok := err.(*protocol.Error); ok { log.Error("Unable to finish registration due to error: %v\nDevInfo: %s", pErr, pErr.DevInfo) @@ -87,7 +87,7 @@ func WebauthnRegisterPost(ctx *context.Context) { return } - dbCred, err := auth.GetWebAuthnCredentialByName(ctx.User.ID, name) + dbCred, err := auth.GetWebAuthnCredentialByName(ctx.Doer.ID, name) if err != nil && !auth.IsErrWebAuthnCredentialNotExist(err) { ctx.ServerError("GetWebAuthnCredentialsByUID", err) return @@ -98,7 +98,7 @@ func WebauthnRegisterPost(ctx *context.Context) { } // Create the credential - _, err = auth.CreateCredential(ctx.User.ID, name, cred) + _, err = auth.CreateCredential(ctx.Doer.ID, name, cred) if err != nil { ctx.ServerError("CreateCredential", err) return @@ -111,7 +111,7 @@ func WebauthnRegisterPost(ctx *context.Context) { // WebauthnDelete deletes an security key by id func WebauthnDelete(ctx *context.Context) { form := web.GetForm(ctx).(*forms.WebauthnDeleteForm) - if _, err := auth.DeleteCredential(form.ID, ctx.User.ID); err != nil { + if _, err := auth.DeleteCredential(form.ID, ctx.Doer.ID); err != nil { ctx.ServerError("GetWebAuthnCredentialByID", err) return } |