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.

252 lines
8.1 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
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. Uid int64 `form:"uid" binding:"Required"`
  20. RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"`
  21. Private bool `form:"private"`
  22. Description string `form:"desc" binding:"MaxSize(255)"`
  23. Language string `form:"language"`
  24. License string `form:"license"`
  25. InitReadme bool `form:"initReadme"`
  26. }
  27. func (f *CreateRepoForm) Name(field string) string {
  28. names := map[string]string{
  29. "RepoName": "Repository name",
  30. "Description": "Description",
  31. }
  32. return names[field]
  33. }
  34. func (f *CreateRepoForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  35. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  36. validate(errors, data, f)
  37. }
  38. type MigrateRepoForm struct {
  39. Url string `form:"url" binding:"Url"`
  40. AuthUserName string `form:"auth_username"`
  41. AuthPasswd string `form:"auth_password"`
  42. Uid int64 `form:"uid" binding:"Required"`
  43. RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"`
  44. Mirror bool `form:"mirror"`
  45. Private bool `form:"private"`
  46. Description string `form:"desc" binding:"MaxSize(255)"`
  47. }
  48. func (f *MigrateRepoForm) Name(field string) string {
  49. names := map[string]string{
  50. "Url": "Migration URL",
  51. "RepoName": "Repository name",
  52. "Description": "Description",
  53. }
  54. return names[field]
  55. }
  56. func (f *MigrateRepoForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  57. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  58. validate(errors, data, f)
  59. }
  60. type RepoSettingForm struct {
  61. RepoName string `form:"name" binding:"Required;AlphaDash;MaxSize(100)"`
  62. Description string `form:"desc" binding:"MaxSize(255)"`
  63. Website string `form:"site" binding:"Url;MaxSize(100)"`
  64. Branch string `form:"branch"`
  65. Interval int `form:"interval"`
  66. Private bool `form:"private"`
  67. GoGet bool `form:"goget"`
  68. }
  69. func (f *RepoSettingForm) Name(field string) string {
  70. names := map[string]string{
  71. "RepoName": "Repository name",
  72. "Description": "Description",
  73. "Website": "Website address",
  74. }
  75. return names[field]
  76. }
  77. func (f *RepoSettingForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  78. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  79. validate(errors, data, f)
  80. }
  81. // __ __ ___. .__ .__ __
  82. // / \ / \ ____\_ |__ | |__ | |__ ____ | | __
  83. // \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
  84. // \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
  85. // \__/\ / \___ >___ /___| /___| /\____/|__|_ \
  86. // \/ \/ \/ \/ \/ \/
  87. type NewWebhookForm struct {
  88. Url string `form:"url" binding:"Required;Url"`
  89. ContentType string `form:"content_type" binding:"Required"`
  90. Secret string `form:"secret""`
  91. PushOnly bool `form:"push_only"`
  92. Active bool `form:"active"`
  93. }
  94. func (f *NewWebhookForm) Name(field string) string {
  95. names := map[string]string{
  96. "Url": "Payload URL",
  97. "ContentType": "Content type",
  98. }
  99. return names[field]
  100. }
  101. func (f *NewWebhookForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  102. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  103. validate(errors, data, f)
  104. }
  105. // .___
  106. // | | ______ ________ __ ____
  107. // | |/ ___// ___/ | \_/ __ \
  108. // | |\___ \ \___ \| | /\ ___/
  109. // |___/____ >____ >____/ \___ >
  110. // \/ \/ \/
  111. type CreateIssueForm struct {
  112. IssueName string `form:"title" binding:"Required;MaxSize(50)"`
  113. MilestoneId int64 `form:"milestoneid"`
  114. AssigneeId int64 `form:"assigneeid"`
  115. Labels string `form:"labels"`
  116. Content string `form:"content"`
  117. }
  118. func (f *CreateIssueForm) Name(field string) string {
  119. names := map[string]string{
  120. "IssueName": "Issue name",
  121. }
  122. return names[field]
  123. }
  124. func (f *CreateIssueForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  125. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  126. validate(errors, data, f)
  127. }
  128. // _____ .__.__ __
  129. // / \ |__| | ____ _______/ |_ ____ ____ ____
  130. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  131. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  132. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  133. // \/ \/ \/ \/ \/
  134. type CreateMilestoneForm struct {
  135. Title string `form:"title" binding:"Required;MaxSize(50)"`
  136. Content string `form:"content"`
  137. Deadline string `form:"due_date"`
  138. }
  139. func (f *CreateMilestoneForm) Name(field string) string {
  140. names := map[string]string{
  141. "Title": "Milestone name",
  142. }
  143. return names[field]
  144. }
  145. func (f *CreateMilestoneForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  146. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  147. validate(errors, data, f)
  148. }
  149. // .____ ___. .__
  150. // | | _____ \_ |__ ____ | |
  151. // | | \__ \ | __ \_/ __ \| |
  152. // | |___ / __ \| \_\ \ ___/| |__
  153. // |_______ (____ /___ /\___ >____/
  154. // \/ \/ \/ \/
  155. type CreateLabelForm struct {
  156. Title string `form:"title" binding:"Required;MaxSize(50)"`
  157. Color string `form:"color" binding:"Required;Size(7)"`
  158. }
  159. func (f *CreateLabelForm) Name(field string) string {
  160. names := map[string]string{
  161. "Title": "Label name",
  162. "Color": "Label color",
  163. }
  164. return names[field]
  165. }
  166. func (f *CreateLabelForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  167. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  168. validate(errors, data, f)
  169. }
  170. // __________ .__
  171. // \______ \ ____ | | ____ _____ ______ ____
  172. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  173. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  174. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  175. // \/ \/ \/ \/ \/ \/
  176. type NewReleaseForm struct {
  177. TagName string `form:"tag_name" binding:"Required"`
  178. Target string `form:"tag_target" binding:"Required"`
  179. Title string `form:"title" binding:"Required"`
  180. Content string `form:"content" binding:"Required"`
  181. Draft string `form:"draft"`
  182. Prerelease bool `form:"prerelease"`
  183. }
  184. func (f *NewReleaseForm) Name(field string) string {
  185. names := map[string]string{
  186. "TagName": "Tag name",
  187. "Target": "Target",
  188. "Title": "Release title",
  189. "Content": "Release content",
  190. }
  191. return names[field]
  192. }
  193. func (f *NewReleaseForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  194. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  195. validate(errors, data, f)
  196. }
  197. type EditReleaseForm struct {
  198. Target string `form:"tag_target" binding:"Required"`
  199. Title string `form:"title" binding:"Required"`
  200. Content string `form:"content" binding:"Required"`
  201. Draft string `form:"draft"`
  202. Prerelease bool `form:"prerelease"`
  203. }
  204. func (f *EditReleaseForm) Name(field string) string {
  205. names := map[string]string{
  206. "Target": "Target",
  207. "Title": "Release title",
  208. "Content": "Release content",
  209. }
  210. return names[field]
  211. }
  212. func (f *EditReleaseForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) {
  213. data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData)
  214. validate(errors, data, f)
  215. }