Forms are dependent on models and therefore should be in services.
This PR also removes the old auth. aliasing
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
"time"
"code.gitea.io/gitea/models"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/queue"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/services/forms"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
return func(t *testing.T) {
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge?token=%s",
owner, repo, index, ctx.Token)
- req := NewRequestWithJSON(t, http.MethodPost, urlStr, &auth.MergePullRequestForm{
+ req := NewRequestWithJSON(t, http.MethodPost, urlStr, &forms.MergePullRequestForm{
MergeMessageField: "doAPIMergePullRequest Merge",
Do: string(models.MergeStyleMerge),
})
DecodeJSON(t, resp, &err)
assert.EqualValues(t, "Please try again later", err.Message)
queue.GetManager().FlushAll(context.Background(), 5*time.Second)
- req = NewRequestWithJSON(t, http.MethodPost, urlStr, &auth.MergePullRequestForm{
+ req = NewRequestWithJSON(t, http.MethodPost, urlStr, &forms.MergePullRequestForm{
MergeMessageField: "doAPIMergePullRequest Merge",
Do: string(models.MergeStyleMerge),
})
return func(t *testing.T) {
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge?token=%s",
owner, repo, index, ctx.Token)
- req := NewRequestWithJSON(t, http.MethodPost, urlStr, &auth.MergePullRequestForm{
+ req := NewRequestWithJSON(t, http.MethodPost, urlStr, &forms.MergePullRequestForm{
Do: string(models.MergeStyleManuallyMerged),
MergeCommitID: commitID,
})
"testing"
"code.gitea.io/gitea/models"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/services/forms"
issue_service "code.gitea.io/gitea/services/issue"
"github.com/stretchr/testify/assert"
session := loginUser(t, owner.Name)
token := getTokenForLoggedInUser(t, session)
- req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge?token=%s", owner.Name, repo.Name, pr.Index, token), &auth.MergePullRequestForm{
+ req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge?token=%s", owner.Name, repo.Name, pr.Index, token), &forms.MergePullRequestForm{
MergeMessageField: pr.Issue.Title,
Do: string(models.MergeStyleMerge),
})
+++ /dev/null
-// Copyright 2014 The Gogs Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package forms
-
-import (
- "net/http"
-
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/web/middleware"
-
- "gitea.com/go-chi/binding"
-)
-
-// AdminCreateUserForm form for admin to create user
-type AdminCreateUserForm struct {
- LoginType string `binding:"Required"`
- LoginName string
- UserName string `binding:"Required;AlphaDashDot;MaxSize(40)"`
- Email string `binding:"Required;Email;MaxSize(254)"`
- Password string `binding:"MaxSize(255)"`
- SendNotify bool
- MustChangePassword bool
-}
-
-// Validate validates form fields
-func (f *AdminCreateUserForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// AdminEditUserForm form for admin to create user
-type AdminEditUserForm struct {
- LoginType string `binding:"Required"`
- UserName string `binding:"AlphaDashDot;MaxSize(40)"`
- LoginName string
- FullName string `binding:"MaxSize(100)"`
- Email string `binding:"Required;Email;MaxSize(254)"`
- Password string `binding:"MaxSize(255)"`
- Website string `binding:"ValidUrl;MaxSize(255)"`
- Location string `binding:"MaxSize(50)"`
- MaxRepoCreation int
- Active bool
- Admin bool
- Restricted bool
- AllowGitHook bool
- AllowImportLocal bool
- AllowCreateOrganization bool
- ProhibitLogin bool
- Reset2FA bool `form:"reset_2fa"`
-}
-
-// Validate validates form fields
-func (f *AdminEditUserForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// AdminDashboardForm form for admin dashboard operations
-type AdminDashboardForm struct {
- Op string `binding:"required"`
- From string
-}
-
-// Validate validates form fields
-func (f *AdminDashboardForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
+++ /dev/null
-// Copyright 2014 The Gogs Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package forms
-
-import (
- "net/http"
-
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/web/middleware"
-
- "gitea.com/go-chi/binding"
-)
-
-// AuthenticationForm form for authentication
-type AuthenticationForm struct {
- ID int64
- Type int `binding:"Range(2,7)"`
- Name string `binding:"Required;MaxSize(30)"`
- Host string
- Port int
- BindDN string
- BindPassword string
- UserBase string
- UserDN string
- AttributeUsername string
- AttributeName string
- AttributeSurname string
- AttributeMail string
- AttributeSSHPublicKey string
- AttributesInBind bool
- UsePagedSearch bool
- SearchPageSize int
- Filter string
- AdminFilter string
- GroupsEnabled bool
- GroupDN string
- GroupFilter string
- GroupMemberUID string
- UserUID string
- RestrictedFilter string
- AllowDeactivateAll bool
- IsActive bool
- IsSyncEnabled bool
- SMTPAuth string
- SMTPHost string
- SMTPPort int
- AllowedDomains string
- SecurityProtocol int `binding:"Range(0,2)"`
- TLS bool
- SkipVerify bool
- PAMServiceName string
- Oauth2Provider string
- Oauth2Key string
- Oauth2Secret string
- OpenIDConnectAutoDiscoveryURL string
- Oauth2UseCustomURL bool
- Oauth2TokenURL string
- Oauth2AuthURL string
- Oauth2ProfileURL string
- Oauth2EmailURL string
- Oauth2IconURL string
- SSPIAutoCreateUsers bool
- SSPIAutoActivateUsers bool
- SSPIStripDomainNames bool
- SSPISeparatorReplacement string `binding:"AlphaDashDot;MaxSize(5)"`
- SSPIDefaultLanguage string
-}
-
-// Validate validates fields
-func (f *AuthenticationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
+++ /dev/null
-// Copyright 2014 The Gogs Authors. All rights reserved.
-// Copyright 2019 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package forms
-
-import (
- "net/http"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/structs"
- "code.gitea.io/gitea/modules/web/middleware"
-
- "gitea.com/go-chi/binding"
-)
-
-// ________ .__ __ .__
-// \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
-// / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
-// / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
-// \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
-// \/ /_____/ \/ \/ \/ \/ \/
-
-// CreateOrgForm form for creating organization
-type CreateOrgForm struct {
- OrgName string `binding:"Required;AlphaDashDot;MaxSize(40)" locale:"org.org_name_holder"`
- Visibility structs.VisibleType
- RepoAdminChangeTeamAccess bool
-}
-
-// Validate validates the fields
-func (f *CreateOrgForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// UpdateOrgSettingForm form for updating organization settings
-type UpdateOrgSettingForm struct {
- Name string `binding:"Required;AlphaDashDot;MaxSize(40)" locale:"org.org_name_holder"`
- FullName string `binding:"MaxSize(100)"`
- Description string `binding:"MaxSize(255)"`
- Website string `binding:"ValidUrl;MaxSize(255)"`
- Location string `binding:"MaxSize(50)"`
- Visibility structs.VisibleType
- MaxRepoCreation int
- RepoAdminChangeTeamAccess bool
-}
-
-// Validate validates the fields
-func (f *UpdateOrgSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// ___________
-// \__ ___/___ _____ _____
-// | |_/ __ \\__ \ / \
-// | |\ ___/ / __ \| Y Y \
-// |____| \___ >____ /__|_| /
-// \/ \/ \/
-
-// CreateTeamForm form for creating team
-type CreateTeamForm struct {
- TeamName string `binding:"Required;AlphaDashDot;MaxSize(30)"`
- Description string `binding:"MaxSize(255)"`
- Permission string
- Units []models.UnitType
- RepoAccess string
- CanCreateOrgRepo bool
-}
-
-// Validate validates the fields
-func (f *CreateTeamForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
+++ /dev/null
-// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package forms
-
-import (
- "net/http"
-
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/web/middleware"
-
- "gitea.com/go-chi/binding"
-)
-
-// NewBranchForm form for creating a new branch
-type NewBranchForm struct {
- NewBranchName string `binding:"Required;MaxSize(100);GitRefName"`
- CreateTag bool
-}
-
-// Validate validates the fields
-func (f *NewBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
+++ /dev/null
-// Copyright 2014 The Gogs Authors. All rights reserved.
-// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package forms
-
-import (
- "net/http"
- "net/url"
- "strings"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/structs"
- "code.gitea.io/gitea/modules/web/middleware"
- "code.gitea.io/gitea/routers/utils"
-
- "gitea.com/go-chi/binding"
-)
-
-// _______________________________________ _________.______________________ _______________.___.
-// \______ \_ _____/\______ \_____ \ / _____/| \__ ___/\_____ \\______ \__ | |
-// | _/| __)_ | ___// | \ \_____ \ | | | | / | \| _// | |
-// | | \| \ | | / | \/ \| | | | / | \ | \\____ |
-// |____|_ /_______ / |____| \_______ /_______ /|___| |____| \_______ /____|_ // ______|
-// \/ \/ \/ \/ \/ \/ \/
-
-// CreateRepoForm form for creating repository
-type CreateRepoForm struct {
- UID int64 `binding:"Required"`
- RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
- Private bool
- Description string `binding:"MaxSize(255)"`
- DefaultBranch string `binding:"GitRefName;MaxSize(100)"`
- AutoInit bool
- Gitignores string
- IssueLabels string
- License string
- Readme string
- Template bool
-
- RepoTemplate int64
- GitContent bool
- Topics bool
- GitHooks bool
- Webhooks bool
- Avatar bool
- Labels bool
- TrustModel string
-}
-
-// Validate validates the fields
-func (f *CreateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// MigrateRepoForm form for migrating repository
-// this is used to interact with web ui
-type MigrateRepoForm struct {
- // required: true
- CloneAddr string `json:"clone_addr" binding:"Required"`
- Service structs.GitServiceType `json:"service"`
- AuthUsername string `json:"auth_username"`
- AuthPassword string `json:"auth_password"`
- AuthToken string `json:"auth_token"`
- // required: true
- UID int64 `json:"uid" binding:"Required"`
- // required: true
- RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
- Mirror bool `json:"mirror"`
- Private bool `json:"private"`
- Description string `json:"description" binding:"MaxSize(255)"`
- Wiki bool `json:"wiki"`
- Milestones bool `json:"milestones"`
- Labels bool `json:"labels"`
- Issues bool `json:"issues"`
- PullRequests bool `json:"pull_requests"`
- Releases bool `json:"releases"`
- MirrorInterval string `json:"mirror_interval"`
-}
-
-// Validate validates the fields
-func (f *MigrateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// ParseRemoteAddr checks if given remote address is valid,
-// and returns composed URL with needed username and password.
-func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, error) {
- remoteAddr = strings.TrimSpace(remoteAddr)
- // Remote address can be HTTP/HTTPS/Git URL or local path.
- if strings.HasPrefix(remoteAddr, "http://") ||
- strings.HasPrefix(remoteAddr, "https://") ||
- strings.HasPrefix(remoteAddr, "git://") {
- u, err := url.Parse(remoteAddr)
- if err != nil {
- return "", &models.ErrInvalidCloneAddr{IsURLError: true}
- }
- if len(authUsername)+len(authPassword) > 0 {
- u.User = url.UserPassword(authUsername, authPassword)
- }
- remoteAddr = u.String()
- }
-
- return remoteAddr, nil
-}
-
-// RepoSettingForm form for changing repository settings
-type RepoSettingForm struct {
- RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
- Description string `binding:"MaxSize(255)"`
- Website string `binding:"ValidUrl;MaxSize(255)"`
- Interval string
- MirrorAddress string
- MirrorUsername string
- MirrorPassword string
- Private bool
- Template bool
- EnablePrune bool
-
- // Advanced settings
- EnableWiki bool
- EnableExternalWiki bool
- ExternalWikiURL string
- EnableIssues bool
- EnableExternalTracker bool
- ExternalTrackerURL string
- TrackerURLFormat string
- TrackerIssueStyle string
- EnableCloseIssuesViaCommitInAnyBranch bool
- EnableProjects bool
- EnablePulls bool
- PullsIgnoreWhitespace bool
- PullsAllowMerge bool
- PullsAllowRebase bool
- PullsAllowRebaseMerge bool
- PullsAllowSquash bool
- PullsAllowManualMerge bool
- PullsDefaultMergeStyle string
- EnableAutodetectManualMerge bool
- EnableTimetracker bool
- AllowOnlyContributorsToTrackTime bool
- EnableIssueDependencies bool
- IsArchived bool
-
- // Signing Settings
- TrustModel string
-
- // Admin settings
- EnableHealthCheck bool
-}
-
-// Validate validates the fields
-func (f *RepoSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// __________ .__
-// \______ \____________ ____ ____ | |__
-// | | _/\_ __ \__ \ / \_/ ___\| | \
-// | | \ | | \// __ \| | \ \___| Y \
-// |______ / |__| (____ /___| /\___ >___| /
-// \/ \/ \/ \/ \/
-
-// ProtectBranchForm form for changing protected branch settings
-type ProtectBranchForm struct {
- Protected bool
- EnablePush string
- WhitelistUsers string
- WhitelistTeams string
- WhitelistDeployKeys bool
- EnableMergeWhitelist bool
- MergeWhitelistUsers string
- MergeWhitelistTeams string
- EnableStatusCheck bool
- StatusCheckContexts []string
- RequiredApprovals int64
- EnableApprovalsWhitelist bool
- ApprovalsWhitelistUsers string
- ApprovalsWhitelistTeams string
- BlockOnRejectedReviews bool
- BlockOnOfficialReviewRequests bool
- BlockOnOutdatedBranch bool
- DismissStaleApprovals bool
- RequireSignedCommits bool
- ProtectedFilePatterns string
-}
-
-// Validate validates the fields
-func (f *ProtectBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// __ __ ___. .__ .__ __
-// / \ / \ ____\_ |__ | |__ | |__ ____ | | __
-// \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
-// \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
-// \__/\ / \___ >___ /___| /___| /\____/|__|_ \
-// \/ \/ \/ \/ \/ \/
-
-// WebhookForm form for changing web hook
-type WebhookForm struct {
- Events string
- Create bool
- Delete bool
- Fork bool
- Issues bool
- IssueAssign bool
- IssueLabel bool
- IssueMilestone bool
- IssueComment bool
- Release bool
- Push bool
- PullRequest bool
- PullRequestAssign bool
- PullRequestLabel bool
- PullRequestMilestone bool
- PullRequestComment bool
- PullRequestReview bool
- PullRequestSync bool
- Repository bool
- Active bool
- BranchFilter string `binding:"GlobPattern"`
-}
-
-// PushOnly if the hook will be triggered when push
-func (f WebhookForm) PushOnly() bool {
- return f.Events == "push_only"
-}
-
-// SendEverything if the hook will be triggered any event
-func (f WebhookForm) SendEverything() bool {
- return f.Events == "send_everything"
-}
-
-// ChooseEvents if the hook will be triggered choose events
-func (f WebhookForm) ChooseEvents() bool {
- return f.Events == "choose_events"
-}
-
-// NewWebhookForm form for creating web hook
-type NewWebhookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- HTTPMethod string `binding:"Required;In(POST,GET)"`
- ContentType int `binding:"Required"`
- Secret string
- WebhookForm
-}
-
-// Validate validates the fields
-func (f *NewWebhookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// NewGogshookForm form for creating gogs hook
-type NewGogshookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- ContentType int `binding:"Required"`
- Secret string
- WebhookForm
-}
-
-// Validate validates the fields
-func (f *NewGogshookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// NewSlackHookForm form for creating slack hook
-type NewSlackHookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- Channel string `binding:"Required"`
- Username string
- IconURL string
- Color string
- WebhookForm
-}
-
-// Validate validates the fields
-func (f *NewSlackHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// HasInvalidChannel validates the channel name is in the right format
-func (f NewSlackHookForm) HasInvalidChannel() bool {
- return !utils.IsValidSlackChannel(f.Channel)
-}
-
-// NewDiscordHookForm form for creating discord hook
-type NewDiscordHookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- Username string
- IconURL string
- WebhookForm
-}
-
-// Validate validates the fields
-func (f *NewDiscordHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// NewDingtalkHookForm form for creating dingtalk hook
-type NewDingtalkHookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- WebhookForm
-}
-
-// Validate validates the fields
-func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// NewTelegramHookForm form for creating telegram hook
-type NewTelegramHookForm struct {
- BotToken string `binding:"Required"`
- ChatID string `binding:"Required"`
- WebhookForm
-}
-
-// Validate validates the fields
-func (f *NewTelegramHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// NewMatrixHookForm form for creating Matrix hook
-type NewMatrixHookForm struct {
- HomeserverURL string `binding:"Required;ValidUrl"`
- RoomID string `binding:"Required"`
- AccessToken string `binding:"Required"`
- MessageType int
- WebhookForm
-}
-
-// Validate validates the fields
-func (f *NewMatrixHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// NewMSTeamsHookForm form for creating MS Teams hook
-type NewMSTeamsHookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- WebhookForm
-}
-
-// Validate validates the fields
-func (f *NewMSTeamsHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// NewFeishuHookForm form for creating feishu hook
-type NewFeishuHookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- WebhookForm
-}
-
-// Validate validates the fields
-func (f *NewFeishuHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// .___
-// | | ______ ________ __ ____
-// | |/ ___// ___/ | \_/ __ \
-// | |\___ \ \___ \| | /\ ___/
-// |___/____ >____ >____/ \___ >
-// \/ \/ \/
-
-// CreateIssueForm form for creating issue
-type CreateIssueForm struct {
- Title string `binding:"Required;MaxSize(255)"`
- LabelIDs string `form:"label_ids"`
- AssigneeIDs string `form:"assignee_ids"`
- Ref string `form:"ref"`
- MilestoneID int64
- ProjectID int64
- AssigneeID int64
- Content string
- Files []string
-}
-
-// Validate validates the fields
-func (f *CreateIssueForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// CreateCommentForm form for creating comment
-type CreateCommentForm struct {
- Content string
- Status string `binding:"OmitEmpty;In(reopen,close)"`
- Files []string
-}
-
-// Validate validates the fields
-func (f *CreateCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// ReactionForm form for adding and removing reaction
-type ReactionForm struct {
- Content string `binding:"Required"`
-}
-
-// Validate validates the fields
-func (f *ReactionForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// IssueLockForm form for locking an issue
-type IssueLockForm struct {
- Reason string `binding:"Required"`
-}
-
-// Validate validates the fields
-func (i *IssueLockForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, i, ctx.Locale)
-}
-
-// HasValidReason checks to make sure that the reason submitted in
-// the form matches any of the values in the config
-func (i IssueLockForm) HasValidReason() bool {
- if strings.TrimSpace(i.Reason) == "" {
- return true
- }
-
- for _, v := range setting.Repository.Issue.LockReasons {
- if v == i.Reason {
- return true
- }
- }
-
- return false
-}
-
-// __________ __ __
-// \______ \_______ ____ |__| ____ _____/ |_ ______
-// | ___/\_ __ \/ _ \ | |/ __ \_/ ___\ __\/ ___/
-// | | | | \( <_> ) | \ ___/\ \___| | \___ \
-// |____| |__| \____/\__| |\___ >\___ >__| /____ >
-// \______| \/ \/ \/
-
-// CreateProjectForm form for creating a project
-type CreateProjectForm struct {
- Title string `binding:"Required;MaxSize(100)"`
- Content string
- BoardType models.ProjectBoardType
-}
-
-// UserCreateProjectForm is a from for creating an individual or organization
-// form.
-type UserCreateProjectForm struct {
- Title string `binding:"Required;MaxSize(100)"`
- Content string
- BoardType models.ProjectBoardType
- UID int64 `binding:"Required"`
-}
-
-// EditProjectBoardForm is a form for editing a project board
-type EditProjectBoardForm struct {
- Title string `binding:"Required;MaxSize(100)"`
- Sorting int8
-}
-
-// _____ .__.__ __
-// / \ |__| | ____ _______/ |_ ____ ____ ____
-// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
-// / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
-// \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
-// \/ \/ \/ \/ \/
-
-// CreateMilestoneForm form for creating milestone
-type CreateMilestoneForm struct {
- Title string `binding:"Required;MaxSize(50)"`
- Content string
- Deadline string
-}
-
-// Validate validates the fields
-func (f *CreateMilestoneForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// .____ ___. .__
-// | | _____ \_ |__ ____ | |
-// | | \__ \ | __ \_/ __ \| |
-// | |___ / __ \| \_\ \ ___/| |__
-// |_______ (____ /___ /\___ >____/
-// \/ \/ \/ \/
-
-// CreateLabelForm form for creating label
-type CreateLabelForm struct {
- ID int64
- Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
- Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
- Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
-}
-
-// Validate validates the fields
-func (f *CreateLabelForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// InitializeLabelsForm form for initializing labels
-type InitializeLabelsForm struct {
- TemplateName string `binding:"Required"`
-}
-
-// Validate validates the fields
-func (f *InitializeLabelsForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// __________ .__ .__ __________ __
-// \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
-// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
-// | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
-// |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
-// \/ \/ |__| \/ \/
-
-// MergePullRequestForm form for merging Pull Request
-// swagger:model MergePullRequestOption
-type MergePullRequestForm struct {
- // required: true
- // enum: merge,rebase,rebase-merge,squash,manually-merged
- Do string `binding:"Required;In(merge,rebase,rebase-merge,squash,manually-merged)"`
- MergeTitleField string
- MergeMessageField string
- MergeCommitID string // only used for manually-merged
- ForceMerge *bool `json:"force_merge,omitempty"`
-}
-
-// Validate validates the fields
-func (f *MergePullRequestForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// CodeCommentForm form for adding code comments for PRs
-type CodeCommentForm struct {
- Origin string `binding:"Required;In(timeline,diff)"`
- Content string `binding:"Required"`
- Side string `binding:"Required;In(previous,proposed)"`
- Line int64
- TreePath string `form:"path" binding:"Required"`
- IsReview bool `form:"is_review"`
- Reply int64 `form:"reply"`
- LatestCommitID string
-}
-
-// Validate validates the fields
-func (f *CodeCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// SubmitReviewForm for submitting a finished code review
-type SubmitReviewForm struct {
- Content string
- Type string `binding:"Required;In(approve,comment,reject)"`
- CommitID string
-}
-
-// Validate validates the fields
-func (f *SubmitReviewForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// ReviewType will return the corresponding reviewtype for type
-func (f SubmitReviewForm) ReviewType() models.ReviewType {
- switch f.Type {
- case "approve":
- return models.ReviewTypeApprove
- case "comment":
- return models.ReviewTypeComment
- case "reject":
- return models.ReviewTypeReject
- default:
- return models.ReviewTypeUnknown
- }
-}
-
-// HasEmptyContent checks if the content of the review form is empty.
-func (f SubmitReviewForm) HasEmptyContent() bool {
- reviewType := f.ReviewType()
-
- return (reviewType == models.ReviewTypeComment || reviewType == models.ReviewTypeReject) &&
- len(strings.TrimSpace(f.Content)) == 0
-}
-
-// DismissReviewForm for dismissing stale review by repo admin
-type DismissReviewForm struct {
- ReviewID int64 `binding:"Required"`
- Message string
-}
-
-// __________ .__
-// \______ \ ____ | | ____ _____ ______ ____
-// | _// __ \| | _/ __ \\__ \ / ___// __ \
-// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
-// |____|_ /\___ >____/\___ >____ /____ >\___ >
-// \/ \/ \/ \/ \/ \/
-
-// NewReleaseForm form for creating release
-type NewReleaseForm struct {
- TagName string `binding:"Required;GitRefName;MaxSize(255)"`
- Target string `form:"tag_target" binding:"Required;MaxSize(255)"`
- Title string `binding:"Required;MaxSize(255)"`
- Content string
- Draft string
- TagOnly string
- Prerelease bool
- AddTagMsg bool
- Files []string
-}
-
-// Validate validates the fields
-func (f *NewReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// EditReleaseForm form for changing release
-type EditReleaseForm struct {
- Title string `form:"title" binding:"Required;MaxSize(255)"`
- Content string `form:"content"`
- Draft string `form:"draft"`
- Prerelease bool `form:"prerelease"`
- Files []string
-}
-
-// Validate validates the fields
-func (f *EditReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// __ __.__ __ .__
-// / \ / \__| | _|__|
-// \ \/\/ / | |/ / |
-// \ /| | <| |
-// \__/\ / |__|__|_ \__|
-// \/ \/
-
-// NewWikiForm form for creating wiki
-type NewWikiForm struct {
- Title string `binding:"Required"`
- Content string `binding:"Required"`
- Message string
-}
-
-// Validate validates the fields
-// FIXME: use code generation to generate this method.
-func (f *NewWikiForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// ___________ .___.__ __
-// \_ _____/ __| _/|__|/ |_
-// | __)_ / __ | | \ __\
-// | \/ /_/ | | || |
-// /_______ /\____ | |__||__|
-// \/ \/
-
-// EditRepoFileForm form for changing repository file
-type EditRepoFileForm struct {
- TreePath string `binding:"Required;MaxSize(500)"`
- Content string
- CommitSummary string `binding:"MaxSize(100)"`
- CommitMessage string
- CommitChoice string `binding:"Required;MaxSize(50)"`
- NewBranchName string `binding:"GitRefName;MaxSize(100)"`
- LastCommit string
- Signoff bool
-}
-
-// Validate validates the fields
-func (f *EditRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// EditPreviewDiffForm form for changing preview diff
-type EditPreviewDiffForm struct {
- Content string
-}
-
-// Validate validates the fields
-func (f *EditPreviewDiffForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// ____ ___ .__ .___
-// | | \______ | | _________ __| _/
-// | | /\____ \| | / _ \__ \ / __ |
-// | | / | |_> > |_( <_> ) __ \_/ /_/ |
-// |______/ | __/|____/\____(____ /\____ |
-// |__| \/ \/
-//
-
-// UploadRepoFileForm form for uploading repository file
-type UploadRepoFileForm struct {
- TreePath string `binding:"MaxSize(500)"`
- CommitSummary string `binding:"MaxSize(100)"`
- CommitMessage string
- CommitChoice string `binding:"Required;MaxSize(50)"`
- NewBranchName string `binding:"GitRefName;MaxSize(100)"`
- Files []string
- Signoff bool
-}
-
-// Validate validates the fields
-func (f *UploadRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// RemoveUploadFileForm form for removing uploaded file
-type RemoveUploadFileForm struct {
- File string `binding:"Required;MaxSize(50)"`
-}
-
-// Validate validates the fields
-func (f *RemoveUploadFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// ________ .__ __
-// \______ \ ____ | | _____/ |_ ____
-// | | \_/ __ \| | _/ __ \ __\/ __ \
-// | ` \ ___/| |_\ ___/| | \ ___/
-// /_______ /\___ >____/\___ >__| \___ >
-// \/ \/ \/ \/
-
-// DeleteRepoFileForm form for deleting repository file
-type DeleteRepoFileForm struct {
- CommitSummary string `binding:"MaxSize(100)"`
- CommitMessage string
- CommitChoice string `binding:"Required;MaxSize(50)"`
- NewBranchName string `binding:"GitRefName;MaxSize(100)"`
- LastCommit string
- Signoff bool
-}
-
-// Validate validates the fields
-func (f *DeleteRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// ___________.__ ___________ __
-// \__ ___/|__| _____ ____ \__ ___/___________ ____ | | __ ___________
-// | | | |/ \_/ __ \ | | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
-// | | | | Y Y \ ___/ | | | | \// __ \\ \___| <\ ___/| | \/
-// |____| |__|__|_| /\___ > |____| |__| (____ /\___ >__|_ \\___ >__|
-// \/ \/ \/ \/ \/ \/
-
-// AddTimeManuallyForm form that adds spent time manually.
-type AddTimeManuallyForm struct {
- Hours int `binding:"Range(0,1000)"`
- Minutes int `binding:"Range(0,1000)"`
-}
-
-// Validate validates the fields
-func (f *AddTimeManuallyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// SaveTopicForm form for save topics for repository
-type SaveTopicForm struct {
- Topics []string `binding:"topics;Required;"`
-}
-
-// DeadlineForm hold the validation rules for deadlines
-type DeadlineForm struct {
- DateString string `form:"date" binding:"Required;Size(10)"`
-}
-
-// Validate validates the fields
-func (f *DeadlineForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
+++ /dev/null
-// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package forms
-
-import (
- "testing"
-
- "code.gitea.io/gitea/modules/setting"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestSubmitReviewForm_IsEmpty(t *testing.T) {
-
- cases := []struct {
- form SubmitReviewForm
- expected bool
- }{
- // Approved PR with a comment shouldn't count as empty
- {SubmitReviewForm{Type: "approve", Content: "Awesome"}, false},
-
- // Approved PR without a comment shouldn't count as empty
- {SubmitReviewForm{Type: "approve", Content: ""}, false},
-
- // Rejected PR without a comment should count as empty
- {SubmitReviewForm{Type: "reject", Content: ""}, true},
-
- // Rejected PR with a comment shouldn't count as empty
- {SubmitReviewForm{Type: "reject", Content: "Awesome"}, false},
-
- // Comment review on a PR with a comment shouldn't count as empty
- {SubmitReviewForm{Type: "comment", Content: "Awesome"}, false},
-
- // Comment review on a PR without a comment should count as empty
- {SubmitReviewForm{Type: "comment", Content: ""}, true},
- }
-
- for _, v := range cases {
- assert.Equal(t, v.expected, v.form.HasEmptyContent())
- }
-}
-
-func TestIssueLock_HasValidReason(t *testing.T) {
-
- // Init settings
- _ = setting.Repository
-
- cases := []struct {
- form IssueLockForm
- expected bool
- }{
- {IssueLockForm{""}, true}, // an empty reason is accepted
- {IssueLockForm{"Off-topic"}, true},
- {IssueLockForm{"Too heated"}, true},
- {IssueLockForm{"Spam"}, true},
- {IssueLockForm{"Resolved"}, true},
-
- {IssueLockForm{"ZZZZ"}, false},
- {IssueLockForm{"I want to lock this issue"}, false},
- }
-
- for _, v := range cases {
- assert.Equal(t, v.expected, v.form.HasValidReason())
- }
-}
+++ /dev/null
-// Copyright 2014 The Gogs Authors. All rights reserved.
-// Copyright 2018 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package forms
-
-import (
- "mime/multipart"
- "net/http"
- "strings"
-
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/web/middleware"
-
- "gitea.com/go-chi/binding"
-)
-
-// InstallForm form for installation page
-type InstallForm struct {
- DbType string `binding:"Required"`
- DbHost string
- DbUser string
- DbPasswd string
- DbName string
- SSLMode string
- Charset string `binding:"Required;In(utf8,utf8mb4)"`
- DbPath string
- DbSchema string
-
- AppName string `binding:"Required" locale:"install.app_name"`
- RepoRootPath string `binding:"Required"`
- LFSRootPath string
- RunUser string `binding:"Required"`
- Domain string `binding:"Required"`
- SSHPort int
- HTTPPort string `binding:"Required"`
- AppURL string `binding:"Required"`
- LogRootPath string `binding:"Required"`
-
- SMTPHost string
- SMTPFrom string
- SMTPUser string `binding:"OmitEmpty;MaxSize(254)" locale:"install.mailer_user"`
- SMTPPasswd string
- RegisterConfirm bool
- MailNotify bool
-
- OfflineMode bool
- DisableGravatar bool
- EnableFederatedAvatar bool
- EnableOpenIDSignIn bool
- EnableOpenIDSignUp bool
- DisableRegistration bool
- AllowOnlyExternalRegistration bool
- EnableCaptcha bool
- RequireSignInView bool
- DefaultKeepEmailPrivate bool
- DefaultAllowCreateOrganization bool
- DefaultEnableTimetracking bool
- NoReplyAddress string
-
- PasswordAlgorithm string
-
- AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
- AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
- AdminConfirmPasswd string
- AdminEmail string `binding:"OmitEmpty;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
-}
-
-// Validate validates the fields
-func (f *InstallForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// _____ ____ _________________ ___
-// / _ \ | | \__ ___/ | \
-// / /_\ \| | / | | / ~ \
-// / | \ | / | | \ Y /
-// \____|__ /______/ |____| \___|_ /
-// \/ \/
-
-// RegisterForm form for registering
-type RegisterForm struct {
- UserName string `binding:"Required;AlphaDashDot;MaxSize(40)"`
- Email string `binding:"Required;Email;MaxSize(254)"`
- Password string `binding:"MaxSize(255)"`
- Retype string
- GRecaptchaResponse string `form:"g-recaptcha-response"`
- HcaptchaResponse string `form:"h-captcha-response"`
-}
-
-// Validate validates the fields
-func (f *RegisterForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// IsEmailDomainListed checks whether the domain of an email address
-// matches a list of domains
-func IsEmailDomainListed(list []string, email string) bool {
- if len(list) == 0 {
- return false
- }
-
- n := strings.LastIndex(email, "@")
- if n <= 0 {
- return false
- }
-
- domain := strings.ToLower(email[n+1:])
-
- for _, v := range list {
- if strings.ToLower(v) == domain {
- return true
- }
- }
-
- return false
-}
-
-// IsEmailDomainAllowed validates that the email address
-// provided by the user matches what has been configured .
-// The email is marked as allowed if it matches any of the
-// domains in the whitelist or if it doesn't match any of
-// domains in the blocklist, if any such list is not empty.
-func (f RegisterForm) IsEmailDomainAllowed() bool {
- if len(setting.Service.EmailDomainWhitelist) == 0 {
- return !IsEmailDomainListed(setting.Service.EmailDomainBlocklist, f.Email)
- }
-
- return IsEmailDomainListed(setting.Service.EmailDomainWhitelist, f.Email)
-}
-
-// MustChangePasswordForm form for updating your password after account creation
-// by an admin
-type MustChangePasswordForm struct {
- Password string `binding:"Required;MaxSize(255)"`
- Retype string
-}
-
-// Validate validates the fields
-func (f *MustChangePasswordForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// SignInForm form for signing in with user/password
-type SignInForm struct {
- UserName string `binding:"Required;MaxSize(254)"`
- // TODO remove required from password for SecondFactorAuthentication
- Password string `binding:"Required;MaxSize(255)"`
- Remember bool
-}
-
-// Validate validates the fields
-func (f *SignInForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// AuthorizationForm form for authorizing oauth2 clients
-type AuthorizationForm struct {
- ResponseType string `binding:"Required;In(code)"`
- ClientID string `binding:"Required"`
- RedirectURI string
- State string
- Scope string
- Nonce string
-
- // PKCE support
- CodeChallengeMethod string // S256, plain
- CodeChallenge string
-}
-
-// Validate validates the fields
-func (f *AuthorizationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// GrantApplicationForm form for authorizing oauth2 clients
-type GrantApplicationForm struct {
- ClientID string `binding:"Required"`
- RedirectURI string
- State string
- Scope string
- Nonce string
-}
-
-// Validate validates the fields
-func (f *GrantApplicationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// AccessTokenForm for issuing access tokens from authorization codes or refresh tokens
-type AccessTokenForm struct {
- GrantType string `json:"grant_type"`
- ClientID string `json:"client_id"`
- ClientSecret string `json:"client_secret"`
- RedirectURI string `json:"redirect_uri"`
- Code string `json:"code"`
- RefreshToken string `json:"refresh_token"`
-
- // PKCE support
- CodeVerifier string `json:"code_verifier"`
-}
-
-// Validate validates the fields
-func (f *AccessTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// __________________________________________.___ _______ ________ _________
-// / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
-// \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
-// / \ | \ | | | | | / | \ \_\ \/ \
-// /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
-// \/ \/ \/ \/ \/
-
-// UpdateProfileForm form for updating profile
-type UpdateProfileForm struct {
- Name string `binding:"AlphaDashDot;MaxSize(40)"`
- FullName string `binding:"MaxSize(100)"`
- KeepEmailPrivate bool
- Website string `binding:"ValidUrl;MaxSize(255)"`
- Location string `binding:"MaxSize(50)"`
- Language string
- Description string `binding:"MaxSize(255)"`
- KeepActivityPrivate bool
-}
-
-// Validate validates the fields
-func (f *UpdateProfileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// Avatar types
-const (
- AvatarLocal string = "local"
- AvatarByMail string = "bymail"
-)
-
-// AvatarForm form for changing avatar
-type AvatarForm struct {
- Source string
- Avatar *multipart.FileHeader
- Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
- Federavatar bool
-}
-
-// Validate validates the fields
-func (f *AvatarForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// AddEmailForm form for adding new email
-type AddEmailForm struct {
- Email string `binding:"Required;Email;MaxSize(254)"`
-}
-
-// Validate validates the fields
-func (f *AddEmailForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// UpdateThemeForm form for updating a users' theme
-type UpdateThemeForm struct {
- Theme string `binding:"Required;MaxSize(30)"`
-}
-
-// Validate validates the field
-func (f *UpdateThemeForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// IsThemeExists checks if the theme is a theme available in the config.
-func (f UpdateThemeForm) IsThemeExists() bool {
- var exists bool
-
- for _, v := range setting.UI.Themes {
- if strings.EqualFold(v, f.Theme) {
- exists = true
- break
- }
- }
-
- return exists
-}
-
-// ChangePasswordForm form for changing password
-type ChangePasswordForm struct {
- OldPassword string `form:"old_password" binding:"MaxSize(255)"`
- Password string `form:"password" binding:"Required;MaxSize(255)"`
- Retype string `form:"retype"`
-}
-
-// Validate validates the fields
-func (f *ChangePasswordForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// AddOpenIDForm is for changing openid uri
-type AddOpenIDForm struct {
- Openid string `binding:"Required;MaxSize(256)"`
-}
-
-// Validate validates the fields
-func (f *AddOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// AddKeyForm form for adding SSH/GPG key
-type AddKeyForm struct {
- Type string `binding:"OmitEmpty"`
- Title string `binding:"Required;MaxSize(50)"`
- Content string `binding:"Required"`
- IsWritable bool
-}
-
-// Validate validates the fields
-func (f *AddKeyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// NewAccessTokenForm form for creating access token
-type NewAccessTokenForm struct {
- Name string `binding:"Required;MaxSize(255)"`
-}
-
-// Validate validates the fields
-func (f *NewAccessTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// EditOAuth2ApplicationForm form for editing oauth2 applications
-type EditOAuth2ApplicationForm struct {
- Name string `binding:"Required;MaxSize(255)" form:"application_name"`
- RedirectURI string `binding:"Required" form:"redirect_uri"`
-}
-
-// Validate validates the fields
-func (f *EditOAuth2ApplicationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// TwoFactorAuthForm for logging in with 2FA token.
-type TwoFactorAuthForm struct {
- Passcode string `binding:"Required"`
-}
-
-// Validate validates the fields
-func (f *TwoFactorAuthForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// TwoFactorScratchAuthForm for logging in with 2FA scratch token.
-type TwoFactorScratchAuthForm struct {
- Token string `binding:"Required"`
-}
-
-// Validate validates the fields
-func (f *TwoFactorScratchAuthForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// U2FRegistrationForm for reserving an U2F name
-type U2FRegistrationForm struct {
- Name string `binding:"Required"`
-}
-
-// Validate validates the fields
-func (f *U2FRegistrationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// U2FDeleteForm for deleting U2F keys
-type U2FDeleteForm struct {
- ID int64 `binding:"Required"`
-}
-
-// Validate validates the fields
-func (f *U2FDeleteForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
+++ /dev/null
-// Copyright 2017 The Gitea Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package forms
-
-import (
- "net/http"
-
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/web/middleware"
- "gitea.com/go-chi/binding"
-)
-
-// SignInOpenIDForm form for signing in with OpenID
-type SignInOpenIDForm struct {
- Openid string `binding:"Required;MaxSize(256)"`
- Remember bool
-}
-
-// Validate validates the fields
-func (f *SignInOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// SignUpOpenIDForm form for signin up with OpenID
-type SignUpOpenIDForm struct {
- UserName string `binding:"Required;AlphaDashDot;MaxSize(40)"`
- Email string `binding:"Required;Email;MaxSize(254)"`
- GRecaptchaResponse string `form:"g-recaptcha-response"`
- HcaptchaResponse string `form:"h-captcha-response"`
-}
-
-// Validate validates the fields
-func (f *SignUpOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
-
-// ConnectOpenIDForm form for connecting an existing account to an OpenID URI
-type ConnectOpenIDForm struct {
- UserName string `binding:"Required;MaxSize(254)"`
- Password string `binding:"Required;MaxSize(255)"`
-}
-
-// Validate validates the fields
-func (f *ConnectOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
- ctx := context.GetContext(req)
- return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
-}
+++ /dev/null
-// Copyright 2018 The Gogs Authors. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package forms
-
-import (
- "testing"
-
- "code.gitea.io/gitea/modules/setting"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestRegisterForm_IsDomainAllowed_Empty(t *testing.T) {
- _ = setting.Service
-
- setting.Service.EmailDomainWhitelist = []string{}
-
- form := RegisterForm{}
-
- assert.True(t, form.IsEmailDomainAllowed())
-}
-
-func TestRegisterForm_IsDomainAllowed_InvalidEmail(t *testing.T) {
- _ = setting.Service
-
- setting.Service.EmailDomainWhitelist = []string{"gitea.io"}
-
- tt := []struct {
- email string
- }{
- {"securitygieqqq"},
- {"hdudhdd"},
- }
-
- for _, v := range tt {
- form := RegisterForm{Email: v.email}
-
- assert.False(t, form.IsEmailDomainAllowed())
- }
-}
-
-func TestRegisterForm_IsDomainAllowed_WhitelistedEmail(t *testing.T) {
- _ = setting.Service
-
- setting.Service.EmailDomainWhitelist = []string{"gitea.io"}
-
- tt := []struct {
- email string
- valid bool
- }{
- {"security@gitea.io", true},
- {"security@gITea.io", true},
- {"hdudhdd", false},
- {"seee@example.com", false},
- }
-
- for _, v := range tt {
- form := RegisterForm{Email: v.email}
-
- assert.Equal(t, v.valid, form.IsEmailDomainAllowed())
- }
-}
-
-func TestRegisterForm_IsDomainAllowed_BlocklistedEmail(t *testing.T) {
- _ = setting.Service
-
- setting.Service.EmailDomainWhitelist = []string{}
- setting.Service.EmailDomainBlocklist = []string{"gitea.io"}
-
- tt := []struct {
- email string
- valid bool
- }{
- {"security@gitea.io", false},
- {"security@gitea.example", true},
- {"hdudhdd", true},
- }
-
- for _, v := range tt {
- form := RegisterForm{Email: v.email}
-
- assert.Equal(t, v.valid, form.IsEmailDomainAllowed())
- }
-}
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/cron"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/mailer"
jsoniter "github.com/json-iterator/go"
// DashboardPost run an admin operation
func DashboardPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.AdminDashboardForm)
+ form := web.GetForm(ctx).(*forms.AdminDashboardForm)
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminDashboard"] = true
"code.gitea.io/gitea/modules/auth/pam"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
"xorm.io/xorm/convert"
)
ctx.HTML(http.StatusOK, tplAuthNew)
}
-func parseLDAPConfig(form auth.AuthenticationForm) *models.LDAPConfig {
+func parseLDAPConfig(form forms.AuthenticationForm) *models.LDAPConfig {
var pageSize uint32
if form.UsePagedSearch {
pageSize = uint32(form.SearchPageSize)
}
}
-func parseSMTPConfig(form auth.AuthenticationForm) *models.SMTPConfig {
+func parseSMTPConfig(form forms.AuthenticationForm) *models.SMTPConfig {
return &models.SMTPConfig{
Auth: form.SMTPAuth,
Host: form.SMTPHost,
}
}
-func parseOAuth2Config(form auth.AuthenticationForm) *models.OAuth2Config {
+func parseOAuth2Config(form forms.AuthenticationForm) *models.OAuth2Config {
var customURLMapping *oauth2.CustomURLMapping
if form.Oauth2UseCustomURL {
customURLMapping = &oauth2.CustomURLMapping{
}
}
-func parseSSPIConfig(ctx *context.Context, form auth.AuthenticationForm) (*models.SSPIConfig, error) {
+func parseSSPIConfig(ctx *context.Context, form forms.AuthenticationForm) (*models.SSPIConfig, error) {
if util.IsEmptyString(form.SSPISeparatorReplacement) {
ctx.Data["Err_SSPISeparatorReplacement"] = true
return nil, errors.New(ctx.Tr("form.SSPISeparatorReplacement") + ctx.Tr("form.require_error"))
// NewAuthSourcePost response for adding an auth source
func NewAuthSourcePost(ctx *context.Context) {
- form := *web.GetForm(ctx).(*auth.AuthenticationForm)
+ form := *web.GetForm(ctx).(*forms.AuthenticationForm)
ctx.Data["Title"] = ctx.Tr("admin.auths.new")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true
// EditAuthSourcePost response for editing auth source
func EditAuthSourcePost(ctx *context.Context) {
- form := *web.GetForm(ctx).(*auth.AuthenticationForm)
+ form := *web.GetForm(ctx).(*forms.AuthenticationForm)
ctx.Data["Title"] = ctx.Tr("admin.auths.edit")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminAuthentications"] = true
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/password"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers"
router_user_setting "code.gitea.io/gitea/routers/user/setting"
+ "code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/mailer"
)
// NewUserPost response for adding a new user
func NewUserPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.AdminCreateUserForm)
+ form := web.GetForm(ctx).(*forms.AdminCreateUserForm)
ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true
// EditUserPost response for editting user
func EditUserPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.AdminEditUserForm)
+ form := web.GetForm(ctx).(*forms.AdminEditUserForm)
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true
"testing"
"code.gitea.io/gitea/models"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
"github.com/stretchr/testify/assert"
)
username := "gitea"
email := "gitea@gitea.io"
- form := auth.AdminCreateUserForm{
+ form := forms.AdminCreateUserForm{
LoginType: "local",
LoginName: "local",
UserName: username,
username := "gitea"
email := "gitea@gitea.io"
- form := auth.AdminCreateUserForm{
+ form := forms.AdminCreateUserForm{
LoginType: "local",
LoginName: "local",
UserName: username,
username := "gitea"
email := "gitea@gitea.io\r\n"
- form := auth.AdminCreateUserForm{
+ form := forms.AdminCreateUserForm{
LoginType: "local",
LoginName: "local",
UserName: username,
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/settings"
_ "code.gitea.io/gitea/routers/api/v1/swagger" // for swagger generation
"code.gitea.io/gitea/routers/api/v1/user"
+ "code.gitea.io/gitea/services/forms"
"gitea.com/go-chi/binding"
"gitea.com/go-chi/session"
m.Get(".patch", repo.DownloadPullPatch)
m.Post("/update", reqToken(), repo.UpdatePullRequest)
m.Combo("/merge").Get(repo.IsPullRequestMerged).
- Post(reqToken(), mustNotBeArchived, bind(auth.MergePullRequestForm{}), repo.MergePullRequest)
+ Post(reqToken(), mustNotBeArchived, bind(forms.MergePullRequestForm{}), repo.MergePullRequest)
m.Group("/reviews", func() {
m.Combo("").
Get(repo.ListPullReviews).
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/migrations"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
)
// Migrate migrate remote git repository to gitea
}
}
- remoteAddr, err := auth.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
+ remoteAddr, err := forms.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
if err == nil {
err = migrations.IsMigrateURLAllowed(remoteAddr, ctx.User)
}
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils"
+ "code.gitea.io/gitea/services/forms"
issue_service "code.gitea.io/gitea/services/issue"
pull_service "code.gitea.io/gitea/services/pull"
)
// "409":
// "$ref": "#/responses/error"
- form := web.GetForm(ctx).(*auth.MergePullRequestForm)
+ form := web.GetForm(ctx).(*forms.MergePullRequestForm)
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrPullRequestNotExist(err) {
package swagger
import (
- auth "code.gitea.io/gitea/modules/forms"
api "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/services/forms"
)
// not actually a response, just a hack to get go-swagger to include definitions
// in:body
EditPullRequestOption api.EditPullRequestOption
// in:body
- MergePullRequestOption auth.MergePullRequestForm
+ MergePullRequestOption forms.MergePullRequestForm
// in:body
CreateReleaseOption api.CreateReleaseOption
EditUserOption api.EditUserOption
// in:body
- MigrateRepoForm auth.MigrateRepoForm
+ MigrateRepoForm forms.MigrateRepoForm
// in:body
EditAttachmentOptions api.EditAttachmentOptions
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/generate"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/modules/web/middleware"
+ "code.gitea.io/gitea/services/forms"
"gitea.com/go-chi/session"
"gopkg.in/ini.v1"
// Install render installation page
func Install(ctx *context.Context) {
- form := auth.InstallForm{}
+ form := forms.InstallForm{}
// Database settings
form.DbHost = setting.Database.Host
// InstallPost response for submit install items
func InstallPost(ctx *context.Context) {
- form := *web.GetForm(ctx).(*auth.InstallForm)
+ form := *web.GetForm(ctx).(*forms.InstallForm)
var err error
ctx.Data["CurDbOption"] = form.DbType
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
)
const (
// CreatePost response for create organization
func CreatePost(ctx *context.Context) {
- form := *web.GetForm(ctx).(*auth.CreateOrgForm)
+ form := *web.GetForm(ctx).(*forms.CreateOrgForm)
ctx.Data["Title"] = ctx.Tr("new_org")
if !ctx.User.CanCreateOrganization() {
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
)
// RetrieveLabels find all the labels of an organization
// NewLabel create new label for organization
func NewLabel(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateLabelForm)
+ form := web.GetForm(ctx).(*forms.CreateLabelForm)
ctx.Data["Title"] = ctx.Tr("repo.labels")
ctx.Data["PageIsLabels"] = true
// UpdateLabel update a label's name and color
func UpdateLabel(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateLabelForm)
+ form := web.GetForm(ctx).(*forms.CreateLabelForm)
l, err := models.GetLabelInOrgByID(ctx.Org.Organization.ID, form.ID)
if err != nil {
switch {
// InitializeLabels init labels for an organization
func InitializeLabels(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.InitializeLabelsForm)
+ form := web.GetForm(ctx).(*forms.InitializeLabelsForm)
if ctx.HasError() {
ctx.Redirect(ctx.Repo.RepoLink + "/labels")
return
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
userSetting "code.gitea.io/gitea/routers/user/setting"
+ "code.gitea.io/gitea/services/forms"
)
const (
// SettingsPost response for settings change submited
func SettingsPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.UpdateOrgSettingForm)
+ form := web.GetForm(ctx).(*forms.UpdateOrgSettingForm)
ctx.Data["Title"] = ctx.Tr("org.settings")
ctx.Data["PageIsSettingsOptions"] = true
ctx.Data["CurrentVisibility"] = ctx.Org.Organization.Visibility
// SettingsAvatar response for change avatar on settings page
func SettingsAvatar(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.AvatarForm)
- form.Source = auth.AvatarLocal
+ form := web.GetForm(ctx).(*forms.AvatarForm)
+ form.Source = forms.AvatarLocal
if err := userSetting.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil {
ctx.Flash.Error(err.Error())
} else {
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/utils"
+ "code.gitea.io/gitea/services/forms"
)
const (
// NewTeamPost response for create new team
func NewTeamPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateTeamForm)
+ form := web.GetForm(ctx).(*forms.CreateTeamForm)
ctx.Data["Title"] = ctx.Org.Organization.FullName
ctx.Data["PageIsOrgTeams"] = true
ctx.Data["PageIsOrgTeamsNew"] = true
// EditTeamPost response for modify team information
func EditTeamPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateTeamForm)
+ form := web.GetForm(ctx).(*forms.CreateTeamForm)
t := ctx.Org.Team
ctx.Data["Title"] = ctx.Org.Organization.FullName
ctx.Data["PageIsOrgTeams"] = true
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/repofiles"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/utils"
+ "code.gitea.io/gitea/services/forms"
release_service "code.gitea.io/gitea/services/release"
repo_service "code.gitea.io/gitea/services/repository"
)
// CreateBranch creates new branch in repository
func CreateBranch(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewBranchForm)
+ form := web.GetForm(ctx).(*forms.NewBranchForm)
if !ctx.Repo.CanCreateBranch() {
ctx.NotFound("CreateBranch", nil)
return
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/repofiles"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/utils"
+ "code.gitea.io/gitea/services/forms"
jsoniter "github.com/json-iterator/go"
)
editFile(ctx, true)
}
-func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bool) {
+func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile bool) {
canCommit := renderCommitRights(ctx)
treeNames, treePaths := getParentTreeFields(form.TreePath)
branchName := ctx.Repo.BranchName
// EditFilePost response for editing file
func EditFilePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.EditRepoFileForm)
+ form := web.GetForm(ctx).(*forms.EditRepoFileForm)
editFilePost(ctx, *form, false)
}
// NewFilePost response for creating file
func NewFilePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.EditRepoFileForm)
+ form := web.GetForm(ctx).(*forms.EditRepoFileForm)
editFilePost(ctx, *form, true)
}
// DiffPreviewPost render preview diff page
func DiffPreviewPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.EditPreviewDiffForm)
+ form := web.GetForm(ctx).(*forms.EditPreviewDiffForm)
treePath := cleanUploadFileName(ctx.Repo.TreePath)
if len(treePath) == 0 {
ctx.Error(http.StatusInternalServerError, "file name to diff is invalid")
// DeleteFilePost response for deleting file
func DeleteFilePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.DeleteRepoFileForm)
+ form := web.GetForm(ctx).(*forms.DeleteRepoFileForm)
canCommit := renderCommitRights(ctx)
branchName := ctx.Repo.BranchName
if form.CommitChoice == frmCommitChoiceNewBranch {
// UploadFilePost response for uploading file
func UploadFilePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.UploadRepoFileForm)
+ form := web.GetForm(ctx).(*forms.UploadRepoFileForm)
ctx.Data["PageIsUpload"] = true
ctx.Data["RequireTribute"] = true
ctx.Data["RequireSimpleMDE"] = true
// RemoveUploadFileFromServer remove file from server file dir
func RemoveUploadFileFromServer(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.RemoveUploadFileForm)
+ form := web.GetForm(ctx).(*forms.RemoveUploadFileForm)
if len(form.File) == 0 {
ctx.Status(204)
return
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/git"
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
comment_service "code.gitea.io/gitea/services/comments"
+ "code.gitea.io/gitea/services/forms"
issue_service "code.gitea.io/gitea/services/issue"
pull_service "code.gitea.io/gitea/services/pull"
}
// ValidateRepoMetas check and returns repository's meta informations
-func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm, isPull bool) ([]int64, []int64, int64, int64) {
+func ValidateRepoMetas(ctx *context.Context, form forms.CreateIssueForm, isPull bool) ([]int64, []int64, int64, int64) {
var (
repo = ctx.Repo.Repository
err error
// NewIssuePost response for creating new issue
func NewIssuePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateIssueForm)
+ form := web.GetForm(ctx).(*forms.CreateIssueForm)
ctx.Data["Title"] = ctx.Tr("repo.issues.new")
ctx.Data["PageIsIssueList"] = true
ctx.Data["NewIssueChooseTemplate"] = len(ctx.IssueTemplatesFromDefaultBranch()) > 0
// NewComment create a comment for issue
func NewComment(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateCommentForm)
+ form := web.GetForm(ctx).(*forms.CreateCommentForm)
issue := GetActionIssue(ctx)
if ctx.Written() {
return
// ChangeIssueReaction create a reaction for issue
func ChangeIssueReaction(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.ReactionForm)
+ form := web.GetForm(ctx).(*forms.ReactionForm)
issue := GetActionIssue(ctx)
if ctx.Written() {
return
// ChangeCommentReaction create a reaction for comment
func ChangeCommentReaction(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.ReactionForm)
+ form := web.GetForm(ctx).(*forms.ReactionForm)
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
if err != nil {
ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err)
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
issue_service "code.gitea.io/gitea/services/issue"
)
// InitializeLabels init labels for a repository
func InitializeLabels(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.InitializeLabelsForm)
+ form := web.GetForm(ctx).(*forms.InitializeLabelsForm)
if ctx.HasError() {
ctx.Redirect(ctx.Repo.RepoLink + "/labels")
return
// NewLabel create new label for repository
func NewLabel(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateLabelForm)
+ form := web.GetForm(ctx).(*forms.CreateLabelForm)
ctx.Data["Title"] = ctx.Tr("repo.labels")
ctx.Data["PageIsLabels"] = true
// UpdateLabel update a label's name and color
func UpdateLabel(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateLabelForm)
+ form := web.GetForm(ctx).(*forms.CreateLabelForm)
l, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, form.ID)
if err != nil {
switch {
"testing"
"code.gitea.io/gitea/models"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
"github.com/stretchr/testify/assert"
)
ctx := test.MockContext(t, "user2/repo1/labels/initialize")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 2)
- web.SetForm(ctx, &auth.InitializeLabelsForm{TemplateName: "Default"})
+ web.SetForm(ctx, &forms.InitializeLabelsForm{TemplateName: "Default"})
InitializeLabels(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
models.AssertExistsAndLoadBean(t, &models.Label{
ctx := test.MockContext(t, "user2/repo1/labels/edit")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
- web.SetForm(ctx, &auth.CreateLabelForm{
+ web.SetForm(ctx, &forms.CreateLabelForm{
Title: "newlabel",
Color: "#abcdef",
})
ctx := test.MockContext(t, "user2/repo1/labels/edit")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
- web.SetForm(ctx, &auth.CreateLabelForm{
+ web.SetForm(ctx, &forms.CreateLabelForm{
ID: 2,
Title: "newnameforlabel",
Color: "#abcdef",
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
)
// LockIssue locks an issue. This would limit commenting abilities to
// users with write access to the repo.
func LockIssue(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.IssueLockForm)
+ form := web.GetForm(ctx).(*forms.IssueLockForm)
issue := GetActionIssue(ctx)
if ctx.Written() {
return
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
)
// AddTimeManually tracks time manually
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/migrations"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/task"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
)
const (
ctx.HTML(http.StatusOK, base.TplName("repo/migrate/"+serviceType.Name()))
}
-func handleMigrateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form *auth.MigrateRepoForm) {
+func handleMigrateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form *forms.MigrateRepoForm) {
if setting.Repository.DisableMigrations {
ctx.Error(http.StatusForbidden, "MigrateError: the site administrator has disabled migrations")
return
ctx.Data["Err_RepoName"] = true
ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form)
default:
- remoteAddr, _ := auth.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
+ remoteAddr, _ := forms.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
err = util.URLSanitizedError(err, remoteAddr)
if strings.Contains(err.Error(), "Authentication failed") ||
strings.Contains(err.Error(), "Bad credentials") ||
// MigratePost response for migrating from external git repository
func MigratePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.MigrateRepoForm)
+ form := web.GetForm(ctx).(*forms.MigrateRepoForm)
if setting.Repository.DisableMigrations {
ctx.Error(http.StatusForbidden, "MigratePost: the site administrator has disabled migrations")
return
return
}
- remoteAddr, err := auth.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
+ remoteAddr, err := forms.ParseRemoteAddr(form.CloneAddr, form.AuthUsername, form.AuthPassword)
if err == nil {
err = migrations.IsMigrateURLAllowed(remoteAddr, ctx.User)
}
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
"xorm.io/builder"
)
// NewMilestonePost response for creating milestone
func NewMilestonePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateMilestoneForm)
+ form := web.GetForm(ctx).(*forms.CreateMilestoneForm)
ctx.Data["Title"] = ctx.Tr("repo.milestones.new")
ctx.Data["PageIsIssueList"] = true
ctx.Data["PageIsMilestones"] = true
// EditMilestonePost response for edting milestone
func EditMilestonePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateMilestoneForm)
+ form := web.GetForm(ctx).(*forms.CreateMilestoneForm)
ctx.Data["Title"] = ctx.Tr("repo.milestones.edit")
ctx.Data["PageIsMilestones"] = true
ctx.Data["PageIsEditMilestone"] = true
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
)
const (
// NewProjectPost creates a new project
func NewProjectPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateProjectForm)
+ form := web.GetForm(ctx).(*forms.CreateProjectForm)
ctx.Data["Title"] = ctx.Tr("repo.projects.new")
if ctx.HasError() {
// EditProjectPost response for editing a project
func EditProjectPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateProjectForm)
+ form := web.GetForm(ctx).(*forms.CreateProjectForm)
ctx.Data["Title"] = ctx.Tr("repo.projects.edit")
ctx.Data["PageIsProjects"] = true
ctx.Data["PageIsEditProjects"] = true
// AddBoardToProjectPost allows a new board to be added to a project.
func AddBoardToProjectPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.EditProjectBoardForm)
+ form := web.GetForm(ctx).(*forms.EditProjectBoardForm)
if !ctx.Repo.IsOwner() && !ctx.Repo.IsAdmin() && !ctx.Repo.CanAccess(models.AccessModeWrite, models.UnitTypeProjects) {
ctx.JSON(http.StatusForbidden, map[string]string{
"message": "Only authorized users are allowed to perform this action.",
// EditProjectBoard allows a project board's to be updated
func EditProjectBoard(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.EditProjectBoardForm)
+ form := web.GetForm(ctx).(*forms.EditProjectBoardForm)
_, board := checkProjectBoardChangePermissions(ctx)
if ctx.Written() {
return
}
// CreateProjectPost creates an individual and/or organization project
-func CreateProjectPost(ctx *context.Context, form auth.UserCreateProjectForm) {
+func CreateProjectPost(ctx *context.Context, form forms.UserCreateProjectForm) {
user := checkContextUser(ctx, form.UID)
if ctx.Written() {
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/routers/utils"
+ "code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/gitdiff"
pull_service "code.gitea.io/gitea/services/pull"
repo_service "code.gitea.io/gitea/services/repository"
// ForkPost response for forking a repository
func ForkPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateRepoForm)
+ form := web.GetForm(ctx).(*forms.CreateRepoForm)
ctx.Data["Title"] = ctx.Tr("new_fork")
ctxUser := checkContextUser(ctx, form.UID)
// MergePullRequest response for merging pull request
func MergePullRequest(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.MergePullRequestForm)
+ form := web.GetForm(ctx).(*forms.MergePullRequestForm)
issue := checkPullInfo(ctx)
if ctx.Written() {
return
// CompareAndPullRequestPost response for creating pull request
func CompareAndPullRequestPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateIssueForm)
+ form := web.GetForm(ctx).(*forms.CreateIssueForm)
ctx.Data["Title"] = ctx.Tr("repo.pulls.compare_changes")
ctx.Data["PageIsComparePull"] = true
ctx.Data["IsDiffCompare"] = true
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
pull_service "code.gitea.io/gitea/services/pull"
)
// CreateCodeComment will create a code comment including an pending review if required
func CreateCodeComment(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CodeCommentForm)
+ form := web.GetForm(ctx).(*forms.CodeCommentForm)
issue := GetActionIssue(ctx)
if !issue.IsPull {
return
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
func SubmitReview(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.SubmitReviewForm)
+ form := web.GetForm(ctx).(*forms.SubmitReviewForm)
issue := GetActionIssue(ctx)
if !issue.IsPull {
return
// DismissReview dismissing stale review by repo admin
func DismissReview(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.DismissReviewForm)
+ form := web.GetForm(ctx).(*forms.DismissReviewForm)
comm, err := pull_service.DismissReview(form.ReviewID, form.Message, ctx.User, true)
if err != nil {
ctx.ServerError("pull_service.DismissReview", err)
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/upload"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
releaseservice "code.gitea.io/gitea/services/release"
)
// NewReleasePost response for creating a release
func NewReleasePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewReleaseForm)
+ form := web.GetForm(ctx).(*forms.NewReleaseForm)
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
ctx.Data["PageIsReleaseList"] = true
ctx.Data["RequireSimpleMDE"] = true
// EditReleasePost response for edit release
func EditReleasePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.EditReleaseForm)
+ form := web.GetForm(ctx).(*forms.EditReleaseForm)
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
ctx.Data["PageIsReleaseList"] = true
ctx.Data["PageIsEditRelease"] = true
"testing"
"code.gitea.io/gitea/models"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
)
func TestNewReleasePost(t *testing.T) {
RepoID int64
UserID int64
TagName string
- Form auth.NewReleaseForm
+ Form forms.NewReleaseForm
}{
{
RepoID: 1,
UserID: 2,
TagName: "v1.1", // pre-existing tag
- Form: auth.NewReleaseForm{
+ Form: forms.NewReleaseForm{
TagName: "newtag",
Target: "master",
Title: "title",
RepoID: 1,
UserID: 2,
TagName: "newtag",
- Form: auth.NewReleaseForm{
+ Form: forms.NewReleaseForm{
TagName: "newtag",
Target: "master",
Title: "title",
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
archiver_service "code.gitea.io/gitea/services/archiver"
+ "code.gitea.io/gitea/services/forms"
repo_service "code.gitea.io/gitea/services/repository"
)
// CreatePost response for creating repository
func CreatePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.CreateRepoForm)
+ form := web.GetForm(ctx).(*forms.CreateRepoForm)
ctx.Data["Title"] = ctx.Tr("new_repo")
ctx.Data["Gitignores"] = models.Gitignores
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/migrations"
"code.gitea.io/gitea/modules/validation"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/utils"
+ "code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/mailer"
mirror_service "code.gitea.io/gitea/services/mirror"
repo_service "code.gitea.io/gitea/services/repository"
// SettingsPost response for changes of a repository
func SettingsPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.RepoSettingForm)
+ form := web.GetForm(ctx).(*forms.RepoSettingForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsOptions"] = true
}
}
- address, err := auth.ParseRemoteAddr(form.MirrorAddress, form.MirrorUsername, form.MirrorPassword)
+ address, err := forms.ParseRemoteAddr(form.MirrorAddress, form.MirrorUsername, form.MirrorPassword)
if err == nil {
err = migrations.IsMigrateURLAllowed(address, ctx.User)
}
// DeployKeysPost response for adding a deploy key of a repository
func DeployKeysPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.AddKeyForm)
+ form := web.GetForm(ctx).(*forms.AddKeyForm)
ctx.Data["Title"] = ctx.Tr("repo.settings.deploy_keys")
ctx.Data["PageIsSettingsKeys"] = true
}
// UpdateAvatarSetting update repo's avatar
-func UpdateAvatarSetting(ctx *context.Context, form auth.AvatarForm) error {
+func UpdateAvatarSetting(ctx *context.Context, form forms.AvatarForm) error {
ctxRepo := ctx.Repo.Repository
if form.Avatar == nil {
// SettingsAvatar save new POSTed repository avatar
func SettingsAvatar(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.AvatarForm)
- form.Source = auth.AvatarLocal
+ form := web.GetForm(ctx).(*forms.AvatarForm)
+ form.Source = forms.AvatarLocal
if err := UpdateAvatarSetting(ctx, *form); err != nil {
ctx.Flash.Error(err.Error())
} else {
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
pull_service "code.gitea.io/gitea/services/pull"
)
// SettingsProtectedBranchPost updates the protected branch settings
func SettingsProtectedBranchPost(ctx *context.Context) {
- f := web.GetForm(ctx).(*auth.ProtectBranchForm)
+ f := web.GetForm(ctx).(*forms.ProtectBranchForm)
branch := ctx.Params("*")
if !ctx.Repo.GitRepo.IsBranchExist(branch) {
ctx.NotFound("IsBranchExist", nil)
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
"github.com/stretchr/testify/assert"
)
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 2)
- addKeyForm := auth.AddKeyForm{
+ addKeyForm := forms.AddKeyForm{
Title: "read-only",
Content: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn+iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr/cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ/5t5nJNMCNuLGT5UIo/RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL+tr1SZi/EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0/iE9Pb5fkWO9c4AnM1FgI/8Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE/jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ+K2/ioKgXqnXvltu0A9R8/LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM= nocomment\n",
}
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 2)
- addKeyForm := auth.AddKeyForm{
+ addKeyForm := forms.AddKeyForm{
Title: "read-write",
Content: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC4cn+iXnA4KvcQYSV88vGn0Yi91vG47t1P7okprVmhNTkipNRIHWr6WdCO4VDr/cvsRkuVJAsLO2enwjGWWueOO6BodiBgyAOZ/5t5nJNMCNuLGT5UIo/RI1b0WRQwxEZTRjt6mFNw6lH14wRd8ulsr9toSWBPMOGWoYs1PDeDL0JuTjL+tr1SZi/EyxCngpYszKdXllJEHyI79KQgeD0Vt3pTrkbNVTOEcCNqZePSVmUH8X8Vhugz3bnE0/iE9Pb5fkWO9c4AnM1FgI/8Bvp27Fw2ShryIXuR6kKvUqhVMTuOSDHwu6A8jLE5Owt3GAYugDpDYuwTVNGrHLXKpPzrGGPE/jPmaLCMZcsdkec95dYeU3zKODEm8UQZFhmJmDeWVJ36nGrGZHL4J5aTTaeFUJmmXDaJYiJ+K2/ioKgXqnXvltu0A9R8/LGy4nrTJRr4JMLuJFoUXvGm1gXQ70w2LSpk6yl71RNC0hCtsBe8BP8IhYCM0EP5jh7eCMQZNvM= nocomment\n",
IsWritable: true,
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/webhook"
jsoniter "github.com/json-iterator/go"
)
}
// ParseHookEvent convert web form content to models.HookEvent
-func ParseHookEvent(form auth.WebhookForm) *models.HookEvent {
+func ParseHookEvent(form forms.WebhookForm) *models.HookEvent {
return &models.HookEvent{
PushOnly: form.PushOnly(),
SendEverything: form.SendEverything(),
// GiteaHooksNewPost response for creating Gitea webhook
func GiteaHooksNewPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewWebhookForm)
+ form := web.GetForm(ctx).(*forms.NewWebhookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
// GogsHooksNewPost response for creating webhook
func GogsHooksNewPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewGogshookForm)
+ form := web.GetForm(ctx).(*forms.NewGogshookForm)
newGogsWebhookPost(ctx, *form, models.GOGS)
}
// newGogsWebhookPost response for creating gogs hook
-func newGogsWebhookPost(ctx *context.Context, form auth.NewGogshookForm, kind models.HookTaskType) {
+func newGogsWebhookPost(ctx *context.Context, form forms.NewGogshookForm, kind models.HookTaskType) {
ctx.Data["Title"] = ctx.Tr("repo.settings.add_webhook")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
// DiscordHooksNewPost response for creating discord hook
func DiscordHooksNewPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewDiscordHookForm)
+ form := web.GetForm(ctx).(*forms.NewDiscordHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
// DingtalkHooksNewPost response for creating dingtalk hook
func DingtalkHooksNewPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewDingtalkHookForm)
+ form := web.GetForm(ctx).(*forms.NewDingtalkHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
// TelegramHooksNewPost response for creating telegram hook
func TelegramHooksNewPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewTelegramHookForm)
+ form := web.GetForm(ctx).(*forms.NewTelegramHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
// MatrixHooksNewPost response for creating a Matrix hook
func MatrixHooksNewPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewMatrixHookForm)
+ form := web.GetForm(ctx).(*forms.NewMatrixHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
// MSTeamsHooksNewPost response for creating MS Teams hook
func MSTeamsHooksNewPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewMSTeamsHookForm)
+ form := web.GetForm(ctx).(*forms.NewMSTeamsHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
// SlackHooksNewPost response for creating slack hook
func SlackHooksNewPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewSlackHookForm)
+ form := web.GetForm(ctx).(*forms.NewSlackHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
// FeishuHooksNewPost response for creating feishu hook
func FeishuHooksNewPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewFeishuHookForm)
+ form := web.GetForm(ctx).(*forms.NewFeishuHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksNew"] = true
// WebHooksEditPost response for editing web hook
func WebHooksEditPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewWebhookForm)
+ form := web.GetForm(ctx).(*forms.NewWebhookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true
// GogsHooksEditPost response for editing gogs hook
func GogsHooksEditPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewGogshookForm)
+ form := web.GetForm(ctx).(*forms.NewGogshookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings.update_webhook")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true
// SlackHooksEditPost response for editing slack hook
func SlackHooksEditPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewSlackHookForm)
+ form := web.GetForm(ctx).(*forms.NewSlackHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true
// DiscordHooksEditPost response for editing discord hook
func DiscordHooksEditPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewDiscordHookForm)
+ form := web.GetForm(ctx).(*forms.NewDiscordHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true
// DingtalkHooksEditPost response for editing discord hook
func DingtalkHooksEditPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewDingtalkHookForm)
+ form := web.GetForm(ctx).(*forms.NewDingtalkHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true
// TelegramHooksEditPost response for editing discord hook
func TelegramHooksEditPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewTelegramHookForm)
+ form := web.GetForm(ctx).(*forms.NewTelegramHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true
// MatrixHooksEditPost response for editing a Matrix hook
func MatrixHooksEditPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewMatrixHookForm)
+ form := web.GetForm(ctx).(*forms.NewMatrixHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true
// MSTeamsHooksEditPost response for editing MS Teams hook
func MSTeamsHooksEditPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewMSTeamsHookForm)
+ form := web.GetForm(ctx).(*forms.NewMSTeamsHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true
// FeishuHooksEditPost response for editing feishu hook
func FeishuHooksEditPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewFeishuHookForm)
+ form := web.GetForm(ctx).(*forms.NewFeishuHookForm)
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsHooks"] = true
ctx.Data["PageIsSettingsHooksEdit"] = true
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
wiki_service "code.gitea.io/gitea/services/wiki"
)
// NewWikiPost response for wiki create request
func NewWikiPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewWikiForm)
+ form := web.GetForm(ctx).(*forms.NewWikiForm)
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
ctx.Data["PageIsWiki"] = true
ctx.Data["RequireSimpleMDE"] = true
// EditWikiPost response for wiki modify request
func EditWikiPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewWikiForm)
+ form := web.GetForm(ctx).(*forms.NewWikiForm)
ctx.Data["Title"] = ctx.Tr("repo.wiki.new_page")
ctx.Data["PageIsWiki"] = true
ctx.Data["RequireSimpleMDE"] = true
"testing"
"code.gitea.io/gitea/models"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
wiki_service "code.gitea.io/gitea/services/wiki"
"github.com/stretchr/testify/assert"
ctx := test.MockContext(t, "user2/repo1/wiki/_new")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
- web.SetForm(ctx, &auth.NewWikiForm{
+ web.SetForm(ctx, &forms.NewWikiForm{
Title: title,
Content: content,
Message: message,
ctx := test.MockContext(t, "user2/repo1/wiki/_new")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
- web.SetForm(ctx, &auth.NewWikiForm{
+ web.SetForm(ctx, &forms.NewWikiForm{
Title: "_edit",
Content: content,
Message: message,
ctx.SetParams(":page", "Home")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
- web.SetForm(ctx, &auth.NewWikiForm{
+ web.SetForm(ctx, &forms.NewWikiForm{
Title: title,
Content: content,
Message: message,
"net/http"
"path"
- "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/routers"
+ "code.gitea.io/gitea/services/forms"
"gitea.com/go-chi/session"
)
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/httpcache"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/routers/repo"
"code.gitea.io/gitea/routers/user"
userSetting "code.gitea.io/gitea/routers/user/setting"
+ "code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/mailer"
// to registers all internal adapters
// ***** START: User *****
m.Group("/user", func() {
m.Get("/login", user.SignIn)
- m.Post("/login", bindIgnErr(auth.SignInForm{}), user.SignInPost)
+ m.Post("/login", bindIgnErr(forms.SignInForm{}), user.SignInPost)
m.Group("", func() {
m.Combo("/login/openid").
Get(user.SignInOpenID).
- Post(bindIgnErr(auth.SignInOpenIDForm{}), user.SignInOpenIDPost)
+ Post(bindIgnErr(forms.SignInOpenIDForm{}), user.SignInOpenIDPost)
}, openIDSignInEnabled)
m.Group("/openid", func() {
m.Combo("/connect").
Get(user.ConnectOpenID).
- Post(bindIgnErr(auth.ConnectOpenIDForm{}), user.ConnectOpenIDPost)
+ Post(bindIgnErr(forms.ConnectOpenIDForm{}), user.ConnectOpenIDPost)
m.Group("/register", func() {
m.Combo("").
Get(user.RegisterOpenID, openIDSignUpEnabled).
- Post(bindIgnErr(auth.SignUpOpenIDForm{}), user.RegisterOpenIDPost)
+ Post(bindIgnErr(forms.SignUpOpenIDForm{}), user.RegisterOpenIDPost)
}, openIDSignUpEnabled)
}, openIDSignInEnabled)
m.Get("/sign_up", user.SignUp)
- m.Post("/sign_up", bindIgnErr(auth.RegisterForm{}), user.SignUpPost)
+ m.Post("/sign_up", bindIgnErr(forms.RegisterForm{}), user.SignUpPost)
m.Group("/oauth2", func() {
m.Get("/{provider}", user.SignInOAuth)
m.Get("/{provider}/callback", user.SignInOAuthCallback)
})
m.Get("/link_account", user.LinkAccount)
- m.Post("/link_account_signin", bindIgnErr(auth.SignInForm{}), user.LinkAccountPostSignIn)
- m.Post("/link_account_signup", bindIgnErr(auth.RegisterForm{}), user.LinkAccountPostRegister)
+ m.Post("/link_account_signin", bindIgnErr(forms.SignInForm{}), user.LinkAccountPostSignIn)
+ m.Post("/link_account_signup", bindIgnErr(forms.RegisterForm{}), user.LinkAccountPostRegister)
m.Group("/two_factor", func() {
m.Get("", user.TwoFactor)
- m.Post("", bindIgnErr(auth.TwoFactorAuthForm{}), user.TwoFactorPost)
+ m.Post("", bindIgnErr(forms.TwoFactorAuthForm{}), user.TwoFactorPost)
m.Get("/scratch", user.TwoFactorScratch)
- m.Post("/scratch", bindIgnErr(auth.TwoFactorScratchAuthForm{}), user.TwoFactorScratchPost)
+ m.Post("/scratch", bindIgnErr(forms.TwoFactorScratchAuthForm{}), user.TwoFactorScratchPost)
})
m.Group("/u2f", func() {
m.Get("", user.U2F)
m.Any("/user/events", events.Events)
m.Group("/login/oauth", func() {
- m.Get("/authorize", bindIgnErr(auth.AuthorizationForm{}), user.AuthorizeOAuth)
- m.Post("/grant", bindIgnErr(auth.GrantApplicationForm{}), user.GrantApplicationOAuth)
+ m.Get("/authorize", bindIgnErr(forms.AuthorizationForm{}), user.AuthorizeOAuth)
+ m.Post("/grant", bindIgnErr(forms.GrantApplicationForm{}), user.GrantApplicationOAuth)
// TODO manage redirection
- m.Post("/authorize", bindIgnErr(auth.AuthorizationForm{}), user.AuthorizeOAuth)
+ m.Post("/authorize", bindIgnErr(forms.AuthorizationForm{}), user.AuthorizeOAuth)
}, ignSignInAndCsrf, reqSignIn)
if setting.CORSConfig.Enabled {
m.Post("/login/oauth/access_token", cors.Handler(cors.Options{
AllowedMethods: setting.CORSConfig.Methods,
AllowCredentials: setting.CORSConfig.AllowCredentials,
MaxAge: int(setting.CORSConfig.MaxAge.Seconds()),
- }), bindIgnErr(auth.AccessTokenForm{}), ignSignInAndCsrf, user.AccessTokenOAuth)
+ }), bindIgnErr(forms.AccessTokenForm{}), ignSignInAndCsrf, user.AccessTokenOAuth)
} else {
- m.Post("/login/oauth/access_token", bindIgnErr(auth.AccessTokenForm{}), ignSignInAndCsrf, user.AccessTokenOAuth)
+ m.Post("/login/oauth/access_token", bindIgnErr(forms.AccessTokenForm{}), ignSignInAndCsrf, user.AccessTokenOAuth)
}
m.Group("/user/settings", func() {
m.Get("", userSetting.Profile)
- m.Post("", bindIgnErr(auth.UpdateProfileForm{}), userSetting.ProfilePost)
+ m.Post("", bindIgnErr(forms.UpdateProfileForm{}), userSetting.ProfilePost)
m.Get("/change_password", user.MustChangePassword)
- m.Post("/change_password", bindIgnErr(auth.MustChangePasswordForm{}), user.MustChangePasswordPost)
- m.Post("/avatar", bindIgnErr(auth.AvatarForm{}), userSetting.AvatarPost)
+ m.Post("/change_password", bindIgnErr(forms.MustChangePasswordForm{}), user.MustChangePasswordPost)
+ m.Post("/avatar", bindIgnErr(forms.AvatarForm{}), userSetting.AvatarPost)
m.Post("/avatar/delete", userSetting.DeleteAvatar)
m.Group("/account", func() {
- m.Combo("").Get(userSetting.Account).Post(bindIgnErr(auth.ChangePasswordForm{}), userSetting.AccountPost)
- m.Post("/email", bindIgnErr(auth.AddEmailForm{}), userSetting.EmailPost)
+ m.Combo("").Get(userSetting.Account).Post(bindIgnErr(forms.ChangePasswordForm{}), userSetting.AccountPost)
+ m.Post("/email", bindIgnErr(forms.AddEmailForm{}), userSetting.EmailPost)
m.Post("/email/delete", userSetting.DeleteEmail)
m.Post("/delete", userSetting.DeleteAccount)
- m.Post("/theme", bindIgnErr(auth.UpdateThemeForm{}), userSetting.UpdateUIThemePost)
+ m.Post("/theme", bindIgnErr(forms.UpdateThemeForm{}), userSetting.UpdateUIThemePost)
})
m.Group("/security", func() {
m.Get("", userSetting.Security)
m.Post("/regenerate_scratch", userSetting.RegenerateScratchTwoFactor)
m.Post("/disable", userSetting.DisableTwoFactor)
m.Get("/enroll", userSetting.EnrollTwoFactor)
- m.Post("/enroll", bindIgnErr(auth.TwoFactorAuthForm{}), userSetting.EnrollTwoFactorPost)
+ m.Post("/enroll", bindIgnErr(forms.TwoFactorAuthForm{}), userSetting.EnrollTwoFactorPost)
})
m.Group("/u2f", func() {
- m.Post("/request_register", bindIgnErr(auth.U2FRegistrationForm{}), userSetting.U2FRegister)
+ m.Post("/request_register", bindIgnErr(forms.U2FRegistrationForm{}), userSetting.U2FRegister)
m.Post("/register", bindIgnErr(u2f.RegisterResponse{}), userSetting.U2FRegisterPost)
- m.Post("/delete", bindIgnErr(auth.U2FDeleteForm{}), userSetting.U2FDelete)
+ m.Post("/delete", bindIgnErr(forms.U2FDeleteForm{}), userSetting.U2FDelete)
})
m.Group("/openid", func() {
- m.Post("", bindIgnErr(auth.AddOpenIDForm{}), userSetting.OpenIDPost)
+ m.Post("", bindIgnErr(forms.AddOpenIDForm{}), userSetting.OpenIDPost)
m.Post("/delete", userSetting.DeleteOpenID)
m.Post("/toggle_visibility", userSetting.ToggleOpenIDVisibility)
}, openIDSignInEnabled)
})
m.Group("/applications/oauth2", func() {
m.Get("/{id}", userSetting.OAuth2ApplicationShow)
- m.Post("/{id}", bindIgnErr(auth.EditOAuth2ApplicationForm{}), userSetting.OAuthApplicationsEdit)
+ m.Post("/{id}", bindIgnErr(forms.EditOAuth2ApplicationForm{}), userSetting.OAuthApplicationsEdit)
m.Post("/{id}/regenerate_secret", userSetting.OAuthApplicationsRegenerateSecret)
- m.Post("", bindIgnErr(auth.EditOAuth2ApplicationForm{}), userSetting.OAuthApplicationsPost)
+ m.Post("", bindIgnErr(forms.EditOAuth2ApplicationForm{}), userSetting.OAuthApplicationsPost)
m.Post("/delete", userSetting.DeleteOAuth2Application)
m.Post("/revoke", userSetting.RevokeOAuth2Grant)
})
m.Combo("/applications").Get(userSetting.Applications).
- Post(bindIgnErr(auth.NewAccessTokenForm{}), userSetting.ApplicationsPost)
+ Post(bindIgnErr(forms.NewAccessTokenForm{}), userSetting.ApplicationsPost)
m.Post("/applications/delete", userSetting.DeleteApplication)
m.Combo("/keys").Get(userSetting.Keys).
- Post(bindIgnErr(auth.AddKeyForm{}), userSetting.KeysPost)
+ Post(bindIgnErr(forms.AddKeyForm{}), userSetting.KeysPost)
m.Post("/keys/delete", userSetting.DeleteKey)
m.Get("/organization", userSetting.Organization)
m.Get("/repos", userSetting.Repos)
// ***** START: Admin *****
m.Group("/admin", func() {
m.Get("", adminReq, admin.Dashboard)
- m.Post("", adminReq, bindIgnErr(auth.AdminDashboardForm{}), admin.DashboardPost)
+ m.Post("", adminReq, bindIgnErr(forms.AdminDashboardForm{}), admin.DashboardPost)
m.Get("/config", admin.Config)
m.Post("/config/test_mail", admin.SendTestMail)
m.Group("/monitor", func() {
m.Group("/users", func() {
m.Get("", admin.Users)
- m.Combo("/new").Get(admin.NewUser).Post(bindIgnErr(auth.AdminCreateUserForm{}), admin.NewUserPost)
- m.Combo("/{userid}").Get(admin.EditUser).Post(bindIgnErr(auth.AdminEditUserForm{}), admin.EditUserPost)
+ m.Combo("/new").Get(admin.NewUser).Post(bindIgnErr(forms.AdminCreateUserForm{}), admin.NewUserPost)
+ m.Combo("/{userid}").Get(admin.EditUser).Post(bindIgnErr(forms.AdminEditUserForm{}), admin.EditUserPost)
m.Post("/{userid}/delete", admin.DeleteUser)
})
m.Get("", admin.DefaultOrSystemWebhooks)
m.Post("/delete", admin.DeleteDefaultOrSystemWebhook)
m.Get("/{id}", repo.WebHooksEdit)
- m.Post("/gitea/{id}", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
- m.Post("/gogs/{id}", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksEditPost)
- m.Post("/slack/{id}", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost)
- m.Post("/discord/{id}", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksEditPost)
- m.Post("/dingtalk/{id}", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksEditPost)
- m.Post("/telegram/{id}", bindIgnErr(auth.NewTelegramHookForm{}), repo.TelegramHooksEditPost)
- m.Post("/matrix/{id}", bindIgnErr(auth.NewMatrixHookForm{}), repo.MatrixHooksEditPost)
- m.Post("/msteams/{id}", bindIgnErr(auth.NewMSTeamsHookForm{}), repo.MSTeamsHooksEditPost)
- m.Post("/feishu/{id}", bindIgnErr(auth.NewFeishuHookForm{}), repo.FeishuHooksEditPost)
+ m.Post("/gitea/{id}", bindIgnErr(forms.NewWebhookForm{}), repo.WebHooksEditPost)
+ m.Post("/gogs/{id}", bindIgnErr(forms.NewGogshookForm{}), repo.GogsHooksEditPost)
+ m.Post("/slack/{id}", bindIgnErr(forms.NewSlackHookForm{}), repo.SlackHooksEditPost)
+ m.Post("/discord/{id}", bindIgnErr(forms.NewDiscordHookForm{}), repo.DiscordHooksEditPost)
+ m.Post("/dingtalk/{id}", bindIgnErr(forms.NewDingtalkHookForm{}), repo.DingtalkHooksEditPost)
+ m.Post("/telegram/{id}", bindIgnErr(forms.NewTelegramHookForm{}), repo.TelegramHooksEditPost)
+ m.Post("/matrix/{id}", bindIgnErr(forms.NewMatrixHookForm{}), repo.MatrixHooksEditPost)
+ m.Post("/msteams/{id}", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksEditPost)
+ m.Post("/feishu/{id}", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksEditPost)
}, webhooksEnabled)
m.Group("/{configType:default-hooks|system-hooks}", func() {
m.Get("/{type}/new", repo.WebhooksNew)
- m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.GiteaHooksNewPost)
- m.Post("/gogs/new", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksNewPost)
- m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost)
- m.Post("/discord/new", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksNewPost)
- m.Post("/dingtalk/new", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost)
- m.Post("/telegram/new", bindIgnErr(auth.NewTelegramHookForm{}), repo.TelegramHooksNewPost)
- m.Post("/matrix/new", bindIgnErr(auth.NewMatrixHookForm{}), repo.MatrixHooksNewPost)
- m.Post("/msteams/new", bindIgnErr(auth.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost)
- m.Post("/feishu/new", bindIgnErr(auth.NewFeishuHookForm{}), repo.FeishuHooksNewPost)
+ m.Post("/gitea/new", bindIgnErr(forms.NewWebhookForm{}), repo.GiteaHooksNewPost)
+ m.Post("/gogs/new", bindIgnErr(forms.NewGogshookForm{}), repo.GogsHooksNewPost)
+ m.Post("/slack/new", bindIgnErr(forms.NewSlackHookForm{}), repo.SlackHooksNewPost)
+ m.Post("/discord/new", bindIgnErr(forms.NewDiscordHookForm{}), repo.DiscordHooksNewPost)
+ m.Post("/dingtalk/new", bindIgnErr(forms.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost)
+ m.Post("/telegram/new", bindIgnErr(forms.NewTelegramHookForm{}), repo.TelegramHooksNewPost)
+ m.Post("/matrix/new", bindIgnErr(forms.NewMatrixHookForm{}), repo.MatrixHooksNewPost)
+ m.Post("/msteams/new", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost)
+ m.Post("/feishu/new", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksNewPost)
})
m.Group("/auths", func() {
m.Get("", admin.Authentications)
- m.Combo("/new").Get(admin.NewAuthSource).Post(bindIgnErr(auth.AuthenticationForm{}), admin.NewAuthSourcePost)
+ m.Combo("/new").Get(admin.NewAuthSource).Post(bindIgnErr(forms.AuthenticationForm{}), admin.NewAuthSourcePost)
m.Combo("/{authid}").Get(admin.EditAuthSource).
- Post(bindIgnErr(auth.AuthenticationForm{}), admin.EditAuthSourcePost)
+ Post(bindIgnErr(forms.AuthenticationForm{}), admin.EditAuthSourcePost)
m.Post("/{authid}/delete", admin.DeleteAuthSource)
})
m.Group("/org", func() {
m.Group("", func() {
m.Get("/create", org.Create)
- m.Post("/create", bindIgnErr(auth.CreateOrgForm{}), org.CreatePost)
+ m.Post("/create", bindIgnErr(forms.CreateOrgForm{}), org.CreatePost)
})
m.Group("/{org}", func() {
m.Group("/{org}", func() {
m.Get("/teams/new", org.NewTeam)
- m.Post("/teams/new", bindIgnErr(auth.CreateTeamForm{}), org.NewTeamPost)
+ m.Post("/teams/new", bindIgnErr(forms.CreateTeamForm{}), org.NewTeamPost)
m.Get("/teams/{team}/edit", org.EditTeam)
- m.Post("/teams/{team}/edit", bindIgnErr(auth.CreateTeamForm{}), org.EditTeamPost)
+ m.Post("/teams/{team}/edit", bindIgnErr(forms.CreateTeamForm{}), org.EditTeamPost)
m.Post("/teams/{team}/delete", org.DeleteTeam)
m.Group("/settings", func() {
m.Combo("").Get(org.Settings).
- Post(bindIgnErr(auth.UpdateOrgSettingForm{}), org.SettingsPost)
- m.Post("/avatar", bindIgnErr(auth.AvatarForm{}), org.SettingsAvatar)
+ Post(bindIgnErr(forms.UpdateOrgSettingForm{}), org.SettingsPost)
+ m.Post("/avatar", bindIgnErr(forms.AvatarForm{}), org.SettingsAvatar)
m.Post("/avatar/delete", org.SettingsDeleteAvatar)
m.Group("/hooks", func() {
m.Get("", org.Webhooks)
m.Post("/delete", org.DeleteWebhook)
m.Get("/{type}/new", repo.WebhooksNew)
- m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.GiteaHooksNewPost)
- m.Post("/gogs/new", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksNewPost)
- m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost)
- m.Post("/discord/new", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksNewPost)
- m.Post("/dingtalk/new", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost)
- m.Post("/telegram/new", bindIgnErr(auth.NewTelegramHookForm{}), repo.TelegramHooksNewPost)
- m.Post("/matrix/new", bindIgnErr(auth.NewMatrixHookForm{}), repo.MatrixHooksNewPost)
- m.Post("/msteams/new", bindIgnErr(auth.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost)
- m.Post("/feishu/new", bindIgnErr(auth.NewFeishuHookForm{}), repo.FeishuHooksNewPost)
+ m.Post("/gitea/new", bindIgnErr(forms.NewWebhookForm{}), repo.GiteaHooksNewPost)
+ m.Post("/gogs/new", bindIgnErr(forms.NewGogshookForm{}), repo.GogsHooksNewPost)
+ m.Post("/slack/new", bindIgnErr(forms.NewSlackHookForm{}), repo.SlackHooksNewPost)
+ m.Post("/discord/new", bindIgnErr(forms.NewDiscordHookForm{}), repo.DiscordHooksNewPost)
+ m.Post("/dingtalk/new", bindIgnErr(forms.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost)
+ m.Post("/telegram/new", bindIgnErr(forms.NewTelegramHookForm{}), repo.TelegramHooksNewPost)
+ m.Post("/matrix/new", bindIgnErr(forms.NewMatrixHookForm{}), repo.MatrixHooksNewPost)
+ m.Post("/msteams/new", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost)
+ m.Post("/feishu/new", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksNewPost)
m.Get("/{id}", repo.WebHooksEdit)
- m.Post("/gitea/{id}", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
- m.Post("/gogs/{id}", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksEditPost)
- m.Post("/slack/{id}", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost)
- m.Post("/discord/{id}", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksEditPost)
- m.Post("/dingtalk/{id}", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksEditPost)
- m.Post("/telegram/{id}", bindIgnErr(auth.NewTelegramHookForm{}), repo.TelegramHooksEditPost)
- m.Post("/matrix/{id}", bindIgnErr(auth.NewMatrixHookForm{}), repo.MatrixHooksEditPost)
- m.Post("/msteams/{id}", bindIgnErr(auth.NewMSTeamsHookForm{}), repo.MSTeamsHooksEditPost)
- m.Post("/feishu/{id}", bindIgnErr(auth.NewFeishuHookForm{}), repo.FeishuHooksEditPost)
+ m.Post("/gitea/{id}", bindIgnErr(forms.NewWebhookForm{}), repo.WebHooksEditPost)
+ m.Post("/gogs/{id}", bindIgnErr(forms.NewGogshookForm{}), repo.GogsHooksEditPost)
+ m.Post("/slack/{id}", bindIgnErr(forms.NewSlackHookForm{}), repo.SlackHooksEditPost)
+ m.Post("/discord/{id}", bindIgnErr(forms.NewDiscordHookForm{}), repo.DiscordHooksEditPost)
+ m.Post("/dingtalk/{id}", bindIgnErr(forms.NewDingtalkHookForm{}), repo.DingtalkHooksEditPost)
+ m.Post("/telegram/{id}", bindIgnErr(forms.NewTelegramHookForm{}), repo.TelegramHooksEditPost)
+ m.Post("/matrix/{id}", bindIgnErr(forms.NewMatrixHookForm{}), repo.MatrixHooksEditPost)
+ m.Post("/msteams/{id}", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksEditPost)
+ m.Post("/feishu/{id}", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksEditPost)
}, webhooksEnabled)
m.Group("/labels", func() {
m.Get("", org.RetrieveLabels, org.Labels)
- m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), org.NewLabel)
- m.Post("/edit", bindIgnErr(auth.CreateLabelForm{}), org.UpdateLabel)
+ m.Post("/new", bindIgnErr(forms.CreateLabelForm{}), org.NewLabel)
+ m.Post("/edit", bindIgnErr(forms.CreateLabelForm{}), org.UpdateLabel)
m.Post("/delete", org.DeleteLabel)
- m.Post("/initialize", bindIgnErr(auth.InitializeLabelsForm{}), org.InitializeLabels)
+ m.Post("/initialize", bindIgnErr(forms.InitializeLabelsForm{}), org.InitializeLabels)
})
m.Route("/delete", "GET,POST", org.SettingsDelete)
// ***** START: Repository *****
m.Group("/repo", func() {
m.Get("/create", repo.Create)
- m.Post("/create", bindIgnErr(auth.CreateRepoForm{}), repo.CreatePost)
+ m.Post("/create", bindIgnErr(forms.CreateRepoForm{}), repo.CreatePost)
m.Get("/migrate", repo.Migrate)
- m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), repo.MigratePost)
+ m.Post("/migrate", bindIgnErr(forms.MigrateRepoForm{}), repo.MigratePost)
m.Group("/fork", func() {
m.Combo("/{repoid}").Get(repo.Fork).
- Post(bindIgnErr(auth.CreateRepoForm{}), repo.ForkPost)
+ Post(bindIgnErr(forms.CreateRepoForm{}), repo.ForkPost)
}, context.RepoIDAssignment(), context.UnitTypes(), reqRepoCodeReader)
}, reqSignIn)
m.Group("/{username}/{reponame}", func() {
m.Group("/settings", func() {
m.Combo("").Get(repo.Settings).
- Post(bindIgnErr(auth.RepoSettingForm{}), repo.SettingsPost)
- m.Post("/avatar", bindIgnErr(auth.AvatarForm{}), repo.SettingsAvatar)
+ Post(bindIgnErr(forms.RepoSettingForm{}), repo.SettingsPost)
+ m.Post("/avatar", bindIgnErr(forms.AvatarForm{}), repo.SettingsAvatar)
m.Post("/avatar/delete", repo.SettingsDeleteAvatar)
m.Group("/collaboration", func() {
m.Group("/branches", func() {
m.Combo("").Get(repo.ProtectedBranch).Post(repo.ProtectedBranchPost)
m.Combo("/*").Get(repo.SettingsProtectedBranch).
- Post(bindIgnErr(auth.ProtectBranchForm{}), context.RepoMustNotBeArchived(), repo.SettingsProtectedBranchPost)
+ Post(bindIgnErr(forms.ProtectBranchForm{}), context.RepoMustNotBeArchived(), repo.SettingsProtectedBranchPost)
}, repo.MustBeNotEmpty)
m.Group("/hooks/git", func() {
m.Get("", repo.Webhooks)
m.Post("/delete", repo.DeleteWebhook)
m.Get("/{type}/new", repo.WebhooksNew)
- m.Post("/gitea/new", bindIgnErr(auth.NewWebhookForm{}), repo.GiteaHooksNewPost)
- m.Post("/gogs/new", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksNewPost)
- m.Post("/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost)
- m.Post("/discord/new", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksNewPost)
- m.Post("/dingtalk/new", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost)
- m.Post("/telegram/new", bindIgnErr(auth.NewTelegramHookForm{}), repo.TelegramHooksNewPost)
- m.Post("/matrix/new", bindIgnErr(auth.NewMatrixHookForm{}), repo.MatrixHooksNewPost)
- m.Post("/msteams/new", bindIgnErr(auth.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost)
- m.Post("/feishu/new", bindIgnErr(auth.NewFeishuHookForm{}), repo.FeishuHooksNewPost)
+ m.Post("/gitea/new", bindIgnErr(forms.NewWebhookForm{}), repo.GiteaHooksNewPost)
+ m.Post("/gogs/new", bindIgnErr(forms.NewGogshookForm{}), repo.GogsHooksNewPost)
+ m.Post("/slack/new", bindIgnErr(forms.NewSlackHookForm{}), repo.SlackHooksNewPost)
+ m.Post("/discord/new", bindIgnErr(forms.NewDiscordHookForm{}), repo.DiscordHooksNewPost)
+ m.Post("/dingtalk/new", bindIgnErr(forms.NewDingtalkHookForm{}), repo.DingtalkHooksNewPost)
+ m.Post("/telegram/new", bindIgnErr(forms.NewTelegramHookForm{}), repo.TelegramHooksNewPost)
+ m.Post("/matrix/new", bindIgnErr(forms.NewMatrixHookForm{}), repo.MatrixHooksNewPost)
+ m.Post("/msteams/new", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost)
+ m.Post("/feishu/new", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksNewPost)
m.Get("/{id}", repo.WebHooksEdit)
m.Post("/{id}/test", repo.TestWebhook)
- m.Post("/gitea/{id}", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
- m.Post("/gogs/{id}", bindIgnErr(auth.NewGogshookForm{}), repo.GogsHooksEditPost)
- m.Post("/slack/{id}", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost)
- m.Post("/discord/{id}", bindIgnErr(auth.NewDiscordHookForm{}), repo.DiscordHooksEditPost)
- m.Post("/dingtalk/{id}", bindIgnErr(auth.NewDingtalkHookForm{}), repo.DingtalkHooksEditPost)
- m.Post("/telegram/{id}", bindIgnErr(auth.NewTelegramHookForm{}), repo.TelegramHooksEditPost)
- m.Post("/matrix/{id}", bindIgnErr(auth.NewMatrixHookForm{}), repo.MatrixHooksEditPost)
- m.Post("/msteams/{id}", bindIgnErr(auth.NewMSTeamsHookForm{}), repo.MSTeamsHooksEditPost)
- m.Post("/feishu/{id}", bindIgnErr(auth.NewFeishuHookForm{}), repo.FeishuHooksEditPost)
+ m.Post("/gitea/{id}", bindIgnErr(forms.NewWebhookForm{}), repo.WebHooksEditPost)
+ m.Post("/gogs/{id}", bindIgnErr(forms.NewGogshookForm{}), repo.GogsHooksEditPost)
+ m.Post("/slack/{id}", bindIgnErr(forms.NewSlackHookForm{}), repo.SlackHooksEditPost)
+ m.Post("/discord/{id}", bindIgnErr(forms.NewDiscordHookForm{}), repo.DiscordHooksEditPost)
+ m.Post("/dingtalk/{id}", bindIgnErr(forms.NewDingtalkHookForm{}), repo.DingtalkHooksEditPost)
+ m.Post("/telegram/{id}", bindIgnErr(forms.NewTelegramHookForm{}), repo.TelegramHooksEditPost)
+ m.Post("/matrix/{id}", bindIgnErr(forms.NewMatrixHookForm{}), repo.MatrixHooksEditPost)
+ m.Post("/msteams/{id}", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksEditPost)
+ m.Post("/feishu/{id}", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksEditPost)
}, webhooksEnabled)
m.Group("/keys", func() {
m.Combo("").Get(repo.DeployKeys).
- Post(bindIgnErr(auth.AddKeyForm{}), repo.DeployKeysPost)
+ Post(bindIgnErr(forms.AddKeyForm{}), repo.DeployKeysPost)
m.Post("/delete", repo.DeleteDeployKey)
})
}, reqRepoIssuesOrPullsReader, context.RepoRef())
m.Combo("/compare/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists).
Get(ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff).
- Post(reqSignIn, context.RepoMustNotBeArchived(), reqRepoPullsReader, repo.MustAllowPulls, bindIgnErr(auth.CreateIssueForm{}), repo.SetWhitespaceBehavior, repo.CompareAndPullRequestPost)
+ Post(reqSignIn, context.RepoMustNotBeArchived(), reqRepoPullsReader, repo.MustAllowPulls, bindIgnErr(forms.CreateIssueForm{}), repo.SetWhitespaceBehavior, repo.CompareAndPullRequestPost)
}, context.RepoAssignment(), context.UnitTypes())
// Grouping for those endpoints that do require authentication
m.Group("/issues", func() {
m.Group("/new", func() {
m.Combo("").Get(context.RepoRef(), repo.NewIssue).
- Post(bindIgnErr(auth.CreateIssueForm{}), repo.NewIssuePost)
+ Post(bindIgnErr(forms.CreateIssueForm{}), repo.NewIssuePost)
m.Get("/choose", context.RepoRef(), repo.NewIssueChooseTemplate)
})
}, context.RepoMustNotBeArchived(), reqRepoIssueReader)
m.Post("/add", repo.AddDependency)
m.Post("/delete", repo.RemoveDependency)
})
- m.Combo("/comments").Post(repo.MustAllowUserComment, bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
+ m.Combo("/comments").Post(repo.MustAllowUserComment, bindIgnErr(forms.CreateCommentForm{}), repo.NewComment)
m.Group("/times", func() {
- m.Post("/add", bindIgnErr(auth.AddTimeManuallyForm{}), repo.AddTimeManually)
+ m.Post("/add", bindIgnErr(forms.AddTimeManuallyForm{}), repo.AddTimeManually)
m.Post("/{timeid}/delete", repo.DeleteTime)
m.Group("/stopwatch", func() {
m.Post("/toggle", repo.IssueStopwatch)
m.Post("/cancel", repo.CancelStopwatch)
})
})
- m.Post("/reactions/{action}", bindIgnErr(auth.ReactionForm{}), repo.ChangeIssueReaction)
- m.Post("/lock", reqRepoIssueWriter, bindIgnErr(auth.IssueLockForm{}), repo.LockIssue)
+ m.Post("/reactions/{action}", bindIgnErr(forms.ReactionForm{}), repo.ChangeIssueReaction)
+ m.Post("/lock", reqRepoIssueWriter, bindIgnErr(forms.IssueLockForm{}), repo.LockIssue)
m.Post("/unlock", reqRepoIssueWriter, repo.UnlockIssue)
}, context.RepoMustNotBeArchived())
m.Group("/{index}", func() {
m.Post("/projects", reqRepoIssuesOrPullsWriter, repo.UpdateIssueProject)
m.Post("/assignee", reqRepoIssuesOrPullsWriter, repo.UpdateIssueAssignee)
m.Post("/request_review", reqRepoIssuesOrPullsReader, repo.UpdatePullReviewRequest)
- m.Post("/dismiss_review", reqRepoAdmin, bindIgnErr(auth.DismissReviewForm{}), repo.DismissReview)
+ m.Post("/dismiss_review", reqRepoAdmin, bindIgnErr(forms.DismissReviewForm{}), repo.DismissReview)
m.Post("/status", reqRepoIssuesOrPullsWriter, repo.UpdateIssueStatus)
m.Post("/resolve_conversation", reqRepoIssuesOrPullsReader, repo.UpdateResolveConversation)
m.Post("/attachments", repo.UploadIssueAttachment)
m.Group("/comments/{id}", func() {
m.Post("", repo.UpdateCommentContent)
m.Post("/delete", repo.DeleteComment)
- m.Post("/reactions/{action}", bindIgnErr(auth.ReactionForm{}), repo.ChangeCommentReaction)
+ m.Post("/reactions/{action}", bindIgnErr(forms.ReactionForm{}), repo.ChangeCommentReaction)
}, context.RepoMustNotBeArchived())
m.Group("/comments/{id}", func() {
m.Get("/attachments", repo.GetCommentAttachments)
})
m.Group("/labels", func() {
- m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel)
- m.Post("/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel)
+ m.Post("/new", bindIgnErr(forms.CreateLabelForm{}), repo.NewLabel)
+ m.Post("/edit", bindIgnErr(forms.CreateLabelForm{}), repo.UpdateLabel)
m.Post("/delete", repo.DeleteLabel)
- m.Post("/initialize", bindIgnErr(auth.InitializeLabelsForm{}), repo.InitializeLabels)
+ m.Post("/initialize", bindIgnErr(forms.InitializeLabelsForm{}), repo.InitializeLabels)
}, context.RepoMustNotBeArchived(), reqRepoIssuesOrPullsWriter, context.RepoRef())
m.Group("/milestones", func() {
m.Combo("/new").Get(repo.NewMilestone).
- Post(bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost)
+ Post(bindIgnErr(forms.CreateMilestoneForm{}), repo.NewMilestonePost)
m.Get("/{id}/edit", repo.EditMilestone)
- m.Post("/{id}/edit", bindIgnErr(auth.CreateMilestoneForm{}), repo.EditMilestonePost)
+ m.Post("/{id}/edit", bindIgnErr(forms.CreateMilestoneForm{}), repo.EditMilestonePost)
m.Post("/{id}/{action}", repo.ChangeMilestoneStatus)
m.Post("/delete", repo.DeleteMilestone)
}, context.RepoMustNotBeArchived(), reqRepoIssuesOrPullsWriter, context.RepoRef())
m.Group("", func() {
m.Group("", func() {
m.Combo("/_edit/*").Get(repo.EditFile).
- Post(bindIgnErr(auth.EditRepoFileForm{}), repo.EditFilePost)
+ Post(bindIgnErr(forms.EditRepoFileForm{}), repo.EditFilePost)
m.Combo("/_new/*").Get(repo.NewFile).
- Post(bindIgnErr(auth.EditRepoFileForm{}), repo.NewFilePost)
- m.Post("/_preview/*", bindIgnErr(auth.EditPreviewDiffForm{}), repo.DiffPreviewPost)
+ Post(bindIgnErr(forms.EditRepoFileForm{}), repo.NewFilePost)
+ m.Post("/_preview/*", bindIgnErr(forms.EditPreviewDiffForm{}), repo.DiffPreviewPost)
m.Combo("/_delete/*").Get(repo.DeleteFile).
- Post(bindIgnErr(auth.DeleteRepoFileForm{}), repo.DeleteFilePost)
+ Post(bindIgnErr(forms.DeleteRepoFileForm{}), repo.DeleteFilePost)
m.Combo("/_upload/*", repo.MustBeAbleToUpload).
Get(repo.UploadFile).
- Post(bindIgnErr(auth.UploadRepoFileForm{}), repo.UploadFilePost)
+ Post(bindIgnErr(forms.UploadRepoFileForm{}), repo.UploadFilePost)
}, context.RepoRefByType(context.RepoRefBranch), repo.MustBeEditable)
m.Group("", func() {
m.Post("/upload-file", repo.UploadFileToServer)
- m.Post("/upload-remove", bindIgnErr(auth.RemoveUploadFileForm{}), repo.RemoveUploadFileFromServer)
+ m.Post("/upload-remove", bindIgnErr(forms.RemoveUploadFileForm{}), repo.RemoveUploadFileFromServer)
}, context.RepoRef(), repo.MustBeEditable, repo.MustBeAbleToUpload)
}, context.RepoMustNotBeArchived(), reqRepoCodeWriter, repo.MustBeNotEmpty)
m.Post("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.CreateBranch)
m.Post("/tag/*", context.RepoRefByType(context.RepoRefTag), repo.CreateBranch)
m.Post("/commit/*", context.RepoRefByType(context.RepoRefCommit), repo.CreateBranch)
- }, bindIgnErr(auth.NewBranchForm{}))
+ }, bindIgnErr(forms.NewBranchForm{}))
m.Post("/delete", repo.DeleteBranchPost)
m.Post("/restore", repo.RestoreBranchPost)
}, context.RepoMustNotBeArchived(), reqRepoCodeWriter, repo.MustBeNotEmpty)
}, repo.MustBeNotEmpty, reqRepoReleaseReader, context.RepoRefByType(context.RepoRefTag))
m.Group("/releases", func() {
m.Get("/new", repo.NewRelease)
- m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost)
+ m.Post("/new", bindIgnErr(forms.NewReleaseForm{}), repo.NewReleasePost)
m.Post("/delete", repo.DeleteRelease)
m.Post("/attachments", repo.UploadReleaseAttachment)
m.Post("/attachments/remove", repo.DeleteAttachment)
repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoCodeWriter, context.RepoRef())
m.Group("/releases", func() {
m.Get("/edit/*", repo.EditRelease)
- m.Post("/edit/*", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
+ m.Post("/edit/*", bindIgnErr(forms.EditReleaseForm{}), repo.EditReleasePost)
}, reqSignIn, repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoReleaseWriter, func(ctx *context.Context) {
var err error
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
m.Get("/{id}", repo.ViewProject)
m.Group("", func() {
m.Get("/new", repo.NewProject)
- m.Post("/new", bindIgnErr(auth.CreateProjectForm{}), repo.NewProjectPost)
+ m.Post("/new", bindIgnErr(forms.CreateProjectForm{}), repo.NewProjectPost)
m.Group("/{id}", func() {
- m.Post("", bindIgnErr(auth.EditProjectBoardForm{}), repo.AddBoardToProjectPost)
+ m.Post("", bindIgnErr(forms.EditProjectBoardForm{}), repo.AddBoardToProjectPost)
m.Post("/delete", repo.DeleteProject)
m.Get("/edit", repo.EditProject)
- m.Post("/edit", bindIgnErr(auth.CreateProjectForm{}), repo.EditProjectPost)
+ m.Post("/edit", bindIgnErr(forms.CreateProjectForm{}), repo.EditProjectPost)
m.Post("/{action:open|close}", repo.ChangeProjectStatus)
m.Group("/{boardID}", func() {
- m.Put("", bindIgnErr(auth.EditProjectBoardForm{}), repo.EditProjectBoard)
+ m.Put("", bindIgnErr(forms.EditProjectBoardForm{}), repo.EditProjectBoard)
m.Delete("", repo.DeleteProjectBoard)
m.Post("/default", repo.SetDefaultProjectBoard)
m.Group("", func() {
m.Combo("/_new").Get(repo.NewWiki).
- Post(bindIgnErr(auth.NewWikiForm{}), repo.NewWikiPost)
+ Post(bindIgnErr(forms.NewWikiForm{}), repo.NewWikiPost)
m.Combo("/{page}/_edit").Get(repo.EditWiki).
- Post(bindIgnErr(auth.NewWikiForm{}), repo.EditWikiPost)
+ Post(bindIgnErr(forms.NewWikiForm{}), repo.EditWikiPost)
m.Post("/{page}/delete", repo.DeleteWikiPagePost)
}, context.RepoMustNotBeArchived(), reqSignIn, reqRepoWikiWriter)
}, repo.MustEnableWiki, context.RepoRef(), func(ctx *context.Context) {
m.Get(".diff", repo.DownloadPullDiff)
m.Get(".patch", repo.DownloadPullPatch)
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
- m.Post("/merge", context.RepoMustNotBeArchived(), bindIgnErr(auth.MergePullRequestForm{}), repo.MergePullRequest)
+ m.Post("/merge", context.RepoMustNotBeArchived(), bindIgnErr(forms.MergePullRequestForm{}), repo.MergePullRequest)
m.Post("/update", repo.UpdatePullRequest)
m.Post("/cleanup", context.RepoMustNotBeArchived(), context.RepoRef(), repo.CleanUpPullRequest)
m.Group("/files", func() {
m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.ViewPullFiles)
m.Group("/reviews", func() {
m.Get("/new_comment", repo.RenderNewCodeCommentForm)
- m.Post("/comments", bindIgnErr(auth.CodeCommentForm{}), repo.CreateCodeComment)
- m.Post("/submit", bindIgnErr(auth.SubmitReviewForm{}), repo.SubmitReview)
+ m.Post("/comments", bindIgnErr(forms.CodeCommentForm{}), repo.CreateCodeComment)
+ m.Post("/submit", bindIgnErr(forms.SubmitReviewForm{}), repo.SubmitReview)
}, context.RepoMustNotBeArchived())
})
}, repo.MustAllowPulls)
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/eventsource"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/hcaptcha"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/password"
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/routers/utils"
"code.gitea.io/gitea/services/externalaccount"
+ "code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/mailer"
"github.com/markbates/goth"
return
}
- form := web.GetForm(ctx).(*auth.SignInForm)
+ form := web.GetForm(ctx).(*forms.SignInForm)
u, err := models.UserSignIn(form.UserName, form.Password)
if err != nil {
if models.IsErrUserNotExist(err) {
// TwoFactorPost validates a user's two-factor authentication token.
func TwoFactorPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.TwoFactorAuthForm)
+ form := web.GetForm(ctx).(*forms.TwoFactorAuthForm)
ctx.Data["Title"] = ctx.Tr("twofa")
// Ensure user is in a 2FA session.
return
}
- ctx.RenderWithErr(ctx.Tr("auth.twofa_passcode_incorrect"), tplTwofa, auth.TwoFactorAuthForm{})
+ ctx.RenderWithErr(ctx.Tr("auth.twofa_passcode_incorrect"), tplTwofa, forms.TwoFactorAuthForm{})
}
// TwoFactorScratch shows the scratch code form for two-factor authentication.
// TwoFactorScratchPost validates and invalidates a user's two-factor scratch token.
func TwoFactorScratchPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.TwoFactorScratchAuthForm)
+ form := web.GetForm(ctx).(*forms.TwoFactorScratchAuthForm)
ctx.Data["Title"] = ctx.Tr("twofa_scratch")
// Ensure user is in a 2FA session.
return
}
- ctx.RenderWithErr(ctx.Tr("auth.twofa_scratch_token_incorrect"), tplTwofaScratch, auth.TwoFactorScratchAuthForm{})
+ ctx.RenderWithErr(ctx.Tr("auth.twofa_scratch_token_incorrect"), tplTwofaScratch, forms.TwoFactorScratchAuthForm{})
}
// U2F shows the U2F login page
// LinkAccountPostSignIn handle the coupling of external account with another account using signIn
func LinkAccountPostSignIn(ctx *context.Context) {
- signInForm := web.GetForm(ctx).(*auth.SignInForm)
+ signInForm := web.GetForm(ctx).(*forms.SignInForm)
ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
ctx.Data["Title"] = ctx.Tr("link_account")
ctx.Data["LinkAccountMode"] = true
// LinkAccountPostRegister handle the creation of a new account for an external account using signUp
func LinkAccountPostRegister(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.RegisterForm)
+ form := web.GetForm(ctx).(*forms.RegisterForm)
// TODO Make insecure passwords optional for local accounts also,
// once email-based Second-Factor Auth is available
ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
// SignUpPost response for sign up information submission
func SignUpPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.RegisterForm)
+ form := web.GetForm(ctx).(*forms.RegisterForm)
ctx.Data["Title"] = ctx.Tr("sign_up")
ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"
// MustChangePasswordPost response for updating a user's password after his/her
// account was created by an admin
func MustChangePasswordPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.MustChangePasswordForm)
+ form := web.GetForm(ctx).(*forms.MustChangePasswordForm)
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/settings/change_password"
if ctx.HasError() {
"code.gitea.io/gitea/modules/auth/openid"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/generate"
"code.gitea.io/gitea/modules/hcaptcha"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/modules/web/middleware"
+ "code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/mailer"
)
// SignInOpenIDPost response for openid sign in request
func SignInOpenIDPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.SignInOpenIDForm)
+ form := web.GetForm(ctx).(*forms.SignInOpenIDForm)
ctx.Data["Title"] = ctx.Tr("sign_in")
ctx.Data["PageIsSignIn"] = true
ctx.Data["PageIsLoginOpenID"] = true
var id, err = openid.Verify(fullURL)
if err != nil {
- ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
+ ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
Openid: id,
})
return
u, err := models.GetUserByOpenID(id)
if err != nil {
if !models.IsErrUserNotExist(err) {
- ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
+ ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
Openid: id,
})
return
parsedURL, err := url.Parse(fullURL)
if err != nil {
- ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
+ ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
Openid: id,
})
return
}
values, err := url.ParseQuery(parsedURL.RawQuery)
if err != nil {
- ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
+ ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
Openid: id,
})
return
u, err = models.GetUserByEmail(email)
if err != nil {
if !models.IsErrUserNotExist(err) {
- ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
+ ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
Openid: id,
})
return
u, _ = models.GetUserByName(nickname)
if err != nil {
if !models.IsErrUserNotExist(err) {
- ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
+ ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
Openid: id,
})
return
// ConnectOpenIDPost handles submission of a form to connect an OpenID URI to an existing account
func ConnectOpenIDPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.ConnectOpenIDForm)
+ form := web.GetForm(ctx).(*forms.ConnectOpenIDForm)
oid, _ := ctx.Session.Get("openid_verified_uri").(string)
if oid == "" {
ctx.Redirect(setting.AppSubURL + "/user/login/openid")
// RegisterOpenIDPost handles submission of a form to create a new user authenticated via an OpenID URI
func RegisterOpenIDPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.SignUpOpenIDForm)
+ form := web.GetForm(ctx).(*forms.SignUpOpenIDForm)
oid, _ := ctx.Session.Get("openid_verified_uri").(string)
if oid == "" {
ctx.Redirect(setting.AppSubURL + "/user/login/openid")
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
"gitea.com/go-chi/binding"
"github.com/dgrijalva/jwt-go"
// AuthorizeOAuth manages authorize requests
func AuthorizeOAuth(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.AuthorizationForm)
+ form := web.GetForm(ctx).(*forms.AuthorizationForm)
errs := binding.Errors{}
errs = form.Validate(ctx.Req, errs)
if len(errs) > 0 {
// GrantApplicationOAuth manages the post request submitted when a user grants access to an application
func GrantApplicationOAuth(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.GrantApplicationForm)
+ form := web.GetForm(ctx).(*forms.GrantApplicationForm)
if ctx.Session.Get("client_id") != form.ClientID || ctx.Session.Get("state") != form.State ||
ctx.Session.Get("redirect_uri") != form.RedirectURI {
ctx.Error(http.StatusBadRequest)
// AccessTokenOAuth manages all access token requests by the client
func AccessTokenOAuth(ctx *context.Context) {
- form := *web.GetForm(ctx).(*auth.AccessTokenForm)
+ form := *web.GetForm(ctx).(*forms.AccessTokenForm)
if form.ClientID == "" {
authHeader := ctx.Req.Header.Get("Authorization")
authContent := strings.SplitN(authHeader, " ", 2)
}
}
-func handleRefreshToken(ctx *context.Context, form auth.AccessTokenForm) {
+func handleRefreshToken(ctx *context.Context, form forms.AccessTokenForm) {
token, err := models.ParseOAuth2Token(form.RefreshToken)
if err != nil {
handleAccessTokenError(ctx, AccessTokenError{
ctx.JSON(http.StatusOK, accessToken)
}
-func handleAuthorizationCode(ctx *context.Context, form auth.AccessTokenForm) {
+func handleAuthorizationCode(ctx *context.Context, form forms.AccessTokenForm) {
app, err := models.GetOAuth2ApplicationByClientID(form.ClientID)
if err != nil {
handleAccessTokenError(ctx, AccessTokenError{
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/password"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/mailer"
)
// AccountPost response for change user's password
func AccountPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.ChangePasswordForm)
+ form := web.GetForm(ctx).(*forms.ChangePasswordForm)
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsAccount"] = true
// EmailPost response for change user's email
func EmailPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.AddEmailForm)
+ form := web.GetForm(ctx).(*forms.AddEmailForm)
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsAccount"] = true
// UpdateUIThemePost is used to update users' specific theme
func UpdateUIThemePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.UpdateThemeForm)
+ form := web.GetForm(ctx).(*forms.UpdateThemeForm)
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsAccount"] = true
"testing"
"code.gitea.io/gitea/models"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
"github.com/stretchr/testify/assert"
)
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
- web.SetForm(ctx, &auth.ChangePasswordForm{
+ web.SetForm(ctx, &forms.ChangePasswordForm{
OldPassword: req.OldPassword,
Password: req.NewPassword,
Retype: req.Retype,
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
)
const (
// ApplicationsPost response for add user's access token
func ApplicationsPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.NewAccessTokenForm)
+ form := web.GetForm(ctx).(*forms.NewAccessTokenForm)
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsApplications"] = true
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
)
const (
// KeysPost response for change user's SSH/GPG keys
func KeysPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.AddKeyForm)
+ form := web.GetForm(ctx).(*forms.AddKeyForm)
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsKeys"] = true
ctx.Data["DisableSSH"] = setting.SSH.Disabled
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
)
const (
// OAuthApplicationsPost response for adding a oauth2 application
func OAuthApplicationsPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.EditOAuth2ApplicationForm)
+ form := web.GetForm(ctx).(*forms.EditOAuth2ApplicationForm)
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsApplications"] = true
// OAuthApplicationsEdit response for editing oauth2 application
func OAuthApplicationsEdit(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.EditOAuth2ApplicationForm)
+ form := web.GetForm(ctx).(*forms.EditOAuth2ApplicationForm)
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsApplications"] = true
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/modules/web/middleware"
+ "code.gitea.io/gitea/services/forms"
"github.com/unknwon/i18n"
)
// ProfilePost response for change user's profile
func ProfilePost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.UpdateProfileForm)
+ form := web.GetForm(ctx).(*forms.UpdateProfileForm)
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsProfile"] = true
// UpdateAvatarSetting update user's avatar
// FIXME: limit size.
-func UpdateAvatarSetting(ctx *context.Context, form *auth.AvatarForm, ctxUser *models.User) error {
- ctxUser.UseCustomAvatar = form.Source == auth.AvatarLocal
+func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *models.User) error {
+ ctxUser.UseCustomAvatar = form.Source == forms.AvatarLocal
if len(form.Gravatar) > 0 {
if form.Avatar != nil {
ctxUser.Avatar = base.EncodeMD5(form.Gravatar)
// AvatarPost response for change user's avatar request
func AvatarPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.AvatarForm)
+ form := web.GetForm(ctx).(*forms.AvatarForm)
if err := UpdateAvatarSetting(ctx, form, ctx.User); err != nil {
ctx.Flash.Error(err.Error())
} else {
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth/openid"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
)
// OpenIDPost response for change user's openid
func OpenIDPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.AddOpenIDForm)
+ form := web.GetForm(ctx).(*forms.AddOpenIDForm)
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsSecurity"] = true
id, err := openid.Verify(fullURL)
if err != nil {
- ctx.RenderWithErr(err.Error(), tplSettingsSecurity, &auth.AddOpenIDForm{
+ ctx.RenderWithErr(err.Error(), tplSettingsSecurity, &forms.AddOpenIDForm{
Openid: id,
})
return
oid := &models.UserOpenID{UID: ctx.User.ID, URI: id}
if err = models.AddUserOpenID(oid); err != nil {
if models.IsErrOpenIDAlreadyUsed(err) {
- ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsSecurity, &auth.AddOpenIDForm{Openid: id})
+ ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsSecurity, &forms.AddOpenIDForm{Openid: id})
return
}
ctx.ServerError("AddUserOpenID", err)
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
"github.com/pquerna/otp"
"github.com/pquerna/otp/totp"
// EnrollTwoFactorPost handles enrolling the user into 2FA.
func EnrollTwoFactorPost(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.TwoFactorAuthForm)
+ form := web.GetForm(ctx).(*forms.TwoFactorAuthForm)
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsSecurity"] = true
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
- auth "code.gitea.io/gitea/modules/forms"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/forms"
"github.com/tstranex/u2f"
)
// U2FRegister initializes the u2f registration procedure
func U2FRegister(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.U2FRegistrationForm)
+ form := web.GetForm(ctx).(*forms.U2FRegistrationForm)
if form.Name == "" {
ctx.Error(http.StatusConflict)
return
// U2FDelete deletes an security key by id
func U2FDelete(ctx *context.Context) {
- form := web.GetForm(ctx).(*auth.U2FDeleteForm)
+ form := web.GetForm(ctx).(*forms.U2FDeleteForm)
reg, err := models.GetU2FRegistrationByID(form.ID)
if err != nil {
if models.IsErrU2FRegistrationNotExist(err) {
--- /dev/null
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package forms
+
+import (
+ "net/http"
+
+ "code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/web/middleware"
+
+ "gitea.com/go-chi/binding"
+)
+
+// AdminCreateUserForm form for admin to create user
+type AdminCreateUserForm struct {
+ LoginType string `binding:"Required"`
+ LoginName string
+ UserName string `binding:"Required;AlphaDashDot;MaxSize(40)"`
+ Email string `binding:"Required;Email;MaxSize(254)"`
+ Password string `binding:"MaxSize(255)"`
+ SendNotify bool
+ MustChangePassword bool
+}
+
+// Validate validates form fields
+func (f *AdminCreateUserForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// AdminEditUserForm form for admin to create user
+type AdminEditUserForm struct {
+ LoginType string `binding:"Required"`
+ UserName string `binding:"AlphaDashDot;MaxSize(40)"`
+ LoginName string
+ FullName string `binding:"MaxSize(100)"`
+ Email string `binding:"Required;Email;MaxSize(254)"`
+ Password string `binding:"MaxSize(255)"`
+ Website string `binding:"ValidUrl;MaxSize(255)"`
+ Location string `binding:"MaxSize(50)"`
+ MaxRepoCreation int
+ Active bool
+ Admin bool
+ Restricted bool
+ AllowGitHook bool
+ AllowImportLocal bool
+ AllowCreateOrganization bool
+ ProhibitLogin bool
+ Reset2FA bool `form:"reset_2fa"`
+}
+
+// Validate validates form fields
+func (f *AdminEditUserForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// AdminDashboardForm form for admin dashboard operations
+type AdminDashboardForm struct {
+ Op string `binding:"required"`
+ From string
+}
+
+// Validate validates form fields
+func (f *AdminDashboardForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
--- /dev/null
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package forms
+
+import (
+ "net/http"
+
+ "code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/web/middleware"
+
+ "gitea.com/go-chi/binding"
+)
+
+// AuthenticationForm form for authentication
+type AuthenticationForm struct {
+ ID int64
+ Type int `binding:"Range(2,7)"`
+ Name string `binding:"Required;MaxSize(30)"`
+ Host string
+ Port int
+ BindDN string
+ BindPassword string
+ UserBase string
+ UserDN string
+ AttributeUsername string
+ AttributeName string
+ AttributeSurname string
+ AttributeMail string
+ AttributeSSHPublicKey string
+ AttributesInBind bool
+ UsePagedSearch bool
+ SearchPageSize int
+ Filter string
+ AdminFilter string
+ GroupsEnabled bool
+ GroupDN string
+ GroupFilter string
+ GroupMemberUID string
+ UserUID string
+ RestrictedFilter string
+ AllowDeactivateAll bool
+ IsActive bool
+ IsSyncEnabled bool
+ SMTPAuth string
+ SMTPHost string
+ SMTPPort int
+ AllowedDomains string
+ SecurityProtocol int `binding:"Range(0,2)"`
+ TLS bool
+ SkipVerify bool
+ PAMServiceName string
+ Oauth2Provider string
+ Oauth2Key string
+ Oauth2Secret string
+ OpenIDConnectAutoDiscoveryURL string
+ Oauth2UseCustomURL bool
+ Oauth2TokenURL string
+ Oauth2AuthURL string
+ Oauth2ProfileURL string
+ Oauth2EmailURL string
+ Oauth2IconURL string
+ SSPIAutoCreateUsers bool
+ SSPIAutoActivateUsers bool
+ SSPIStripDomainNames bool
+ SSPISeparatorReplacement string `binding:"AlphaDashDot;MaxSize(5)"`
+ SSPIDefaultLanguage string
+}
+
+// Validate validates fields
+func (f *AuthenticationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
--- /dev/null
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package forms
+
+import (
+ "net/http"
+
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/modules/web/middleware"
+
+ "gitea.com/go-chi/binding"
+)
+
+// ________ .__ __ .__
+// \_____ \_______ _________ ____ |__|____________ _/ |_|__| ____ ____
+// / | \_ __ \/ ___\__ \ / \| \___ /\__ \\ __\ |/ _ \ / \
+// / | \ | \/ /_/ > __ \| | \ |/ / / __ \| | | ( <_> ) | \
+// \_______ /__| \___ (____ /___| /__/_____ \(____ /__| |__|\____/|___| /
+// \/ /_____/ \/ \/ \/ \/ \/
+
+// CreateOrgForm form for creating organization
+type CreateOrgForm struct {
+ OrgName string `binding:"Required;AlphaDashDot;MaxSize(40)" locale:"org.org_name_holder"`
+ Visibility structs.VisibleType
+ RepoAdminChangeTeamAccess bool
+}
+
+// Validate validates the fields
+func (f *CreateOrgForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// UpdateOrgSettingForm form for updating organization settings
+type UpdateOrgSettingForm struct {
+ Name string `binding:"Required;AlphaDashDot;MaxSize(40)" locale:"org.org_name_holder"`
+ FullName string `binding:"MaxSize(100)"`
+ Description string `binding:"MaxSize(255)"`
+ Website string `binding:"ValidUrl;MaxSize(255)"`
+ Location string `binding:"MaxSize(50)"`
+ Visibility structs.VisibleType
+ MaxRepoCreation int
+ RepoAdminChangeTeamAccess bool
+}
+
+// Validate validates the fields
+func (f *UpdateOrgSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// ___________
+// \__ ___/___ _____ _____
+// | |_/ __ \\__ \ / \
+// | |\ ___/ / __ \| Y Y \
+// |____| \___ >____ /__|_| /
+// \/ \/ \/
+
+// CreateTeamForm form for creating team
+type CreateTeamForm struct {
+ TeamName string `binding:"Required;AlphaDashDot;MaxSize(30)"`
+ Description string `binding:"MaxSize(255)"`
+ Permission string
+ Units []models.UnitType
+ RepoAccess string
+ CanCreateOrgRepo bool
+}
+
+// Validate validates the fields
+func (f *CreateTeamForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
--- /dev/null
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package forms
+
+import (
+ "net/http"
+
+ "code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/web/middleware"
+
+ "gitea.com/go-chi/binding"
+)
+
+// NewBranchForm form for creating a new branch
+type NewBranchForm struct {
+ NewBranchName string `binding:"Required;MaxSize(100);GitRefName"`
+ CreateTag bool
+}
+
+// Validate validates the fields
+func (f *NewBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
--- /dev/null
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package forms
+
+import (
+ "net/http"
+ "net/url"
+ "strings"
+
+ "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/structs"
+ "code.gitea.io/gitea/modules/web/middleware"
+ "code.gitea.io/gitea/routers/utils"
+
+ "gitea.com/go-chi/binding"
+)
+
+// _______________________________________ _________.______________________ _______________.___.
+// \______ \_ _____/\______ \_____ \ / _____/| \__ ___/\_____ \\______ \__ | |
+// | _/| __)_ | ___// | \ \_____ \ | | | | / | \| _// | |
+// | | \| \ | | / | \/ \| | | | / | \ | \\____ |
+// |____|_ /_______ / |____| \_______ /_______ /|___| |____| \_______ /____|_ // ______|
+// \/ \/ \/ \/ \/ \/ \/
+
+// CreateRepoForm form for creating repository
+type CreateRepoForm struct {
+ UID int64 `binding:"Required"`
+ RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
+ Private bool
+ Description string `binding:"MaxSize(255)"`
+ DefaultBranch string `binding:"GitRefName;MaxSize(100)"`
+ AutoInit bool
+ Gitignores string
+ IssueLabels string
+ License string
+ Readme string
+ Template bool
+
+ RepoTemplate int64
+ GitContent bool
+ Topics bool
+ GitHooks bool
+ Webhooks bool
+ Avatar bool
+ Labels bool
+ TrustModel string
+}
+
+// Validate validates the fields
+func (f *CreateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// MigrateRepoForm form for migrating repository
+// this is used to interact with web ui
+type MigrateRepoForm struct {
+ // required: true
+ CloneAddr string `json:"clone_addr" binding:"Required"`
+ Service structs.GitServiceType `json:"service"`
+ AuthUsername string `json:"auth_username"`
+ AuthPassword string `json:"auth_password"`
+ AuthToken string `json:"auth_token"`
+ // required: true
+ UID int64 `json:"uid" binding:"Required"`
+ // required: true
+ RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
+ Mirror bool `json:"mirror"`
+ Private bool `json:"private"`
+ Description string `json:"description" binding:"MaxSize(255)"`
+ Wiki bool `json:"wiki"`
+ Milestones bool `json:"milestones"`
+ Labels bool `json:"labels"`
+ Issues bool `json:"issues"`
+ PullRequests bool `json:"pull_requests"`
+ Releases bool `json:"releases"`
+ MirrorInterval string `json:"mirror_interval"`
+}
+
+// Validate validates the fields
+func (f *MigrateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// ParseRemoteAddr checks if given remote address is valid,
+// and returns composed URL with needed username and password.
+func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, error) {
+ remoteAddr = strings.TrimSpace(remoteAddr)
+ // Remote address can be HTTP/HTTPS/Git URL or local path.
+ if strings.HasPrefix(remoteAddr, "http://") ||
+ strings.HasPrefix(remoteAddr, "https://") ||
+ strings.HasPrefix(remoteAddr, "git://") {
+ u, err := url.Parse(remoteAddr)
+ if err != nil {
+ return "", &models.ErrInvalidCloneAddr{IsURLError: true}
+ }
+ if len(authUsername)+len(authPassword) > 0 {
+ u.User = url.UserPassword(authUsername, authPassword)
+ }
+ remoteAddr = u.String()
+ }
+
+ return remoteAddr, nil
+}
+
+// RepoSettingForm form for changing repository settings
+type RepoSettingForm struct {
+ RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
+ Description string `binding:"MaxSize(255)"`
+ Website string `binding:"ValidUrl;MaxSize(255)"`
+ Interval string
+ MirrorAddress string
+ MirrorUsername string
+ MirrorPassword string
+ Private bool
+ Template bool
+ EnablePrune bool
+
+ // Advanced settings
+ EnableWiki bool
+ EnableExternalWiki bool
+ ExternalWikiURL string
+ EnableIssues bool
+ EnableExternalTracker bool
+ ExternalTrackerURL string
+ TrackerURLFormat string
+ TrackerIssueStyle string
+ EnableCloseIssuesViaCommitInAnyBranch bool
+ EnableProjects bool
+ EnablePulls bool
+ PullsIgnoreWhitespace bool
+ PullsAllowMerge bool
+ PullsAllowRebase bool
+ PullsAllowRebaseMerge bool
+ PullsAllowSquash bool
+ PullsAllowManualMerge bool
+ PullsDefaultMergeStyle string
+ EnableAutodetectManualMerge bool
+ EnableTimetracker bool
+ AllowOnlyContributorsToTrackTime bool
+ EnableIssueDependencies bool
+ IsArchived bool
+
+ // Signing Settings
+ TrustModel string
+
+ // Admin settings
+ EnableHealthCheck bool
+}
+
+// Validate validates the fields
+func (f *RepoSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// __________ .__
+// \______ \____________ ____ ____ | |__
+// | | _/\_ __ \__ \ / \_/ ___\| | \
+// | | \ | | \// __ \| | \ \___| Y \
+// |______ / |__| (____ /___| /\___ >___| /
+// \/ \/ \/ \/ \/
+
+// ProtectBranchForm form for changing protected branch settings
+type ProtectBranchForm struct {
+ Protected bool
+ EnablePush string
+ WhitelistUsers string
+ WhitelistTeams string
+ WhitelistDeployKeys bool
+ EnableMergeWhitelist bool
+ MergeWhitelistUsers string
+ MergeWhitelistTeams string
+ EnableStatusCheck bool
+ StatusCheckContexts []string
+ RequiredApprovals int64
+ EnableApprovalsWhitelist bool
+ ApprovalsWhitelistUsers string
+ ApprovalsWhitelistTeams string
+ BlockOnRejectedReviews bool
+ BlockOnOfficialReviewRequests bool
+ BlockOnOutdatedBranch bool
+ DismissStaleApprovals bool
+ RequireSignedCommits bool
+ ProtectedFilePatterns string
+}
+
+// Validate validates the fields
+func (f *ProtectBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// __ __ ___. .__ .__ __
+// / \ / \ ____\_ |__ | |__ | |__ ____ | | __
+// \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
+// \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
+// \__/\ / \___ >___ /___| /___| /\____/|__|_ \
+// \/ \/ \/ \/ \/ \/
+
+// WebhookForm form for changing web hook
+type WebhookForm struct {
+ Events string
+ Create bool
+ Delete bool
+ Fork bool
+ Issues bool
+ IssueAssign bool
+ IssueLabel bool
+ IssueMilestone bool
+ IssueComment bool
+ Release bool
+ Push bool
+ PullRequest bool
+ PullRequestAssign bool
+ PullRequestLabel bool
+ PullRequestMilestone bool
+ PullRequestComment bool
+ PullRequestReview bool
+ PullRequestSync bool
+ Repository bool
+ Active bool
+ BranchFilter string `binding:"GlobPattern"`
+}
+
+// PushOnly if the hook will be triggered when push
+func (f WebhookForm) PushOnly() bool {
+ return f.Events == "push_only"
+}
+
+// SendEverything if the hook will be triggered any event
+func (f WebhookForm) SendEverything() bool {
+ return f.Events == "send_everything"
+}
+
+// ChooseEvents if the hook will be triggered choose events
+func (f WebhookForm) ChooseEvents() bool {
+ return f.Events == "choose_events"
+}
+
+// NewWebhookForm form for creating web hook
+type NewWebhookForm struct {
+ PayloadURL string `binding:"Required;ValidUrl"`
+ HTTPMethod string `binding:"Required;In(POST,GET)"`
+ ContentType int `binding:"Required"`
+ Secret string
+ WebhookForm
+}
+
+// Validate validates the fields
+func (f *NewWebhookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// NewGogshookForm form for creating gogs hook
+type NewGogshookForm struct {
+ PayloadURL string `binding:"Required;ValidUrl"`
+ ContentType int `binding:"Required"`
+ Secret string
+ WebhookForm
+}
+
+// Validate validates the fields
+func (f *NewGogshookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// NewSlackHookForm form for creating slack hook
+type NewSlackHookForm struct {
+ PayloadURL string `binding:"Required;ValidUrl"`
+ Channel string `binding:"Required"`
+ Username string
+ IconURL string
+ Color string
+ WebhookForm
+}
+
+// Validate validates the fields
+func (f *NewSlackHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// HasInvalidChannel validates the channel name is in the right format
+func (f NewSlackHookForm) HasInvalidChannel() bool {
+ return !utils.IsValidSlackChannel(f.Channel)
+}
+
+// NewDiscordHookForm form for creating discord hook
+type NewDiscordHookForm struct {
+ PayloadURL string `binding:"Required;ValidUrl"`
+ Username string
+ IconURL string
+ WebhookForm
+}
+
+// Validate validates the fields
+func (f *NewDiscordHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// NewDingtalkHookForm form for creating dingtalk hook
+type NewDingtalkHookForm struct {
+ PayloadURL string `binding:"Required;ValidUrl"`
+ WebhookForm
+}
+
+// Validate validates the fields
+func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// NewTelegramHookForm form for creating telegram hook
+type NewTelegramHookForm struct {
+ BotToken string `binding:"Required"`
+ ChatID string `binding:"Required"`
+ WebhookForm
+}
+
+// Validate validates the fields
+func (f *NewTelegramHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// NewMatrixHookForm form for creating Matrix hook
+type NewMatrixHookForm struct {
+ HomeserverURL string `binding:"Required;ValidUrl"`
+ RoomID string `binding:"Required"`
+ AccessToken string `binding:"Required"`
+ MessageType int
+ WebhookForm
+}
+
+// Validate validates the fields
+func (f *NewMatrixHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// NewMSTeamsHookForm form for creating MS Teams hook
+type NewMSTeamsHookForm struct {
+ PayloadURL string `binding:"Required;ValidUrl"`
+ WebhookForm
+}
+
+// Validate validates the fields
+func (f *NewMSTeamsHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// NewFeishuHookForm form for creating feishu hook
+type NewFeishuHookForm struct {
+ PayloadURL string `binding:"Required;ValidUrl"`
+ WebhookForm
+}
+
+// Validate validates the fields
+func (f *NewFeishuHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// .___
+// | | ______ ________ __ ____
+// | |/ ___// ___/ | \_/ __ \
+// | |\___ \ \___ \| | /\ ___/
+// |___/____ >____ >____/ \___ >
+// \/ \/ \/
+
+// CreateIssueForm form for creating issue
+type CreateIssueForm struct {
+ Title string `binding:"Required;MaxSize(255)"`
+ LabelIDs string `form:"label_ids"`
+ AssigneeIDs string `form:"assignee_ids"`
+ Ref string `form:"ref"`
+ MilestoneID int64
+ ProjectID int64
+ AssigneeID int64
+ Content string
+ Files []string
+}
+
+// Validate validates the fields
+func (f *CreateIssueForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// CreateCommentForm form for creating comment
+type CreateCommentForm struct {
+ Content string
+ Status string `binding:"OmitEmpty;In(reopen,close)"`
+ Files []string
+}
+
+// Validate validates the fields
+func (f *CreateCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// ReactionForm form for adding and removing reaction
+type ReactionForm struct {
+ Content string `binding:"Required"`
+}
+
+// Validate validates the fields
+func (f *ReactionForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// IssueLockForm form for locking an issue
+type IssueLockForm struct {
+ Reason string `binding:"Required"`
+}
+
+// Validate validates the fields
+func (i *IssueLockForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, i, ctx.Locale)
+}
+
+// HasValidReason checks to make sure that the reason submitted in
+// the form matches any of the values in the config
+func (i IssueLockForm) HasValidReason() bool {
+ if strings.TrimSpace(i.Reason) == "" {
+ return true
+ }
+
+ for _, v := range setting.Repository.Issue.LockReasons {
+ if v == i.Reason {
+ return true
+ }
+ }
+
+ return false
+}
+
+// __________ __ __
+// \______ \_______ ____ |__| ____ _____/ |_ ______
+// | ___/\_ __ \/ _ \ | |/ __ \_/ ___\ __\/ ___/
+// | | | | \( <_> ) | \ ___/\ \___| | \___ \
+// |____| |__| \____/\__| |\___ >\___ >__| /____ >
+// \______| \/ \/ \/
+
+// CreateProjectForm form for creating a project
+type CreateProjectForm struct {
+ Title string `binding:"Required;MaxSize(100)"`
+ Content string
+ BoardType models.ProjectBoardType
+}
+
+// UserCreateProjectForm is a from for creating an individual or organization
+// form.
+type UserCreateProjectForm struct {
+ Title string `binding:"Required;MaxSize(100)"`
+ Content string
+ BoardType models.ProjectBoardType
+ UID int64 `binding:"Required"`
+}
+
+// EditProjectBoardForm is a form for editing a project board
+type EditProjectBoardForm struct {
+ Title string `binding:"Required;MaxSize(100)"`
+ Sorting int8
+}
+
+// _____ .__.__ __
+// / \ |__| | ____ _______/ |_ ____ ____ ____
+// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
+// / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
+// \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
+// \/ \/ \/ \/ \/
+
+// CreateMilestoneForm form for creating milestone
+type CreateMilestoneForm struct {
+ Title string `binding:"Required;MaxSize(50)"`
+ Content string
+ Deadline string
+}
+
+// Validate validates the fields
+func (f *CreateMilestoneForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// .____ ___. .__
+// | | _____ \_ |__ ____ | |
+// | | \__ \ | __ \_/ __ \| |
+// | |___ / __ \| \_\ \ ___/| |__
+// |_______ (____ /___ /\___ >____/
+// \/ \/ \/ \/
+
+// CreateLabelForm form for creating label
+type CreateLabelForm struct {
+ ID int64
+ Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
+ Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
+ Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
+}
+
+// Validate validates the fields
+func (f *CreateLabelForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// InitializeLabelsForm form for initializing labels
+type InitializeLabelsForm struct {
+ TemplateName string `binding:"Required"`
+}
+
+// Validate validates the fields
+func (f *InitializeLabelsForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// __________ .__ .__ __________ __
+// \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
+// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
+// | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
+// |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
+// \/ \/ |__| \/ \/
+
+// MergePullRequestForm form for merging Pull Request
+// swagger:model MergePullRequestOption
+type MergePullRequestForm struct {
+ // required: true
+ // enum: merge,rebase,rebase-merge,squash,manually-merged
+ Do string `binding:"Required;In(merge,rebase,rebase-merge,squash,manually-merged)"`
+ MergeTitleField string
+ MergeMessageField string
+ MergeCommitID string // only used for manually-merged
+ ForceMerge *bool `json:"force_merge,omitempty"`
+}
+
+// Validate validates the fields
+func (f *MergePullRequestForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// CodeCommentForm form for adding code comments for PRs
+type CodeCommentForm struct {
+ Origin string `binding:"Required;In(timeline,diff)"`
+ Content string `binding:"Required"`
+ Side string `binding:"Required;In(previous,proposed)"`
+ Line int64
+ TreePath string `form:"path" binding:"Required"`
+ IsReview bool `form:"is_review"`
+ Reply int64 `form:"reply"`
+ LatestCommitID string
+}
+
+// Validate validates the fields
+func (f *CodeCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// SubmitReviewForm for submitting a finished code review
+type SubmitReviewForm struct {
+ Content string
+ Type string `binding:"Required;In(approve,comment,reject)"`
+ CommitID string
+}
+
+// Validate validates the fields
+func (f *SubmitReviewForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// ReviewType will return the corresponding reviewtype for type
+func (f SubmitReviewForm) ReviewType() models.ReviewType {
+ switch f.Type {
+ case "approve":
+ return models.ReviewTypeApprove
+ case "comment":
+ return models.ReviewTypeComment
+ case "reject":
+ return models.ReviewTypeReject
+ default:
+ return models.ReviewTypeUnknown
+ }
+}
+
+// HasEmptyContent checks if the content of the review form is empty.
+func (f SubmitReviewForm) HasEmptyContent() bool {
+ reviewType := f.ReviewType()
+
+ return (reviewType == models.ReviewTypeComment || reviewType == models.ReviewTypeReject) &&
+ len(strings.TrimSpace(f.Content)) == 0
+}
+
+// DismissReviewForm for dismissing stale review by repo admin
+type DismissReviewForm struct {
+ ReviewID int64 `binding:"Required"`
+ Message string
+}
+
+// __________ .__
+// \______ \ ____ | | ____ _____ ______ ____
+// | _// __ \| | _/ __ \\__ \ / ___// __ \
+// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
+// |____|_ /\___ >____/\___ >____ /____ >\___ >
+// \/ \/ \/ \/ \/ \/
+
+// NewReleaseForm form for creating release
+type NewReleaseForm struct {
+ TagName string `binding:"Required;GitRefName;MaxSize(255)"`
+ Target string `form:"tag_target" binding:"Required;MaxSize(255)"`
+ Title string `binding:"Required;MaxSize(255)"`
+ Content string
+ Draft string
+ TagOnly string
+ Prerelease bool
+ AddTagMsg bool
+ Files []string
+}
+
+// Validate validates the fields
+func (f *NewReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// EditReleaseForm form for changing release
+type EditReleaseForm struct {
+ Title string `form:"title" binding:"Required;MaxSize(255)"`
+ Content string `form:"content"`
+ Draft string `form:"draft"`
+ Prerelease bool `form:"prerelease"`
+ Files []string
+}
+
+// Validate validates the fields
+func (f *EditReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// __ __.__ __ .__
+// / \ / \__| | _|__|
+// \ \/\/ / | |/ / |
+// \ /| | <| |
+// \__/\ / |__|__|_ \__|
+// \/ \/
+
+// NewWikiForm form for creating wiki
+type NewWikiForm struct {
+ Title string `binding:"Required"`
+ Content string `binding:"Required"`
+ Message string
+}
+
+// Validate validates the fields
+// FIXME: use code generation to generate this method.
+func (f *NewWikiForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// ___________ .___.__ __
+// \_ _____/ __| _/|__|/ |_
+// | __)_ / __ | | \ __\
+// | \/ /_/ | | || |
+// /_______ /\____ | |__||__|
+// \/ \/
+
+// EditRepoFileForm form for changing repository file
+type EditRepoFileForm struct {
+ TreePath string `binding:"Required;MaxSize(500)"`
+ Content string
+ CommitSummary string `binding:"MaxSize(100)"`
+ CommitMessage string
+ CommitChoice string `binding:"Required;MaxSize(50)"`
+ NewBranchName string `binding:"GitRefName;MaxSize(100)"`
+ LastCommit string
+ Signoff bool
+}
+
+// Validate validates the fields
+func (f *EditRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// EditPreviewDiffForm form for changing preview diff
+type EditPreviewDiffForm struct {
+ Content string
+}
+
+// Validate validates the fields
+func (f *EditPreviewDiffForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// ____ ___ .__ .___
+// | | \______ | | _________ __| _/
+// | | /\____ \| | / _ \__ \ / __ |
+// | | / | |_> > |_( <_> ) __ \_/ /_/ |
+// |______/ | __/|____/\____(____ /\____ |
+// |__| \/ \/
+//
+
+// UploadRepoFileForm form for uploading repository file
+type UploadRepoFileForm struct {
+ TreePath string `binding:"MaxSize(500)"`
+ CommitSummary string `binding:"MaxSize(100)"`
+ CommitMessage string
+ CommitChoice string `binding:"Required;MaxSize(50)"`
+ NewBranchName string `binding:"GitRefName;MaxSize(100)"`
+ Files []string
+ Signoff bool
+}
+
+// Validate validates the fields
+func (f *UploadRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// RemoveUploadFileForm form for removing uploaded file
+type RemoveUploadFileForm struct {
+ File string `binding:"Required;MaxSize(50)"`
+}
+
+// Validate validates the fields
+func (f *RemoveUploadFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// ________ .__ __
+// \______ \ ____ | | _____/ |_ ____
+// | | \_/ __ \| | _/ __ \ __\/ __ \
+// | ` \ ___/| |_\ ___/| | \ ___/
+// /_______ /\___ >____/\___ >__| \___ >
+// \/ \/ \/ \/
+
+// DeleteRepoFileForm form for deleting repository file
+type DeleteRepoFileForm struct {
+ CommitSummary string `binding:"MaxSize(100)"`
+ CommitMessage string
+ CommitChoice string `binding:"Required;MaxSize(50)"`
+ NewBranchName string `binding:"GitRefName;MaxSize(100)"`
+ LastCommit string
+ Signoff bool
+}
+
+// Validate validates the fields
+func (f *DeleteRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// ___________.__ ___________ __
+// \__ ___/|__| _____ ____ \__ ___/___________ ____ | | __ ___________
+// | | | |/ \_/ __ \ | | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
+// | | | | Y Y \ ___/ | | | | \// __ \\ \___| <\ ___/| | \/
+// |____| |__|__|_| /\___ > |____| |__| (____ /\___ >__|_ \\___ >__|
+// \/ \/ \/ \/ \/ \/
+
+// AddTimeManuallyForm form that adds spent time manually.
+type AddTimeManuallyForm struct {
+ Hours int `binding:"Range(0,1000)"`
+ Minutes int `binding:"Range(0,1000)"`
+}
+
+// Validate validates the fields
+func (f *AddTimeManuallyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// SaveTopicForm form for save topics for repository
+type SaveTopicForm struct {
+ Topics []string `binding:"topics;Required;"`
+}
+
+// DeadlineForm hold the validation rules for deadlines
+type DeadlineForm struct {
+ DateString string `form:"date" binding:"Required;Size(10)"`
+}
+
+// Validate validates the fields
+func (f *DeadlineForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
--- /dev/null
+// Copyright 2018 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package forms
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/modules/setting"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestSubmitReviewForm_IsEmpty(t *testing.T) {
+
+ cases := []struct {
+ form SubmitReviewForm
+ expected bool
+ }{
+ // Approved PR with a comment shouldn't count as empty
+ {SubmitReviewForm{Type: "approve", Content: "Awesome"}, false},
+
+ // Approved PR without a comment shouldn't count as empty
+ {SubmitReviewForm{Type: "approve", Content: ""}, false},
+
+ // Rejected PR without a comment should count as empty
+ {SubmitReviewForm{Type: "reject", Content: ""}, true},
+
+ // Rejected PR with a comment shouldn't count as empty
+ {SubmitReviewForm{Type: "reject", Content: "Awesome"}, false},
+
+ // Comment review on a PR with a comment shouldn't count as empty
+ {SubmitReviewForm{Type: "comment", Content: "Awesome"}, false},
+
+ // Comment review on a PR without a comment should count as empty
+ {SubmitReviewForm{Type: "comment", Content: ""}, true},
+ }
+
+ for _, v := range cases {
+ assert.Equal(t, v.expected, v.form.HasEmptyContent())
+ }
+}
+
+func TestIssueLock_HasValidReason(t *testing.T) {
+
+ // Init settings
+ _ = setting.Repository
+
+ cases := []struct {
+ form IssueLockForm
+ expected bool
+ }{
+ {IssueLockForm{""}, true}, // an empty reason is accepted
+ {IssueLockForm{"Off-topic"}, true},
+ {IssueLockForm{"Too heated"}, true},
+ {IssueLockForm{"Spam"}, true},
+ {IssueLockForm{"Resolved"}, true},
+
+ {IssueLockForm{"ZZZZ"}, false},
+ {IssueLockForm{"I want to lock this issue"}, false},
+ }
+
+ for _, v := range cases {
+ assert.Equal(t, v.expected, v.form.HasValidReason())
+ }
+}
--- /dev/null
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Copyright 2018 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package forms
+
+import (
+ "mime/multipart"
+ "net/http"
+ "strings"
+
+ "code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/web/middleware"
+
+ "gitea.com/go-chi/binding"
+)
+
+// InstallForm form for installation page
+type InstallForm struct {
+ DbType string `binding:"Required"`
+ DbHost string
+ DbUser string
+ DbPasswd string
+ DbName string
+ SSLMode string
+ Charset string `binding:"Required;In(utf8,utf8mb4)"`
+ DbPath string
+ DbSchema string
+
+ AppName string `binding:"Required" locale:"install.app_name"`
+ RepoRootPath string `binding:"Required"`
+ LFSRootPath string
+ RunUser string `binding:"Required"`
+ Domain string `binding:"Required"`
+ SSHPort int
+ HTTPPort string `binding:"Required"`
+ AppURL string `binding:"Required"`
+ LogRootPath string `binding:"Required"`
+
+ SMTPHost string
+ SMTPFrom string
+ SMTPUser string `binding:"OmitEmpty;MaxSize(254)" locale:"install.mailer_user"`
+ SMTPPasswd string
+ RegisterConfirm bool
+ MailNotify bool
+
+ OfflineMode bool
+ DisableGravatar bool
+ EnableFederatedAvatar bool
+ EnableOpenIDSignIn bool
+ EnableOpenIDSignUp bool
+ DisableRegistration bool
+ AllowOnlyExternalRegistration bool
+ EnableCaptcha bool
+ RequireSignInView bool
+ DefaultKeepEmailPrivate bool
+ DefaultAllowCreateOrganization bool
+ DefaultEnableTimetracking bool
+ NoReplyAddress string
+
+ PasswordAlgorithm string
+
+ AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
+ AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
+ AdminConfirmPasswd string
+ AdminEmail string `binding:"OmitEmpty;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
+}
+
+// Validate validates the fields
+func (f *InstallForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// _____ ____ _________________ ___
+// / _ \ | | \__ ___/ | \
+// / /_\ \| | / | | / ~ \
+// / | \ | / | | \ Y /
+// \____|__ /______/ |____| \___|_ /
+// \/ \/
+
+// RegisterForm form for registering
+type RegisterForm struct {
+ UserName string `binding:"Required;AlphaDashDot;MaxSize(40)"`
+ Email string `binding:"Required;Email;MaxSize(254)"`
+ Password string `binding:"MaxSize(255)"`
+ Retype string
+ GRecaptchaResponse string `form:"g-recaptcha-response"`
+ HcaptchaResponse string `form:"h-captcha-response"`
+}
+
+// Validate validates the fields
+func (f *RegisterForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// IsEmailDomainListed checks whether the domain of an email address
+// matches a list of domains
+func IsEmailDomainListed(list []string, email string) bool {
+ if len(list) == 0 {
+ return false
+ }
+
+ n := strings.LastIndex(email, "@")
+ if n <= 0 {
+ return false
+ }
+
+ domain := strings.ToLower(email[n+1:])
+
+ for _, v := range list {
+ if strings.ToLower(v) == domain {
+ return true
+ }
+ }
+
+ return false
+}
+
+// IsEmailDomainAllowed validates that the email address
+// provided by the user matches what has been configured .
+// The email is marked as allowed if it matches any of the
+// domains in the whitelist or if it doesn't match any of
+// domains in the blocklist, if any such list is not empty.
+func (f RegisterForm) IsEmailDomainAllowed() bool {
+ if len(setting.Service.EmailDomainWhitelist) == 0 {
+ return !IsEmailDomainListed(setting.Service.EmailDomainBlocklist, f.Email)
+ }
+
+ return IsEmailDomainListed(setting.Service.EmailDomainWhitelist, f.Email)
+}
+
+// MustChangePasswordForm form for updating your password after account creation
+// by an admin
+type MustChangePasswordForm struct {
+ Password string `binding:"Required;MaxSize(255)"`
+ Retype string
+}
+
+// Validate validates the fields
+func (f *MustChangePasswordForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// SignInForm form for signing in with user/password
+type SignInForm struct {
+ UserName string `binding:"Required;MaxSize(254)"`
+ // TODO remove required from password for SecondFactorAuthentication
+ Password string `binding:"Required;MaxSize(255)"`
+ Remember bool
+}
+
+// Validate validates the fields
+func (f *SignInForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// AuthorizationForm form for authorizing oauth2 clients
+type AuthorizationForm struct {
+ ResponseType string `binding:"Required;In(code)"`
+ ClientID string `binding:"Required"`
+ RedirectURI string
+ State string
+ Scope string
+ Nonce string
+
+ // PKCE support
+ CodeChallengeMethod string // S256, plain
+ CodeChallenge string
+}
+
+// Validate validates the fields
+func (f *AuthorizationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// GrantApplicationForm form for authorizing oauth2 clients
+type GrantApplicationForm struct {
+ ClientID string `binding:"Required"`
+ RedirectURI string
+ State string
+ Scope string
+ Nonce string
+}
+
+// Validate validates the fields
+func (f *GrantApplicationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// AccessTokenForm for issuing access tokens from authorization codes or refresh tokens
+type AccessTokenForm struct {
+ GrantType string `json:"grant_type"`
+ ClientID string `json:"client_id"`
+ ClientSecret string `json:"client_secret"`
+ RedirectURI string `json:"redirect_uri"`
+ Code string `json:"code"`
+ RefreshToken string `json:"refresh_token"`
+
+ // PKCE support
+ CodeVerifier string `json:"code_verifier"`
+}
+
+// Validate validates the fields
+func (f *AccessTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// __________________________________________.___ _______ ________ _________
+// / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
+// \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
+// / \ | \ | | | | | / | \ \_\ \/ \
+// /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
+// \/ \/ \/ \/ \/
+
+// UpdateProfileForm form for updating profile
+type UpdateProfileForm struct {
+ Name string `binding:"AlphaDashDot;MaxSize(40)"`
+ FullName string `binding:"MaxSize(100)"`
+ KeepEmailPrivate bool
+ Website string `binding:"ValidUrl;MaxSize(255)"`
+ Location string `binding:"MaxSize(50)"`
+ Language string
+ Description string `binding:"MaxSize(255)"`
+ KeepActivityPrivate bool
+}
+
+// Validate validates the fields
+func (f *UpdateProfileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// Avatar types
+const (
+ AvatarLocal string = "local"
+ AvatarByMail string = "bymail"
+)
+
+// AvatarForm form for changing avatar
+type AvatarForm struct {
+ Source string
+ Avatar *multipart.FileHeader
+ Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
+ Federavatar bool
+}
+
+// Validate validates the fields
+func (f *AvatarForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// AddEmailForm form for adding new email
+type AddEmailForm struct {
+ Email string `binding:"Required;Email;MaxSize(254)"`
+}
+
+// Validate validates the fields
+func (f *AddEmailForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// UpdateThemeForm form for updating a users' theme
+type UpdateThemeForm struct {
+ Theme string `binding:"Required;MaxSize(30)"`
+}
+
+// Validate validates the field
+func (f *UpdateThemeForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// IsThemeExists checks if the theme is a theme available in the config.
+func (f UpdateThemeForm) IsThemeExists() bool {
+ var exists bool
+
+ for _, v := range setting.UI.Themes {
+ if strings.EqualFold(v, f.Theme) {
+ exists = true
+ break
+ }
+ }
+
+ return exists
+}
+
+// ChangePasswordForm form for changing password
+type ChangePasswordForm struct {
+ OldPassword string `form:"old_password" binding:"MaxSize(255)"`
+ Password string `form:"password" binding:"Required;MaxSize(255)"`
+ Retype string `form:"retype"`
+}
+
+// Validate validates the fields
+func (f *ChangePasswordForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// AddOpenIDForm is for changing openid uri
+type AddOpenIDForm struct {
+ Openid string `binding:"Required;MaxSize(256)"`
+}
+
+// Validate validates the fields
+func (f *AddOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// AddKeyForm form for adding SSH/GPG key
+type AddKeyForm struct {
+ Type string `binding:"OmitEmpty"`
+ Title string `binding:"Required;MaxSize(50)"`
+ Content string `binding:"Required"`
+ IsWritable bool
+}
+
+// Validate validates the fields
+func (f *AddKeyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// NewAccessTokenForm form for creating access token
+type NewAccessTokenForm struct {
+ Name string `binding:"Required;MaxSize(255)"`
+}
+
+// Validate validates the fields
+func (f *NewAccessTokenForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// EditOAuth2ApplicationForm form for editing oauth2 applications
+type EditOAuth2ApplicationForm struct {
+ Name string `binding:"Required;MaxSize(255)" form:"application_name"`
+ RedirectURI string `binding:"Required" form:"redirect_uri"`
+}
+
+// Validate validates the fields
+func (f *EditOAuth2ApplicationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// TwoFactorAuthForm for logging in with 2FA token.
+type TwoFactorAuthForm struct {
+ Passcode string `binding:"Required"`
+}
+
+// Validate validates the fields
+func (f *TwoFactorAuthForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// TwoFactorScratchAuthForm for logging in with 2FA scratch token.
+type TwoFactorScratchAuthForm struct {
+ Token string `binding:"Required"`
+}
+
+// Validate validates the fields
+func (f *TwoFactorScratchAuthForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// U2FRegistrationForm for reserving an U2F name
+type U2FRegistrationForm struct {
+ Name string `binding:"Required"`
+}
+
+// Validate validates the fields
+func (f *U2FRegistrationForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// U2FDeleteForm for deleting U2F keys
+type U2FDeleteForm struct {
+ ID int64 `binding:"Required"`
+}
+
+// Validate validates the fields
+func (f *U2FDeleteForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
--- /dev/null
+// Copyright 2017 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package forms
+
+import (
+ "net/http"
+
+ "code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/web/middleware"
+ "gitea.com/go-chi/binding"
+)
+
+// SignInOpenIDForm form for signing in with OpenID
+type SignInOpenIDForm struct {
+ Openid string `binding:"Required;MaxSize(256)"`
+ Remember bool
+}
+
+// Validate validates the fields
+func (f *SignInOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// SignUpOpenIDForm form for signin up with OpenID
+type SignUpOpenIDForm struct {
+ UserName string `binding:"Required;AlphaDashDot;MaxSize(40)"`
+ Email string `binding:"Required;Email;MaxSize(254)"`
+ GRecaptchaResponse string `form:"g-recaptcha-response"`
+ HcaptchaResponse string `form:"h-captcha-response"`
+}
+
+// Validate validates the fields
+func (f *SignUpOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
+
+// ConnectOpenIDForm form for connecting an existing account to an OpenID URI
+type ConnectOpenIDForm struct {
+ UserName string `binding:"Required;MaxSize(254)"`
+ Password string `binding:"Required;MaxSize(255)"`
+}
+
+// Validate validates the fields
+func (f *ConnectOpenIDForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
+ ctx := context.GetContext(req)
+ return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
+}
--- /dev/null
+// Copyright 2018 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package forms
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/modules/setting"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestRegisterForm_IsDomainAllowed_Empty(t *testing.T) {
+ _ = setting.Service
+
+ setting.Service.EmailDomainWhitelist = []string{}
+
+ form := RegisterForm{}
+
+ assert.True(t, form.IsEmailDomainAllowed())
+}
+
+func TestRegisterForm_IsDomainAllowed_InvalidEmail(t *testing.T) {
+ _ = setting.Service
+
+ setting.Service.EmailDomainWhitelist = []string{"gitea.io"}
+
+ tt := []struct {
+ email string
+ }{
+ {"securitygieqqq"},
+ {"hdudhdd"},
+ }
+
+ for _, v := range tt {
+ form := RegisterForm{Email: v.email}
+
+ assert.False(t, form.IsEmailDomainAllowed())
+ }
+}
+
+func TestRegisterForm_IsDomainAllowed_WhitelistedEmail(t *testing.T) {
+ _ = setting.Service
+
+ setting.Service.EmailDomainWhitelist = []string{"gitea.io"}
+
+ tt := []struct {
+ email string
+ valid bool
+ }{
+ {"security@gitea.io", true},
+ {"security@gITea.io", true},
+ {"hdudhdd", false},
+ {"seee@example.com", false},
+ }
+
+ for _, v := range tt {
+ form := RegisterForm{Email: v.email}
+
+ assert.Equal(t, v.valid, form.IsEmailDomainAllowed())
+ }
+}
+
+func TestRegisterForm_IsDomainAllowed_BlocklistedEmail(t *testing.T) {
+ _ = setting.Service
+
+ setting.Service.EmailDomainWhitelist = []string{}
+ setting.Service.EmailDomainBlocklist = []string{"gitea.io"}
+
+ tt := []struct {
+ email string
+ valid bool
+ }{
+ {"security@gitea.io", false},
+ {"security@gitea.example", true},
+ {"hdudhdd", true},
+ }
+
+ for _, v := range tt {
+ form := RegisterForm{Email: v.email}
+
+ assert.Equal(t, v.valid, form.IsEmailDomainAllowed())
+ }
+}
}
},
"x-go-name": "MergePullRequestForm",
- "x-go-package": "code.gitea.io/gitea/modules/forms"
+ "x-go-package": "code.gitea.io/gitea/services/forms"
},
"MigrateRepoForm": {
"description": "MigrateRepoForm form for migrating repository\nthis is used to interact with web ui",
"x-go-name": "Wiki"
}
},
- "x-go-package": "code.gitea.io/gitea/modules/forms"
+ "x-go-package": "code.gitea.io/gitea/services/forms"
},
"MigrateRepoOptions": {
"description": "MigrateRepoOptions options for migrating repository's\nthis is used to interact with api v1",