You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
6.5 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package auth
  5. import (
  6. "net/http"
  7. "reflect"
  8. "github.com/go-martini/martini"
  9. "github.com/gogits/gogs/modules/base"
  10. "github.com/gogits/gogs/modules/middleware/binding"
  11. )
  12. // __________ .__ __
  13. // \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
  14. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |
  15. // | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ |
  16. // |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____|
  17. // \/ \/|__| \/ \/
  18. type CreateRepoForm struct {
  19. RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"`
  20. Private bool `form:"private"`
  21. Description string `form:"desc" binding:"MaxSize(100)"`
  22. Language string `form:"language"`
  23. License string `form:"license"`
  24. InitReadme bool `form:"initReadme"`
  25. }
  26. func (f *CreateRepoForm) Name(field string) string {
  27. names := map[string]string{
  28. "RepoName": "Repository name",
  29. "Description": "Description",
  30. }
  31. return names[field]
  32. }
  33. func (f *CreateRepoForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  34. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  35. validate(errors, data, f)
  36. }
  37. type MigrateRepoForm struct {
  38. Url string `form:"url" binding:"Url"`
  39. AuthUserName string `form:"auth_username"`
  40. AuthPasswd string `form:"auth_password"`
  41. RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"`
  42. Mirror bool `form:"mirror"`
  43. Private bool `form:"private"`
  44. Description string `form:"desc" binding:"MaxSize(100)"`
  45. }
  46. func (f *MigrateRepoForm) Name(field string) string {
  47. names := map[string]string{
  48. "Url": "Migration URL",
  49. "RepoName": "Repository name",
  50. "Description": "Description",
  51. }
  52. return names[field]
  53. }
  54. func (f *MigrateRepoForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  55. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  56. validate(errors, data, f)
  57. }
  58. type RepoSettingForm struct {
  59. RepoName string `form:"name" binding:"Required;AlphaDash;MaxSize(100)"`
  60. Description string `form:"desc" binding:"MaxSize(100)"`
  61. Website string `form:"site" binding:"Url;MaxSize(100)"`
  62. Branch string `form:"branch"`
  63. Interval int `form:"interval"`
  64. Private bool `form:"private"`
  65. GoGet bool `form:"goget"`
  66. }
  67. func (f *RepoSettingForm) Name(field string) string {
  68. names := map[string]string{
  69. "RepoName": "Repository name",
  70. "Description": "Description",
  71. "Website": "Website address",
  72. }
  73. return names[field]
  74. }
  75. func (f *RepoSettingForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  76. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  77. validate(errors, data, f)
  78. }
  79. // __ __ ___. .__ .__ __
  80. // / \ / \ ____\_ |__ | |__ | |__ ____ | | __
  81. // \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
  82. // \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
  83. // \__/\ / \___ >___ /___| /___| /\____/|__|_ \
  84. // \/ \/ \/ \/ \/ \/
  85. type NewWebhookForm struct {
  86. Url string `form:"url" binding:"Required;Url"`
  87. ContentType string `form:"content_type" binding:"Required"`
  88. Secret string `form:"secret""`
  89. PushOnly bool `form:"push_only"`
  90. Active bool `form:"active"`
  91. }
  92. func (f *NewWebhookForm) Name(field string) string {
  93. names := map[string]string{
  94. "Url": "Payload URL",
  95. "ContentType": "Content type",
  96. }
  97. return names[field]
  98. }
  99. func (f *NewWebhookForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  100. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  101. validate(errors, data, f)
  102. }
  103. // .___
  104. // | | ______ ________ __ ____
  105. // | |/ ___// ___/ | \_/ __ \
  106. // | |\___ \ \___ \| | /\ ___/
  107. // |___/____ >____ >____/ \___ >
  108. // \/ \/ \/
  109. type CreateIssueForm struct {
  110. IssueName string `form:"title" binding:"Required;MaxSize(50)"`
  111. MilestoneId int64 `form:"milestoneid"`
  112. AssigneeId int64 `form:"assigneeid"`
  113. Labels string `form:"labels"`
  114. Content string `form:"content"`
  115. }
  116. func (f *CreateIssueForm) Name(field string) string {
  117. names := map[string]string{
  118. "IssueName": "Issue name",
  119. }
  120. return names[field]
  121. }
  122. func (f *CreateIssueForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  123. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  124. validate(errors, data, f)
  125. }
  126. // _____ .__.__ __
  127. // / \ |__| | ____ _______/ |_ ____ ____ ____
  128. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  129. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  130. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  131. // \/ \/ \/ \/ \/
  132. type CreateMilestoneForm struct {
  133. Title string `form:"title" binding:"Required;MaxSize(50)"`
  134. Content string `form:"content"`
  135. Deadline string `form:"due_date"`
  136. }
  137. func (f *CreateMilestoneForm) Name(field string) string {
  138. names := map[string]string{
  139. "Title": "Milestone name",
  140. }
  141. return names[field]
  142. }
  143. func (f *CreateMilestoneForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  144. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  145. validate(errors, data, f)
  146. }
  147. // __________ .__
  148. // \______ \ ____ | | ____ _____ ______ ____
  149. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  150. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  151. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  152. // \/ \/ \/ \/ \/ \/
  153. type NewReleaseForm struct {
  154. TagName string `form:"tag_name" binding:"Required"`
  155. Title string `form:"title" binding:"Required"`
  156. Content string `form:"content" binding:"Required"`
  157. Prerelease bool `form:"prerelease"`
  158. }
  159. func (f *NewReleaseForm) Name(field string) string {
  160. names := map[string]string{
  161. "TagName": "Tag name",
  162. "Title": "Release title",
  163. "Content": "Release content",
  164. }
  165. return names[field]
  166. }
  167. func (f *NewReleaseForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  168. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  169. validate(errors, data, f)
  170. }