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.

177 lines
6.6 KiB

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. "github.com/Unknwon/macaron"
  7. "github.com/macaron-contrib/binding"
  8. )
  9. // _______________________________________ _________.______________________ _______________.___.
  10. // \______ \_ _____/\______ \_____ \ / _____/| \__ ___/\_____ \\______ \__ | |
  11. // | _/| __)_ | ___// | \ \_____ \ | | | | / | \| _// | |
  12. // | | \| \ | | / | \/ \| | | | / | \ | \\____ |
  13. // |____|_ /_______ / |____| \_______ /_______ /|___| |____| \_______ /____|_ // ______|
  14. // \/ \/ \/ \/ \/ \/ \/
  15. type CreateRepoForm struct {
  16. Uid int64 `form:"uid" binding:"Required"`
  17. RepoName string `form:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  18. Private bool `form:"private"`
  19. Description string `form:"desc" binding:"MaxSize(255)"`
  20. Gitignore string `form:"gitignore"`
  21. License string `form:"license"`
  22. InitReadme bool `form:"init_readme"`
  23. }
  24. func (f *CreateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  25. return validate(errs, ctx.Data, f, ctx.Locale)
  26. }
  27. type MigrateRepoForm struct {
  28. HttpsUrl string `form:"url" binding:"Required;Url"`
  29. AuthUserName string `form:"auth_username"`
  30. AuthPasswd string `form:"auth_password"`
  31. Uid int64 `form:"uid" binding:"Required"`
  32. RepoName string `form:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  33. Mirror bool `form:"mirror"`
  34. Private bool `form:"private"`
  35. Description string `form:"desc" binding:"MaxSize(255)"`
  36. }
  37. func (f *MigrateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  38. return validate(errs, ctx.Data, f, ctx.Locale)
  39. }
  40. type RepoSettingForm struct {
  41. RepoName string `form:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  42. Description string `form:"desc" binding:"MaxSize(255)"`
  43. Website string `form:"site" binding:"Url;MaxSize(100)"`
  44. Branch string `form:"branch"`
  45. Interval int `form:"interval"`
  46. Private bool `form:"private"`
  47. GoGet bool `form:"goget"`
  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 NewWebhookForm struct {
  59. HookTaskType string `form:"hook_type" binding:"Required"`
  60. PayloadUrl string `form:"payload_url" binding:"Required;Url"`
  61. ContentType string `form:"content_type" binding:"Required"`
  62. Secret string `form:"secret"`
  63. PushOnly bool `form:"push_only"`
  64. Active bool `form:"active"`
  65. }
  66. func (f *NewWebhookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  67. return validate(errs, ctx.Data, f, ctx.Locale)
  68. }
  69. type NewSlackHookForm struct {
  70. HookTaskType string `form:"hook_type" binding:"Required"`
  71. Domain string `form:"domain" binding:"Required`
  72. Token string `form:"token" binding:"Required"`
  73. Channel string `form:"channel" binding:"Required"`
  74. PushOnly bool `form:"push_only"`
  75. Active bool `form:"active"`
  76. }
  77. func (f *NewSlackHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  78. return validate(errs, ctx.Data, f, ctx.Locale)
  79. }
  80. // .___
  81. // | | ______ ________ __ ____
  82. // | |/ ___// ___/ | \_/ __ \
  83. // | |\___ \ \___ \| | /\ ___/
  84. // |___/____ >____ >____/ \___ >
  85. // \/ \/ \/
  86. type CreateIssueForm struct {
  87. IssueName string `form:"title" binding:"Required;MaxSize(255)"`
  88. MilestoneId int64 `form:"milestoneid"`
  89. AssigneeId int64 `form:"assigneeid"`
  90. Labels string `form:"labels"`
  91. Content string `form:"content"`
  92. }
  93. func (f *CreateIssueForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  94. return validate(errs, ctx.Data, f, ctx.Locale)
  95. }
  96. // _____ .__.__ __
  97. // / \ |__| | ____ _______/ |_ ____ ____ ____
  98. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  99. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  100. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  101. // \/ \/ \/ \/ \/
  102. type CreateMilestoneForm struct {
  103. Title string `form:"title" binding:"Required;MaxSize(50)"`
  104. Content string `form:"content"`
  105. Deadline string `form:"due_date"`
  106. }
  107. func (f *CreateMilestoneForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  108. return validate(errs, ctx.Data, f, ctx.Locale)
  109. }
  110. // .____ ___. .__
  111. // | | _____ \_ |__ ____ | |
  112. // | | \__ \ | __ \_/ __ \| |
  113. // | |___ / __ \| \_\ \ ___/| |__
  114. // |_______ (____ /___ /\___ >____/
  115. // \/ \/ \/ \/
  116. type CreateLabelForm struct {
  117. Title string `form:"title" binding:"Required;MaxSize(50)"`
  118. Color string `form:"color" binding:"Required;Size(7)"`
  119. }
  120. func (f *CreateLabelForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  121. return validate(errs, ctx.Data, f, ctx.Locale)
  122. }
  123. // __________ .__
  124. // \______ \ ____ | | ____ _____ ______ ____
  125. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  126. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  127. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  128. // \/ \/ \/ \/ \/ \/
  129. type NewReleaseForm struct {
  130. TagName string `form:"tag_name" binding:"Required"`
  131. Target string `form:"tag_target" binding:"Required"`
  132. Title string `form:"title" binding:"Required"`
  133. Content string `form:"content" binding:"Required"`
  134. Draft string `form:"draft"`
  135. Prerelease bool `form:"prerelease"`
  136. }
  137. func (f *NewReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  138. return validate(errs, ctx.Data, f, ctx.Locale)
  139. }
  140. type EditReleaseForm struct {
  141. Target string `form:"tag_target" binding:"Required"`
  142. Title string `form:"title" binding:"Required"`
  143. Content string `form:"content" binding:"Required"`
  144. Draft string `form:"draft"`
  145. Prerelease bool `form:"prerelease"`
  146. }
  147. func (f *EditReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  148. return validate(errs, ctx.Data, f, ctx.Locale)
  149. }