Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor User Settings #3900

Merged
merged 11 commits into from
May 15, 2018
8 changes: 4 additions & 4 deletions integrations/delete_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func TestUserDeleteAccount(t *testing.T) {
prepareTestEnv(t)

session := loginUser(t, "user8")
csrf := GetCSRF(t, session, "/user/settings/delete")
urlStr := fmt.Sprintf("/user/settings/delete?password=%s", userPassword)
csrf := GetCSRF(t, session, "/user/settings/account")
urlStr := fmt.Sprintf("/user/settings/account/delete?password=%s", userPassword)
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
"_csrf": csrf,
})
Expand All @@ -58,8 +58,8 @@ func TestUserDeleteAccountStillOwnRepos(t *testing.T) {
prepareTestEnv(t)

session := loginUser(t, "user2")
csrf := GetCSRF(t, session, "/user/settings/delete")
urlStr := fmt.Sprintf("/user/settings/delete?password=%s", userPassword)
csrf := GetCSRF(t, session, "/user/settings/account")
urlStr := fmt.Sprintf("/user/settings/account/delete?password=%s", userPassword)
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
"_csrf": csrf,
})
Expand Down
7 changes: 2 additions & 5 deletions integrations/links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,12 @@ func testLinksAsUser(userName string, t *testing.T) {
"/user2?tab=stars",
"/user2?tab=activity",
"/user/settings",
"/user/settings/avatar",
"/user/settings/account",
"/user/settings/security",
"/user/settings/security/two_factor/enroll",
"/user/settings/email",
"/user/settings/keys",
"/user/settings/applications",
"/user/settings/account_link",
"/user/settings/organization",
"/user/settings/delete",
"/user/settings/repos",
}

session := loginUser(t, userName)
Expand Down
3 changes: 2 additions & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,13 @@ form.name_pattern_not_allowed = The pattern '%s' is not allowed in a username.

[settings]
profile = Profile
account = Account
password = Password
security = Security
avatar = Avatar
ssh_gpg_keys = SSH / GPG Keys
social = Social Accounts
applications = Access Tokens
applications = Applications
orgs = Manage Organizations
repos = Repositories
delete = Delete Account
Expand Down
65 changes: 42 additions & 23 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,35 +217,54 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/user/settings", func() {
m.Get("", user.Settings)
m.Post("", bindIgnErr(auth.UpdateProfileForm{}), user.SettingsPost)
m.Combo("/avatar").Get(user.SettingsAvatar).
Post(binding.MultipartForm(auth.AvatarForm{}), user.SettingsAvatarPost)
m.Post("/avatar", binding.MultipartForm(auth.AvatarForm{}), user.SettingsAvatarPost)
m.Post("/avatar/delete", user.SettingsDeleteAvatar)
m.Combo("/email").Get(user.SettingsEmails).
Post(bindIgnErr(auth.AddEmailForm{}), user.SettingsEmailPost)
m.Post("/email/delete", user.DeleteEmail)
m.Get("/security", user.SettingsSecurity)
m.Post("/security", bindIgnErr(auth.ChangePasswordForm{}), user.SettingsSecurityPost)
m.Group("/openid", func() {
m.Combo("").Get(user.SettingsOpenID).
Post(bindIgnErr(auth.AddOpenIDForm{}), user.SettingsOpenIDPost)
m.Post("/delete", user.DeleteOpenID)
m.Post("/toggle_visibility", user.ToggleOpenIDVisibility)
}, openIDSignInEnabled)
m.Combo("/keys").Get(user.SettingsKeys).
Post(bindIgnErr(auth.AddKeyForm{}), user.SettingsKeysPost)
m.Post("/keys/delete", user.DeleteKey)
m.Group("/account", func() {
m.Combo("").Get(user.SettingsAccount).Post(bindIgnErr(auth.ChangePasswordForm{}), user.SettingsAccountPost)
m.Post("/email", bindIgnErr(auth.AddEmailForm{}), user.SettingsEmailPost)
m.Post("/email/delete", user.DeleteEmail)
m.Post("/delete", user.SettingsDelete)
})
m.Group("/security", func() {
m.Get("", user.SettingsSecurity)
m.Group("/two_factor", func() {
m.Post("/regenerate_scratch", user.SettingsTwoFactorRegenerateScratch)
m.Post("/disable", user.SettingsTwoFactorDisable)
m.Get("/enroll", user.SettingsTwoFactorEnroll)
m.Post("/enroll", bindIgnErr(auth.TwoFactorAuthForm{}), user.SettingsTwoFactorEnrollPost)
})
m.Group("/openid", func() {
m.Post("", bindIgnErr(auth.AddOpenIDForm{}), user.SettingsOpenIDPost)
m.Post("/delete", user.DeleteOpenID)
m.Post("/toggle_visibility", user.ToggleOpenIDVisibility)
}, openIDSignInEnabled)
m.Post("/account_link", user.SettingsDeleteAccountLink)
})
m.Combo("/applications").Get(user.SettingsApplications).
Post(bindIgnErr(auth.NewAccessTokenForm{}), user.SettingsApplicationsPost)
m.Post("/applications/delete", user.SettingsDeleteApplication)
m.Route("/delete", "GET,POST", user.SettingsDelete)
m.Combo("/account_link").Get(user.SettingsAccountLinks).Post(user.SettingsDeleteAccountLink)
m.Combo("/keys").Get(user.SettingsKeys).
Post(bindIgnErr(auth.AddKeyForm{}), user.SettingsKeysPost)
m.Post("/keys/delete", user.DeleteKey)
m.Get("/organization", user.SettingsOrganization)
m.Get("/repos", user.SettingsRepos)
m.Group("/security/two_factor", func() {
m.Post("/regenerate_scratch", user.SettingsTwoFactorRegenerateScratch)
m.Post("/disable", user.SettingsTwoFactorDisable)
m.Get("/enroll", user.SettingsTwoFactorEnroll)
m.Post("/enroll", bindIgnErr(auth.TwoFactorAuthForm{}), user.SettingsTwoFactorEnrollPost)

// redirects from old settings urls to new ones
// TODO: can be removed on next major version
m.Get("/avatar", func(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/user/settings")
})
m.Get("/email", func(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/user/settings/account")
})
m.Get("/delete", func(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/user/settings/account")
})
m.Get("/openid", func(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/user/settings/security")
})
m.Get("/account_link", func(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/user/settings/security")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add , http.StatusMovedPermanently to each Redirect? This way it can be properly cached by browsers

})
}, reqSignIn, func(ctx *context.Context) {
ctx.Data["PageIsUserSettings"] = true
Expand Down