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.

205 lines
6.5 KiB

10 years ago
9 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. "github.com/Unknwon/macaron"
  7. "github.com/macaron-contrib/binding"
  8. )
  9. // _______________________________________ _________.______________________ _______________.___.
  10. // \______ \_ _____/\______ \_____ \ / _____/| \__ ___/\_____ \\______ \__ | |
  11. // | _/| __)_ | ___// | \ \_____ \ | | | | / | \| _// | |
  12. // | | \| \ | | / | \/ \| | | | / | \ | \\____ |
  13. // |____|_ /_______ / |____| \_______ /_______ /|___| |____| \_______ /____|_ // ______|
  14. // \/ \/ \/ \/ \/ \/ \/
  15. type CreateRepoForm struct {
  16. Uid int64 `binding:"Required"`
  17. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  18. Private bool
  19. Description string `binding:"MaxSize(255)"`
  20. AutoInit bool
  21. Gitignores string
  22. License string
  23. Readme string
  24. }
  25. func (f *CreateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  26. return validate(errs, ctx.Data, f, ctx.Locale)
  27. }
  28. type MigrateRepoForm struct {
  29. CloneAddr string `binding:"Required"`
  30. AuthUsername string
  31. AuthPassword string
  32. Mirror bool
  33. Uid int64 `binding:"Required"`
  34. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  35. Private bool
  36. Description string `binding:"MaxSize(255)"`
  37. }
  38. func (f *MigrateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  39. return validate(errs, ctx.Data, f, ctx.Locale)
  40. }
  41. type RepoSettingForm struct {
  42. RepoName string `form:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  43. Description string `form:"desc" binding:"MaxSize(255)"`
  44. Website string `form:"site" binding:"Url;MaxSize(100)"`
  45. Branch string `form:"branch"`
  46. Interval int `form:"interval"`
  47. Private bool `form:"private"`
  48. }
  49. func (f *RepoSettingForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  50. return validate(errs, ctx.Data, f, ctx.Locale)
  51. }
  52. // __ __ ___. .__ .__ __
  53. // / \ / \ ____\_ |__ | |__ | |__ ____ | | __
  54. // \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
  55. // \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
  56. // \__/\ / \___ >___ /___| /___| /\____/|__|_ \
  57. // \/ \/ \/ \/ \/ \/
  58. type WebhookForm struct {
  59. Events string
  60. Create bool
  61. Push bool
  62. Active bool
  63. }
  64. func (f WebhookForm) PushOnly() bool {
  65. return f.Events == "push_only"
  66. }
  67. func (f WebhookForm) SendEverything() bool {
  68. return f.Events == "send_everything"
  69. }
  70. func (f WebhookForm) ChooseEvents() bool {
  71. return f.Events == "choose_events"
  72. }
  73. type NewWebhookForm struct {
  74. PayloadURL string `binding:"Required;Url"`
  75. ContentType int `binding:"Required"`
  76. Secret string
  77. WebhookForm
  78. }
  79. func (f *NewWebhookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  80. return validate(errs, ctx.Data, f, ctx.Locale)
  81. }
  82. type NewSlackHookForm struct {
  83. PayloadURL string `binding:"Required`
  84. Channel string `binding:"Required"`
  85. Username string
  86. IconURL string
  87. Color string
  88. WebhookForm
  89. }
  90. func (f *NewSlackHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  91. return validate(errs, ctx.Data, f, ctx.Locale)
  92. }
  93. // .___
  94. // | | ______ ________ __ ____
  95. // | |/ ___// ___/ | \_/ __ \
  96. // | |\___ \ \___ \| | /\ ___/
  97. // |___/____ >____ >____/ \___ >
  98. // \/ \/ \/
  99. type CreateIssueForm struct {
  100. Title string `binding:"Required;MaxSize(255)"`
  101. LabelIDs string `form:"label_ids"`
  102. MilestoneID int64
  103. AssigneeID int64
  104. Content string
  105. Attachments []string
  106. }
  107. func (f *CreateIssueForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  108. return validate(errs, ctx.Data, f, ctx.Locale)
  109. }
  110. type CreateCommentForm struct {
  111. Content string
  112. Status string `binding:"OmitEmpty;In(reopen,close)"`
  113. Attachments []string
  114. }
  115. func (f *CreateCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  116. return validate(errs, ctx.Data, f, ctx.Locale)
  117. }
  118. // _____ .__.__ __
  119. // / \ |__| | ____ _______/ |_ ____ ____ ____
  120. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  121. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  122. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  123. // \/ \/ \/ \/ \/
  124. type CreateMilestoneForm struct {
  125. Title string `binding:"Required;MaxSize(50)"`
  126. Content string
  127. Deadline string
  128. }
  129. func (f *CreateMilestoneForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  130. return validate(errs, ctx.Data, f, ctx.Locale)
  131. }
  132. // .____ ___. .__
  133. // | | _____ \_ |__ ____ | |
  134. // | | \__ \ | __ \_/ __ \| |
  135. // | |___ / __ \| \_\ \ ___/| |__
  136. // |_______ (____ /___ /\___ >____/
  137. // \/ \/ \/ \/
  138. type CreateLabelForm struct {
  139. ID int64
  140. Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_name"`
  141. Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
  142. }
  143. func (f *CreateLabelForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  144. return validate(errs, ctx.Data, f, ctx.Locale)
  145. }
  146. // __________ .__
  147. // \______ \ ____ | | ____ _____ ______ ____
  148. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  149. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  150. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  151. // \/ \/ \/ \/ \/ \/
  152. type NewReleaseForm struct {
  153. TagName string `form:"tag_name" binding:"Required"`
  154. Target string `form:"tag_target" binding:"Required"`
  155. Title string `form:"title" binding:"Required"`
  156. Content string `form:"content" binding:"Required"`
  157. Draft string `form:"draft"`
  158. Prerelease bool `form:"prerelease"`
  159. }
  160. func (f *NewReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  161. return validate(errs, ctx.Data, f, ctx.Locale)
  162. }
  163. type EditReleaseForm struct {
  164. Title string `form:"title" binding:"Required"`
  165. Content string `form:"content" binding:"Required"`
  166. Draft string `form:"draft"`
  167. Prerelease bool `form:"prerelease"`
  168. }
  169. func (f *EditReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  170. return validate(errs, ctx.Data, f, ctx.Locale)
  171. }