[refactor] replace int with httpStatusCodes (#15282)
* replace "200" (int) with "http.StatusOK" (const) * ctx.Error & ctx.HTML * ctx.JSON Part1 * ctx.JSON Part2 * ctx.JSON Part3
This commit is contained in:
parent
e9fba18a26
commit
16dea6cebd
64 changed files with 504 additions and 441 deletions
|
@ -7,6 +7,7 @@ package setting
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
@ -33,7 +34,7 @@ func Account(ctx *context.Context) {
|
|||
|
||||
loadAccountData(ctx)
|
||||
|
||||
ctx.HTML(200, tplSettingsAccount)
|
||||
ctx.HTML(http.StatusOK, tplSettingsAccount)
|
||||
}
|
||||
|
||||
// AccountPost response for change user's password
|
||||
|
@ -45,7 +46,7 @@ func AccountPost(ctx *context.Context) {
|
|||
if ctx.HasError() {
|
||||
loadAccountData(ctx)
|
||||
|
||||
ctx.HTML(200, tplSettingsAccount)
|
||||
ctx.HTML(http.StatusOK, tplSettingsAccount)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -167,7 +168,7 @@ func EmailPost(ctx *context.Context) {
|
|||
if ctx.HasError() {
|
||||
loadAccountData(ctx)
|
||||
|
||||
ctx.HTML(200, tplSettingsAccount)
|
||||
ctx.HTML(http.StatusOK, tplSettingsAccount)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -216,7 +217,7 @@ func DeleteEmail(ctx *context.Context) {
|
|||
log.Trace("Email address deleted: %s", ctx.User.Name)
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("settings.email_deletion_success"))
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": setting.AppSubURL + "/user/settings/account",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
package setting
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
|
@ -25,7 +27,7 @@ func Applications(ctx *context.Context) {
|
|||
|
||||
loadApplicationsData(ctx)
|
||||
|
||||
ctx.HTML(200, tplSettingsApplications)
|
||||
ctx.HTML(http.StatusOK, tplSettingsApplications)
|
||||
}
|
||||
|
||||
// ApplicationsPost response for add user's access token
|
||||
|
@ -37,7 +39,7 @@ func ApplicationsPost(ctx *context.Context) {
|
|||
if ctx.HasError() {
|
||||
loadApplicationsData(ctx)
|
||||
|
||||
ctx.HTML(200, tplSettingsApplications)
|
||||
ctx.HTML(http.StatusOK, tplSettingsApplications)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -76,7 +78,7 @@ func DeleteApplication(ctx *context.Context) {
|
|||
ctx.Flash.Success(ctx.Tr("settings.delete_token_success"))
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": setting.AppSubURL + "/user/settings/applications",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
package setting
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
|
@ -28,7 +30,7 @@ func Keys(ctx *context.Context) {
|
|||
|
||||
loadKeysData(ctx)
|
||||
|
||||
ctx.HTML(200, tplSettingsKeys)
|
||||
ctx.HTML(http.StatusOK, tplSettingsKeys)
|
||||
}
|
||||
|
||||
// KeysPost response for change user's SSH/GPG keys
|
||||
|
@ -43,7 +45,7 @@ func KeysPost(ctx *context.Context) {
|
|||
if ctx.HasError() {
|
||||
loadKeysData(ctx)
|
||||
|
||||
ctx.HTML(200, tplSettingsKeys)
|
||||
ctx.HTML(http.StatusOK, tplSettingsKeys)
|
||||
return
|
||||
}
|
||||
switch form.Type {
|
||||
|
@ -188,7 +190,7 @@ func DeleteKey(ctx *context.Context) {
|
|||
ctx.Flash.Warning("Function not implemented")
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings/keys")
|
||||
}
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": setting.AppSubURL + "/user/settings/keys",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ package setting
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
|
@ -29,7 +30,7 @@ func OAuthApplicationsPost(ctx *context.Context) {
|
|||
if ctx.HasError() {
|
||||
loadApplicationsData(ctx)
|
||||
|
||||
ctx.HTML(200, tplSettingsApplications)
|
||||
ctx.HTML(http.StatusOK, tplSettingsApplications)
|
||||
return
|
||||
}
|
||||
// TODO validate redirect URI
|
||||
|
@ -49,7 +50,7 @@ func OAuthApplicationsPost(ctx *context.Context) {
|
|||
ctx.ServerError("GenerateClientSecret", err)
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, tplSettingsOAuthApplications)
|
||||
ctx.HTML(http.StatusOK, tplSettingsOAuthApplications)
|
||||
}
|
||||
|
||||
// OAuthApplicationsEdit response for editing oauth2 application
|
||||
|
@ -61,7 +62,7 @@ func OAuthApplicationsEdit(ctx *context.Context) {
|
|||
if ctx.HasError() {
|
||||
loadApplicationsData(ctx)
|
||||
|
||||
ctx.HTML(200, tplSettingsApplications)
|
||||
ctx.HTML(http.StatusOK, tplSettingsApplications)
|
||||
return
|
||||
}
|
||||
// TODO validate redirect URI
|
||||
|
@ -76,7 +77,7 @@ func OAuthApplicationsEdit(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
ctx.Flash.Success(ctx.Tr("settings.update_oauth2_application_success"))
|
||||
ctx.HTML(200, tplSettingsOAuthApplications)
|
||||
ctx.HTML(http.StatusOK, tplSettingsOAuthApplications)
|
||||
}
|
||||
|
||||
// OAuthApplicationsRegenerateSecret handles the post request for regenerating the secret
|
||||
|
@ -104,7 +105,7 @@ func OAuthApplicationsRegenerateSecret(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
ctx.Flash.Success(ctx.Tr("settings.update_oauth2_application_success"))
|
||||
ctx.HTML(200, tplSettingsOAuthApplications)
|
||||
ctx.HTML(http.StatusOK, tplSettingsOAuthApplications)
|
||||
}
|
||||
|
||||
// OAuth2ApplicationShow displays the given application
|
||||
|
@ -123,7 +124,7 @@ func OAuth2ApplicationShow(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
ctx.Data["App"] = app
|
||||
ctx.HTML(200, tplSettingsOAuthApplications)
|
||||
ctx.HTML(http.StatusOK, tplSettingsOAuthApplications)
|
||||
}
|
||||
|
||||
// DeleteOAuth2Application deletes the given oauth2 application
|
||||
|
@ -135,7 +136,7 @@ func DeleteOAuth2Application(ctx *context.Context) {
|
|||
log.Trace("OAuth2 Application deleted: %s", ctx.User.Name)
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("settings.remove_oauth2_application_success"))
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": setting.AppSubURL + "/user/settings/applications",
|
||||
})
|
||||
}
|
||||
|
@ -152,7 +153,7 @@ func RevokeOAuth2Grant(ctx *context.Context) {
|
|||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("settings.revoke_oauth2_grant_success"))
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": setting.AppSubURL + "/user/settings/applications",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -37,7 +38,7 @@ func Profile(ctx *context.Context) {
|
|||
ctx.Data["Title"] = ctx.Tr("settings")
|
||||
ctx.Data["PageIsSettingsProfile"] = true
|
||||
|
||||
ctx.HTML(200, tplSettingsProfile)
|
||||
ctx.HTML(http.StatusOK, tplSettingsProfile)
|
||||
}
|
||||
|
||||
// HandleUsernameChange handle username changes from user settings and admin interface
|
||||
|
@ -79,7 +80,7 @@ func ProfilePost(ctx *context.Context) {
|
|||
ctx.Data["PageIsSettingsProfile"] = true
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplSettingsProfile)
|
||||
ctx.HTML(http.StatusOK, tplSettingsProfile)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -204,7 +205,7 @@ func Organization(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
ctx.Data["Orgs"] = orgs
|
||||
ctx.HTML(200, tplSettingsOrganization)
|
||||
ctx.HTML(http.StatusOK, tplSettingsOrganization)
|
||||
}
|
||||
|
||||
// Repos display a list of all repositories of the user
|
||||
|
@ -305,5 +306,5 @@ func Repos(ctx *context.Context) {
|
|||
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
|
||||
pager.SetDefaultParams(ctx)
|
||||
ctx.Data["Page"] = pager
|
||||
ctx.HTML(200, tplSettingsRepositories)
|
||||
ctx.HTML(http.StatusOK, tplSettingsRepositories)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
package setting
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
|
@ -30,7 +32,7 @@ func Security(ctx *context.Context) {
|
|||
|
||||
loadSecurityData(ctx)
|
||||
|
||||
ctx.HTML(200, tplSettingsSecurity)
|
||||
ctx.HTML(http.StatusOK, tplSettingsSecurity)
|
||||
}
|
||||
|
||||
// DeleteAccountLink delete a single account link
|
||||
|
@ -46,7 +48,7 @@ func DeleteAccountLink(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": setting.AppSubURL + "/user/settings/security",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
package setting
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/auth/openid"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
|
@ -23,7 +25,7 @@ func OpenIDPost(ctx *context.Context) {
|
|||
if ctx.HasError() {
|
||||
loadSecurityData(ctx)
|
||||
|
||||
ctx.HTML(200, tplSettingsSecurity)
|
||||
ctx.HTML(http.StatusOK, tplSettingsSecurity)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -111,7 +113,7 @@ func DeleteOpenID(ctx *context.Context) {
|
|||
log.Trace("OpenID address deleted: %s", ctx.User.Name)
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("settings.openid_deletion_success"))
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": setting.AppSubURL + "/user/settings/security",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"encoding/base64"
|
||||
"html/template"
|
||||
"image/png"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
@ -162,7 +163,7 @@ func EnrollTwoFactor(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.HTML(200, tplSettingsTwofaEnroll)
|
||||
ctx.HTML(http.StatusOK, tplSettingsTwofaEnroll)
|
||||
}
|
||||
|
||||
// EnrollTwoFactorPost handles enrolling the user into 2FA.
|
||||
|
@ -187,7 +188,7 @@ func EnrollTwoFactorPost(ctx *context.Context) {
|
|||
if !twofaGenerateSecretAndQr(ctx) {
|
||||
return
|
||||
}
|
||||
ctx.HTML(200, tplSettingsTwofaEnroll)
|
||||
ctx.HTML(http.StatusOK, tplSettingsTwofaEnroll)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ package setting
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
|
@ -21,7 +22,7 @@ import (
|
|||
func U2FRegister(ctx *context.Context) {
|
||||
form := web.GetForm(ctx).(*auth.U2FRegistrationForm)
|
||||
if form.Name == "" {
|
||||
ctx.Error(409)
|
||||
ctx.Error(http.StatusConflict)
|
||||
return
|
||||
}
|
||||
challenge, err := u2f.NewChallenge(setting.U2F.AppID, setting.U2F.TrustedFacets)
|
||||
|
@ -40,7 +41,7 @@ func U2FRegister(ctx *context.Context) {
|
|||
}
|
||||
for _, reg := range regs {
|
||||
if reg.Name == form.Name {
|
||||
ctx.Error(409, "Name already taken")
|
||||
ctx.Error(http.StatusConflict, "Name already taken")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +54,7 @@ func U2FRegister(ctx *context.Context) {
|
|||
// we'll tolerate errors here as they *should* get saved elsewhere
|
||||
log.Error("Unable to save changes to the session: %v", err)
|
||||
}
|
||||
ctx.JSON(200, u2f.NewWebRegisterRequest(challenge, regs.ToRegistrations()))
|
||||
ctx.JSON(http.StatusOK, u2f.NewWebRegisterRequest(challenge, regs.ToRegistrations()))
|
||||
}
|
||||
|
||||
// U2FRegisterPost receives the response of the security key
|
||||
|
@ -104,7 +105,7 @@ func U2FDelete(ctx *context.Context) {
|
|||
ctx.ServerError("DeleteRegistration", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"redirect": setting.AppSubURL + "/user/settings/security",
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue