1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Rename context.Query to context.Form (#16562)

This commit is contained in:
Lunny Xiao
2021-07-29 09:42:15 +08:00
committed by GitHub
parent 3705168837
commit 33e0b38287
85 changed files with 393 additions and 396 deletions

View File

@@ -111,7 +111,7 @@ func checkAutoLogin(ctx *context.Context) bool {
return true
}
redirectTo := ctx.Query("redirect_to")
redirectTo := ctx.Form("redirect_to")
if len(redirectTo) > 0 {
middleware.SetRedirectToCookie(ctx.Resp, redirectTo)
} else {
@@ -1333,7 +1333,7 @@ func handleUserCreated(ctx *context.Context, u *models.User, gothUser *goth.User
// Activate render activate user page
func Activate(ctx *context.Context) {
code := ctx.Query("code")
code := ctx.Form("code")
if len(code) == 0 {
ctx.Data["IsActivatePage"] = true
@@ -1381,7 +1381,7 @@ func Activate(ctx *context.Context) {
// ActivatePost handles account activation with password check
func ActivatePost(ctx *context.Context) {
code := ctx.Query("code")
code := ctx.Form("code")
if len(code) == 0 {
ctx.Redirect(setting.AppSubURL + "/user/activate")
return
@@ -1397,7 +1397,7 @@ func ActivatePost(ctx *context.Context) {
// if account is local account, verify password
if user.LoginSource == 0 {
password := ctx.Query("password")
password := ctx.Form("password")
if len(password) == 0 {
ctx.Data["Code"] = code
ctx.Data["NeedsPassword"] = true
@@ -1454,8 +1454,8 @@ func handleAccountActivation(ctx *context.Context, user *models.User) {
// ActivateEmail render the activate email page
func ActivateEmail(ctx *context.Context) {
code := ctx.Query("code")
emailStr := ctx.Query("email")
code := ctx.Form("code")
emailStr := ctx.Form("email")
// Verify code.
if email := models.VerifyActiveEmailCode(code, emailStr); email != nil {
@@ -1491,7 +1491,7 @@ func ForgotPasswd(ctx *context.Context) {
return
}
email := ctx.Query("email")
email := ctx.Form("email")
ctx.Data["Email"] = email
ctx.Data["IsResetRequest"] = true
@@ -1508,7 +1508,7 @@ func ForgotPasswdPost(ctx *context.Context) {
}
ctx.Data["IsResetRequest"] = true
email := ctx.Query("email")
email := ctx.Form("email")
ctx.Data["Email"] = email
u, err := models.GetUserByEmail(email)
@@ -1548,7 +1548,7 @@ func ForgotPasswdPost(ctx *context.Context) {
}
func commonResetPassword(ctx *context.Context) (*models.User, *models.TwoFactor) {
code := ctx.Query("code")
code := ctx.Form("code")
ctx.Data["Title"] = ctx.Tr("auth.reset_password")
ctx.Data["Code"] = code
@@ -1577,7 +1577,7 @@ func commonResetPassword(ctx *context.Context) (*models.User, *models.TwoFactor)
}
} else {
ctx.Data["has_two_factor"] = true
ctx.Data["scratch_code"] = ctx.QueryBool("scratch_code")
ctx.Data["scratch_code"] = ctx.FormBool("scratch_code")
}
// Show the user that they are affecting the account that they intended to
@@ -1617,7 +1617,7 @@ func ResetPasswdPost(ctx *context.Context) {
}
// Validate password length.
passwd := ctx.Query("password")
passwd := ctx.Form("password")
if len(passwd) < setting.MinPasswordLength {
ctx.Data["IsResetForm"] = true
ctx.Data["Err_Password"] = true
@@ -1643,8 +1643,8 @@ func ResetPasswdPost(ctx *context.Context) {
// Handle two-factor
regenerateScratchToken := false
if twofa != nil {
if ctx.QueryBool("scratch_code") {
if !twofa.VerifyScratchToken(ctx.Query("token")) {
if ctx.FormBool("scratch_code") {
if !twofa.VerifyScratchToken(ctx.Form("token")) {
ctx.Data["IsResetForm"] = true
ctx.Data["Err_Token"] = true
ctx.RenderWithErr(ctx.Tr("auth.twofa_scratch_token_incorrect"), tplResetPassword, nil)
@@ -1652,7 +1652,7 @@ func ResetPasswdPost(ctx *context.Context) {
}
regenerateScratchToken = true
} else {
passcode := ctx.Query("passcode")
passcode := ctx.Form("passcode")
ok, err := twofa.ValidateTOTP(passcode)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ValidateTOTP", err.Error())
@@ -1689,7 +1689,7 @@ func ResetPasswdPost(ctx *context.Context) {
log.Trace("User password reset: %s", u.Name)
ctx.Data["IsResetFailed"] = true
remember := len(ctx.Query("remember")) != 0
remember := len(ctx.Form("remember")) != 0
if regenerateScratchToken {
// Invalidate the scratch token.

View File

@@ -34,7 +34,7 @@ const (
func SignInOpenID(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("sign_in")
if ctx.Query("openid.return_to") != "" {
if ctx.Form("openid.return_to") != "" {
signInOpenIDVerify(ctx)
return
}
@@ -46,7 +46,7 @@ func SignInOpenID(ctx *context.Context) {
return
}
redirectTo := ctx.Query("redirect_to")
redirectTo := ctx.Form("redirect_to")
if len(redirectTo) > 0 {
middleware.SetRedirectToCookie(ctx.Resp, redirectTo)
} else {

View File

@@ -66,7 +66,7 @@ func AvatarByEmailHash(ctx *context.Context) {
ctx.Redirect(models.DefaultAvatarLink())
return
}
size := ctx.QueryInt("size")
size := ctx.FormInt("size")
if size == 0 {
size = models.DefaultAvatarSize
}

View File

@@ -157,7 +157,7 @@ func Dashboard(ctx *context.Context) {
IncludePrivate: true,
OnlyPerformedBy: false,
IncludeDeleted: false,
Date: ctx.Query("date"),
Date: ctx.Form("date"),
})
if ctx.Written() {
@@ -200,11 +200,11 @@ func Milestones(ctx *context.Context) {
repoCond = userRepoCond
repoIDs []int64
reposQuery = ctx.Query("repos")
isShowClosed = ctx.Query("state") == "closed"
sortType = ctx.Query("sort")
page = ctx.QueryInt("page")
keyword = strings.Trim(ctx.Query("q"), " ")
reposQuery = ctx.Form("repos")
isShowClosed = ctx.Form("state") == "closed"
sortType = ctx.Form("sort")
page = ctx.FormInt("page")
keyword = strings.Trim(ctx.Form("q"), " ")
)
if page <= 1 {
@@ -380,7 +380,7 @@ func buildIssueOverview(ctx *context.Context, unitType models.UnitType) {
var (
viewType string
sortType = ctx.Query("sort")
sortType = ctx.Form("sort")
filterMode = models.FilterModeAll
)
@@ -390,14 +390,14 @@ func buildIssueOverview(ctx *context.Context, unitType models.UnitType) {
// - Remember pre-determined viewType string for later. Will be posted to ctx.Data.
// Organization does not have view type and filter mode.
// User:
// - Use ctx.Query("type") to determine filterMode.
// - Use ctx.Form("type") to determine filterMode.
// The type is set when clicking for example "assigned to me" on the overview page.
// - Remember either this or a fallback. Will be posted to ctx.Data.
// --------------------------------------------------------------------------------
// TODO: distinguish during routing
viewType = ctx.Query("type")
viewType = ctx.Form("type")
switch viewType {
case "assigned":
filterMode = models.FilterModeAssign
@@ -456,7 +456,7 @@ func buildIssueOverview(ctx *context.Context, unitType models.UnitType) {
}
// keyword holds the search term entered into the search field.
keyword := strings.Trim(ctx.Query("q"), " ")
keyword := strings.Trim(ctx.Form("q"), " ")
ctx.Data["Keyword"] = keyword
// Execute keyword search for issues.
@@ -477,7 +477,7 @@ func buildIssueOverview(ctx *context.Context, unitType models.UnitType) {
}
// Educated guess: Do or don't show closed issues.
isShowClosed := ctx.Query("state") == "closed"
isShowClosed := ctx.Form("state") == "closed"
opts.IsClosed = util.OptionalBoolOf(isShowClosed)
// Filter repos and count issues in them. Count will be used later.
@@ -492,7 +492,7 @@ func buildIssueOverview(ctx *context.Context, unitType models.UnitType) {
}
// Make sure page number is at least 1. Will be posted to ctx.Data.
page := ctx.QueryInt("page")
page := ctx.FormInt("page")
if page <= 1 {
page = 1
}
@@ -502,7 +502,7 @@ func buildIssueOverview(ctx *context.Context, unitType models.UnitType) {
// Get IDs for labels (a filter option for issues/pulls).
// Required for IssuesOptions.
var labelIDs []int64
selectedLabels := ctx.Query("labels")
selectedLabels := ctx.Form("labels")
if len(selectedLabels) > 0 && selectedLabels != "0" {
labelIDs, err = base.StringsToInt64s(strings.Split(selectedLabels, ","))
if err != nil {
@@ -512,9 +512,9 @@ func buildIssueOverview(ctx *context.Context, unitType models.UnitType) {
}
opts.LabelIDs = labelIDs
// Parse ctx.Query("repos") and remember matched repo IDs for later.
// Parse ctx.Form("repos") and remember matched repo IDs for later.
// Gets set when clicking filters on the issues overview page.
repoIDs := getRepoIDs(ctx.Query("repos"))
repoIDs := getRepoIDs(ctx.Form("repos"))
if len(repoIDs) > 0 {
opts.RepoIDs = repoIDs
}
@@ -658,7 +658,7 @@ func buildIssueOverview(ctx *context.Context, unitType models.UnitType) {
ctx.Data["IsShowClosed"] = isShowClosed
ctx.Data["IssueRefEndNames"], ctx.Data["IssueRefURLs"] =
issue_service.GetRefEndNamesAndURLs(issues, ctx.Query("RepoLink"))
issue_service.GetRefEndNamesAndURLs(issues, ctx.Form("RepoLink"))
ctx.Data["Issues"] = issues
@@ -900,7 +900,7 @@ func ShowGPGKeys(ctx *context.Context, uid int64) {
// Email2User show user page via email
func Email2User(ctx *context.Context) {
u, err := models.GetUserByEmail(ctx.Query("email"))
u, err := models.GetUserByEmail(ctx.Form("email"))
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.NotFound("GetUserByEmail", err)

View File

@@ -49,8 +49,8 @@ func Notifications(c *context.Context) {
if c.Written() {
return
}
if c.QueryBool("div-only") {
c.Data["SequenceNumber"] = c.Query("sequence-number")
if c.FormBool("div-only") {
c.Data["SequenceNumber"] = c.Form("sequence-number")
c.HTML(http.StatusOK, tplNotificationDiv)
return
}
@@ -59,10 +59,10 @@ func Notifications(c *context.Context) {
func getNotifications(c *context.Context) {
var (
keyword = strings.Trim(c.Query("q"), " ")
keyword = strings.Trim(c.Form("q"), " ")
status models.NotificationStatus
page = c.QueryInt("page")
perPage = c.QueryInt("perPage")
page = c.FormInt("page")
perPage = c.FormInt("perPage")
)
if page < 1 {
page = 1
@@ -87,7 +87,7 @@ func getNotifications(c *context.Context) {
// redirect to last page if request page is more than total pages
pager := context.NewPagination(int(total), perPage, page, 5)
if pager.Paginater.Current() < page {
c.Redirect(fmt.Sprintf("/notifications?q=%s&page=%d", c.Query("q"), pager.Paginater.Current()))
c.Redirect(fmt.Sprintf("/notifications?q=%s&page=%d", c.Form("q"), pager.Paginater.Current()))
return
}
@@ -166,8 +166,8 @@ func NotificationStatusPost(c *context.Context) {
return
}
if !c.QueryBool("noredirect") {
url := fmt.Sprintf("%s/notifications?page=%s", setting.AppSubURL, c.Query("page"))
if !c.FormBool("noredirect") {
url := fmt.Sprintf("%s/notifications?page=%s", setting.AppSubURL, c.Form("page"))
c.Redirect(url, http.StatusSeeOther)
}

View File

@@ -143,15 +143,15 @@ func Profile(ctx *context.Context) {
ctx.Data["Orgs"] = orgs
ctx.Data["HasOrgsVisible"] = models.HasOrgsVisible(orgs, ctx.User)
tab := ctx.Query("tab")
tab := ctx.Form("tab")
ctx.Data["TabName"] = tab
page := ctx.QueryInt("page")
page := ctx.FormInt("page")
if page <= 0 {
page = 1
}
topicOnly := ctx.QueryBool("topic")
topicOnly := ctx.FormBool("topic")
var (
repos []*models.Repository
@@ -160,8 +160,8 @@ func Profile(ctx *context.Context) {
orderBy models.SearchOrderBy
)
ctx.Data["SortType"] = ctx.Query("sort")
switch ctx.Query("sort") {
ctx.Data["SortType"] = ctx.Form("sort")
switch ctx.Form("sort") {
case "newest":
orderBy = models.SearchOrderByNewest
case "oldest":
@@ -187,7 +187,7 @@ func Profile(ctx *context.Context) {
orderBy = models.SearchOrderByRecentUpdated
}
keyword := strings.Trim(ctx.Query("q"), " ")
keyword := strings.Trim(ctx.Form("q"), " ")
ctx.Data["Keyword"] = keyword
switch tab {
case "followers":
@@ -220,7 +220,7 @@ func Profile(ctx *context.Context) {
IncludePrivate: showPrivate,
OnlyPerformedBy: true,
IncludeDeleted: false,
Date: ctx.Query("date"),
Date: ctx.Form("date"),
})
if ctx.Written() {
return
@@ -332,5 +332,5 @@ func Action(ctx *context.Context) {
return
}
ctx.RedirectToFirst(ctx.Query("redirect_to"), u.HomeLink())
ctx.RedirectToFirst(ctx.Form("redirect_to"), u.HomeLink())
}

View File

@@ -90,8 +90,8 @@ func EmailPost(ctx *context.Context) {
ctx.Data["PageIsSettingsAccount"] = true
// Make emailaddress primary.
if ctx.Query("_method") == "PRIMARY" {
if err := models.MakeEmailPrimary(&models.EmailAddress{ID: ctx.QueryInt64("id")}); err != nil {
if ctx.Form("_method") == "PRIMARY" {
if err := models.MakeEmailPrimary(&models.EmailAddress{ID: ctx.FormInt64("id")}); err != nil {
ctx.ServerError("MakeEmailPrimary", err)
return
}
@@ -101,7 +101,7 @@ func EmailPost(ctx *context.Context) {
return
}
// Send activation Email
if ctx.Query("_method") == "SENDACTIVATION" {
if ctx.Form("_method") == "SENDACTIVATION" {
var address string
if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) {
log.Error("Send activation: activation still pending")
@@ -109,7 +109,7 @@ func EmailPost(ctx *context.Context) {
return
}
id := ctx.QueryInt64("id")
id := ctx.FormInt64("id")
email, err := models.GetEmailAddressByID(ctx.User.ID, id)
if err != nil {
log.Error("GetEmailAddressByID(%d,%d) error: %v", ctx.User.ID, id, err)
@@ -147,8 +147,8 @@ func EmailPost(ctx *context.Context) {
return
}
// Set Email Notification Preference
if ctx.Query("_method") == "NOTIFICATION" {
preference := ctx.Query("preference")
if ctx.Form("_method") == "NOTIFICATION" {
preference := ctx.Form("preference")
if !(preference == models.EmailNotificationsEnabled ||
preference == models.EmailNotificationsOnMention ||
preference == models.EmailNotificationsDisabled) {
@@ -212,7 +212,7 @@ func EmailPost(ctx *context.Context) {
// DeleteEmail response for delete user's email
func DeleteEmail(ctx *context.Context) {
if err := models.DeleteEmailAddress(&models.EmailAddress{ID: ctx.QueryInt64("id"), UID: ctx.User.ID}); err != nil {
if err := models.DeleteEmailAddress(&models.EmailAddress{ID: ctx.FormInt64("id"), UID: ctx.User.ID}); err != nil {
ctx.ServerError("DeleteEmail", err)
return
}
@@ -229,7 +229,7 @@ func DeleteAccount(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsAccount"] = true
if _, err := auth.UserSignIn(ctx.User.Name, ctx.Query("password")); err != nil {
if _, err := auth.UserSignIn(ctx.User.Name, ctx.Form("password")); err != nil {
if models.IsErrUserNotExist(err) {
loadAccountData(ctx)

View File

@@ -23,8 +23,8 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
allowDelete := ctx.IsUserSiteAdmin() || setting.Repository.AllowDeleteOfUnadoptedRepositories
ctx.Data["allowDelete"] = allowDelete
dir := ctx.Query("id")
action := ctx.Query("action")
dir := ctx.Form("id")
action := ctx.Form("action")
ctxUser := ctx.User
root := filepath.Join(models.UserPath(ctxUser.LowerName))

View File

@@ -72,7 +72,7 @@ func ApplicationsPost(ctx *context.Context) {
// DeleteApplication response for delete user access token
func DeleteApplication(ctx *context.Context) {
if err := models.DeleteAccessTokenByID(ctx.QueryInt64("id"), ctx.User.ID); err != nil {
if err := models.DeleteAccessTokenByID(ctx.FormInt64("id"), ctx.User.ID); err != nil {
ctx.Flash.Error("DeleteAccessTokenByID: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("settings.delete_token_success"))

View File

@@ -193,15 +193,15 @@ func KeysPost(ctx *context.Context) {
// DeleteKey response for delete user's SSH/GPG key
func DeleteKey(ctx *context.Context) {
switch ctx.Query("type") {
switch ctx.Form("type") {
case "gpg":
if err := models.DeleteGPGKey(ctx.User, ctx.QueryInt64("id")); err != nil {
if err := models.DeleteGPGKey(ctx.User, ctx.FormInt64("id")); err != nil {
ctx.Flash.Error("DeleteGPGKey: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("settings.gpg_key_deletion_success"))
}
case "ssh":
keyID := ctx.QueryInt64("id")
keyID := ctx.FormInt64("id")
external, err := models.PublicKeyIsExternallyManaged(keyID)
if err != nil {
ctx.ServerError("sshKeysExternalManaged", err)
@@ -218,7 +218,7 @@ func DeleteKey(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("settings.ssh_key_deletion_success"))
}
case "principal":
if err := models.DeletePublicKey(ctx.User, ctx.QueryInt64("id")); err != nil {
if err := models.DeletePublicKey(ctx.User, ctx.FormInt64("id")); err != nil {
ctx.Flash.Error("DeletePublicKey: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("settings.ssh_principal_deletion_success"))
@@ -265,5 +265,5 @@ func loadKeysData(ctx *context.Context) {
}
ctx.Data["Principals"] = principals
ctx.Data["VerifyingID"] = ctx.Query("verify_gpg")
ctx.Data["VerifyingID"] = ctx.Form("verify_gpg")
}

View File

@@ -129,7 +129,7 @@ func OAuth2ApplicationShow(ctx *context.Context) {
// DeleteOAuth2Application deletes the given oauth2 application
func DeleteOAuth2Application(ctx *context.Context) {
if err := models.DeleteOAuth2Application(ctx.QueryInt64("id"), ctx.User.ID); err != nil {
if err := models.DeleteOAuth2Application(ctx.FormInt64("id"), ctx.User.ID); err != nil {
ctx.ServerError("DeleteOAuth2Application", err)
return
}
@@ -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.QueryInt64("id") == 0 {
if ctx.User.ID == 0 || ctx.FormInt64("id") == 0 {
ctx.ServerError("RevokeOAuth2Grant", fmt.Errorf("user id or grant id is zero"))
return
}
if err := models.RevokeOAuth2Grant(ctx.QueryInt64("id"), ctx.User.ID); err != nil {
if err := models.RevokeOAuth2Grant(ctx.FormInt64("id"), ctx.User.ID); err != nil {
ctx.ServerError("RevokeOAuth2Grant", err)
return
}

View File

@@ -237,7 +237,7 @@ func Repos(ctx *context.Context) {
opts := models.ListOptions{
PageSize: setting.UI.Admin.UserPagingNum,
Page: ctx.QueryInt("page"),
Page: ctx.FormInt("page"),
}
if opts.Page <= 0 {

View File

@@ -26,7 +26,7 @@ func Security(ctx *context.Context) {
ctx.Data["PageIsSettingsSecurity"] = true
ctx.Data["RequireU2F"] = true
if ctx.Query("openid.return_to") != "" {
if ctx.Form("openid.return_to") != "" {
settingsOpenIDVerify(ctx)
return
}
@@ -38,7 +38,7 @@ func Security(ctx *context.Context) {
// DeleteAccountLink delete a single account link
func DeleteAccountLink(ctx *context.Context) {
id := ctx.QueryInt64("id")
id := ctx.FormInt64("id")
if id <= 0 {
ctx.Flash.Error("Account link id is not given")
} else {

View File

@@ -106,7 +106,7 @@ func settingsOpenIDVerify(ctx *context.Context) {
// DeleteOpenID response for delete user's openid
func DeleteOpenID(ctx *context.Context) {
if err := models.DeleteUserOpenID(&models.UserOpenID{ID: ctx.QueryInt64("id"), UID: ctx.User.ID}); err != nil {
if err := models.DeleteUserOpenID(&models.UserOpenID{ID: ctx.FormInt64("id"), UID: ctx.User.ID}); err != nil {
ctx.ServerError("DeleteUserOpenID", err)
return
}
@@ -120,7 +120,7 @@ func DeleteOpenID(ctx *context.Context) {
// ToggleOpenIDVisibility response for toggle visibility of user's openid
func ToggleOpenIDVisibility(ctx *context.Context) {
if err := models.ToggleUserOpenIDVisibility(ctx.QueryInt64("id")); err != nil {
if err := models.ToggleUserOpenIDVisibility(ctx.FormInt64("id")); err != nil {
ctx.ServerError("ToggleUserOpenIDVisibility", err)
return
}