aboutsummaryrefslogtreecommitdiffstats
path: root/modules/context
diff options
context:
space:
mode:
Diffstat (limited to 'modules/context')
-rw-r--r--modules/context/api.go8
-rw-r--r--modules/context/auth.go24
-rw-r--r--modules/context/context.go2
3 files changed, 18 insertions, 16 deletions
diff --git a/modules/context/api.go b/modules/context/api.go
index 4757c2eeb4..cbd90c50e4 100644
--- a/modules/context/api.go
+++ b/modules/context/api.go
@@ -203,12 +203,12 @@ func (ctx *APIContext) CheckForOTP() {
if models.IsErrTwoFactorNotEnrolled(err) {
return // No 2FA enrollment for this user
}
- ctx.Context.Error(500)
+ ctx.Context.Error(http.StatusInternalServerError)
return
}
ok, err := twofa.ValidateTOTP(otpHeader)
if err != nil {
- ctx.Context.Error(500)
+ ctx.Context.Error(http.StatusInternalServerError)
return
}
if !ok {
@@ -288,7 +288,7 @@ func ReferencesGitRepo(allowEmpty bool) func(http.Handler) http.Handler {
repoPath := models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {
- ctx.Error(500, "RepoRef Invalid repo "+repoPath, err)
+ ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo "+repoPath, err)
return
}
ctx.Repo.GitRepo = gitRepo
@@ -324,7 +324,7 @@ func (ctx *APIContext) NotFound(objs ...interface{}) {
}
}
- ctx.JSON(404, map[string]interface{}{
+ ctx.JSON(http.StatusNotFound, map[string]interface{}{
"message": message,
"documentation_url": setting.API.SwaggerURL,
"errors": errors,
diff --git a/modules/context/auth.go b/modules/context/auth.go
index 3b4d7fc595..ed220d5420 100644
--- a/modules/context/auth.go
+++ b/modules/context/auth.go
@@ -6,6 +6,8 @@
package context
import (
+ "net/http"
+
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -27,13 +29,13 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
if ctx.IsSigned {
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
- ctx.HTML(200, "user/auth/activate")
+ ctx.HTML(http.StatusOK, "user/auth/activate")
return
}
if !ctx.User.IsActive || ctx.User.ProhibitLogin {
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
- ctx.HTML(200, "user/auth/prohibit_login")
+ ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
return
}
@@ -76,7 +78,7 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
return
} else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
- ctx.HTML(200, "user/auth/activate")
+ ctx.HTML(http.StatusOK, "user/auth/activate")
return
}
}
@@ -93,7 +95,7 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
if options.AdminRequired {
if !ctx.User.IsAdmin {
- ctx.Error(403)
+ ctx.Error(http.StatusForbidden)
return
}
ctx.Data["PageIsAdmin"] = true
@@ -108,7 +110,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
if ctx.IsSigned {
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
- ctx.JSON(403, map[string]string{
+ ctx.JSON(http.StatusForbidden, map[string]string{
"message": "This account is not activated.",
})
return
@@ -116,14 +118,14 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
if !ctx.User.IsActive || ctx.User.ProhibitLogin {
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
- ctx.JSON(403, map[string]string{
+ ctx.JSON(http.StatusForbidden, map[string]string{
"message": "This account is prohibited from signing in, please contact your site administrator.",
})
return
}
if ctx.User.MustChangePassword {
- ctx.JSON(403, map[string]string{
+ ctx.JSON(http.StatusForbidden, map[string]string{
"message": "You must change your password. Change it at: " + setting.AppURL + "/user/change_password",
})
return
@@ -139,13 +141,13 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
if options.SignInRequired {
if !ctx.IsSigned {
// Restrict API calls with error message.
- ctx.JSON(403, map[string]string{
+ ctx.JSON(http.StatusForbidden, map[string]string{
"message": "Only signed in user is allowed to call APIs.",
})
return
} else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
- ctx.HTML(200, "user/auth/activate")
+ ctx.HTML(http.StatusOK, "user/auth/activate")
return
}
if ctx.IsSigned && ctx.IsBasicAuth {
@@ -164,7 +166,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
return
}
if !ok {
- ctx.JSON(403, map[string]string{
+ ctx.JSON(http.StatusForbidden, map[string]string{
"message": "Only signed in user is allowed to call APIs.",
})
return
@@ -174,7 +176,7 @@ func ToggleAPI(options *ToggleOptions) func(ctx *APIContext) {
if options.AdminRequired {
if !ctx.User.IsAdmin {
- ctx.JSON(403, map[string]string{
+ ctx.JSON(http.StatusForbidden, map[string]string{
"message": "You have no permission to request for this.",
})
return
diff --git a/modules/context/context.go b/modules/context/context.go
index a784032606..b876487d5e 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -213,7 +213,7 @@ func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form interface{}
}
ctx.Flash.ErrorMsg = msg
ctx.Data["Flash"] = ctx.Flash
- ctx.HTML(200, tpl)
+ ctx.HTML(http.StatusOK, tpl)
}
// NotFound displays a 404 (Not Found) page and prints the given error, if any.