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.

359 lines
11 KiB

Git LFS support v2 (#122) * Import github.com/git-lfs/lfs-test-server as lfs module base Imported commit is 3968aac269a77b73924649b9412ae03f7ccd3198 Removed: Dockerfile CONTRIBUTING.md mgmt* script/ vendor/ kvlogger.go .dockerignore .gitignore README.md * Remove config, add JWT support from github.com/mgit-at/lfs-test-server Imported commit f0cdcc5a01599c5a955dc1bbf683bb4acecdba83 * Add LFS settings * Add LFS meta object model * Add LFS routes and initialization * Import github.com/dgrijalva/jwt-go into vendor/ * Adapt LFS module: handlers, routing, meta store * Move LFS routes to /user/repo/info/lfs/* * Add request header checks to LFS BatchHandler / PostHandler * Implement LFS basic authentication * Rework JWT secret generation / load * Implement LFS SSH token authentication with JWT Specification: https://github.com/github/git-lfs/tree/master/docs/api * Integrate LFS settings into install process * Remove LFS objects when repository is deleted Only removes objects from content store when deleted repo is the only referencing repository * Make LFS module stateless Fixes bug where LFS would not work after installation without restarting Gitea * Change 500 'Internal Server Error' to 400 'Bad Request' * Change sql query to xorm call * Remove unneeded type from LFS module * Change internal imports to code.gitea.io/gitea/ * Add Gitea authors copyright * Change basic auth realm to "gitea-lfs" * Add unique indexes to LFS model * Use xorm count function in LFS check on repository delete * Return io.ReadCloser from content store and close after usage * Add LFS info to runWeb() * Export LFS content store base path * LFS file download from UI * Work around git-lfs client issue with unauthenticated requests Returning a dummy Authorization header for unauthenticated requests lets git-lfs client skip asking for auth credentials See: https://github.com/github/git-lfs/issues/1088 * Fix unauthenticated UI downloads from public repositories * Authentication check order, Finish LFS file view logic * Ignore LFS hooks if installed for current OS user Fixes Gitea UI actions for repositories tracking LFS files. Checks for minimum needed git version by parsing the semantic version string. * Hide LFS metafile diff from commit view, marking as binary * Show LFS notice if file in commit view is tracked * Add notbefore/nbf JWT claim * Correct lint suggestions - comments for structs and functions - Add comments to LFS model - Function comment for GetRandomBytesAsBase64 - LFS server function comments and lint variable suggestion * Move secret generation code out of conditional Ensures no LFS code may run with an empty secret * Do not hand out JWT tokens if LFS server support is disabled
7 years ago
7 years ago
7 years ago
7 years ago
Feature: Timetracking (#2211) * Added comment's hashtag to url for mail notifications. * Added explanation to return statement + documentation. * Replacing in-line link generation with HTMLURL. (+gofmt) * Replaced action-based model with nil-based model. (+gofmt) * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. * Updating comment for mailIssueCommentToParticipants * Added link to comment in "Dashboard" * Deleting feed entry if a comment is going to be deleted * Added migration * Added improved migration to add a CommentID column to action. * Added improved links to comments in feed entries. * Fixes #1956 by filtering for deleted comments that are referenced in actions. * Introducing "IsDeleted" column to action. * Adding design draft (not functional) * Adding database models for stopwatches and trackedtimes * See go-gitea/gitea#967 * Adding design draft (not functional) * Adding translations and improving design * Implementing stopwatch (for timetracking) * Make UI functional * Add hints in timeline for time tracking events * Implementing timetracking feature * Adding "Add time manual" option * Improved stopwatch * Created report of total spent time by user * Only showing total time spent if theire is something to show. * Adding license headers. * Improved error handling for "Add Time Manual" * Adding @sapks 's changes, refactoring * Adding API for feature tracking * Adding unit test * Adding DISABLE/ENABLE option to Repository settings page * Improving translations * Applying @sapk 's changes * Removing repo_unit and using IssuesSetting for disabling/enabling timetracker * Adding DEFAULT_ENABLE_TIMETRACKER to config, installation and admin menu * Improving documentation * Fixing vendor/ folder * Changing timtracking routes by adding subgroups /times and /times/stopwatch (Proposed by @lafriks ) * Restricting write access to timetracking based on the repo settings (Proposed by @lafriks ) * Fixed minor permissions bug. * Adding CanUseTimetracker and IsTimetrackerEnabled in ctx.Repo * Allow assignees and authors to track there time too. * Fixed some build-time-errors + logical errors. * Removing unused Get...ByID functions * Moving IsTimetrackerEnabled from context.Repository to models.Repository * Adding a seperate file for issue related repo functions * Adding license headers * Fixed GetUserByParams return 404 * Moving /users/:username/times to /repos/:username/:reponame/times/:username for security reasons * Adding /repos/:username/times to get all tracked times of the repo * Updating sdk-dependency * Updating swagger.v1.json * Adding warning if user has already a running stopwatch (auto-timetracker) * Replacing GetTrackedTimesBy... with GetTrackedTimes(options FindTrackedTimesOptions) * Changing code.gitea.io/sdk back to code.gitea.io/sdk * Correcting spelling mistake * Updating vendor.json * Changing GET stopwatch/toggle to POST stopwatch/toggle * Changing GET stopwatch/cancel to POST stopwatch/cancel * Added migration for stopwatches/timetracking * Fixed some access bugs for read-only users * Added default allow only contributors to track time value to config * Fixed migration by chaging x.Iterate to x.Find * Resorted imports * Moved Add Time Manually form to repo_form.go * Removed "Seconds" field from Add Time Manually * Resorted imports * Improved permission checking * Fixed some bugs * Added integration test * gofmt * Adding integration test by @lafriks * Added created_unix to comment fixtures * Using last event instead of a fixed event * Adding another integration test by @lafriks * Fixing bug Timetracker enabled causing error 500 at sidebar.tpl * Fixed a refactoring bug that resulted in hiding "HasUserStopwatch" warning. * Returning TrackedTime instead of AddTimeOption at AddTime. * Updating SDK from go-gitea/go-sdk#69 * Resetting Go-SDK back to default repository * Fixing test-vendor by changing ini back to original repository * Adding "tags" to swagger spec * govendor sync * Removed duplicate * Formatting templates * Adding IsTimetrackingEnabled checks to API * Improving translations / english texts * Improving documentation * Updating swagger spec * Fixing integration test caused be translation-changes * Removed encoding issues in local_en-US.ini. * "Added" copyright line * Moved unit.IssuesConfig().EnableTimetracker into a != nil check * Removed some other encoding issues in local_en-US.ini * Improved javascript by checking if data-context exists * Replaced manual comment creation with CreateComment * Removed unnecessary code * Improved error checking * Small cosmetic changes * Replaced int>string>duration parsing with int>duration parsing * Fixed encoding issues * Removed unused imports Signed-off-by: Jonas Franz <info@jonasfranz.software>
6 years ago
7 years ago
Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
7 years ago
7 years ago
Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
7 years ago
Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
7 years ago
Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
7 years ago
Oauth2 consumer (#679) * initial stuff for oauth2 login, fails on: * login button on the signIn page to start the OAuth2 flow and a callback for each provider Only GitHub is implemented for now * show login button only when the OAuth2 consumer is configured (and activated) * create macaron group for oauth2 urls * prevent net/http in modules (other then oauth2) * use a new data sessions oauth2 folder for storing the oauth2 session data * add missing 2FA when this is enabled on the user * add password option for OAuth2 user , for use with git over http and login to the GUI * add tip for registering a GitHub OAuth application * at startup of Gitea register all configured providers and also on adding/deleting of new providers * custom handling of errors in oauth2 request init + show better tip * add ExternalLoginUser model and migration script to add it to database * link a external account to an existing account (still need to handle wrong login and signup) and remove if user is removed * remove the linked external account from the user his settings * if user is unknown we allow him to register a new account or link it to some existing account * sign up with button on signin page (als change OAuth2Provider structure so we can store basic stuff about providers) * from gorilla/sessions docs: "Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with context.ClearHandler as or else you will leak memory!" (we're using gorilla/sessions for storing oauth2 sessions) * use updated goth lib that now supports getting the OAuth2 user if the AccessToken is still valid instead of re-authenticating (prevent flooding the OAuth2 provider)
7 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package auth
  6. import (
  7. "mime/multipart"
  8. "strings"
  9. "code.gitea.io/gitea/modules/setting"
  10. "github.com/go-macaron/binding"
  11. macaron "gopkg.in/macaron.v1"
  12. )
  13. // InstallForm form for installation page
  14. type InstallForm struct {
  15. DbType string `binding:"Required"`
  16. DbHost string
  17. DbUser string
  18. DbPasswd string
  19. DbName string
  20. SSLMode string
  21. Charset string `binding:"Required;In(utf8,utf8mb4)"`
  22. DbPath string
  23. AppName string `binding:"Required" locale:"install.app_name"`
  24. RepoRootPath string `binding:"Required"`
  25. LFSRootPath string
  26. RunUser string `binding:"Required"`
  27. Domain string `binding:"Required"`
  28. SSHPort int
  29. HTTPPort string `binding:"Required"`
  30. AppURL string `binding:"Required"`
  31. LogRootPath string `binding:"Required"`
  32. SMTPHost string
  33. SMTPFrom string
  34. SMTPUser string `binding:"OmitEmpty;MaxSize(254)" locale:"install.mailer_user"`
  35. SMTPPasswd string
  36. RegisterConfirm bool
  37. MailNotify bool
  38. OfflineMode bool
  39. DisableGravatar bool
  40. EnableFederatedAvatar bool
  41. EnableOpenIDSignIn bool
  42. EnableOpenIDSignUp bool
  43. DisableRegistration bool
  44. AllowOnlyExternalRegistration bool
  45. EnableCaptcha bool
  46. RequireSignInView bool
  47. DefaultKeepEmailPrivate bool
  48. DefaultAllowCreateOrganization bool
  49. DefaultEnableTimetracking bool
  50. NoReplyAddress string
  51. AdminName string `binding:"OmitEmpty;AlphaDashDot;MaxSize(30)" locale:"install.admin_name"`
  52. AdminPasswd string `binding:"OmitEmpty;MaxSize(255)" locale:"install.admin_password"`
  53. AdminConfirmPasswd string
  54. AdminEmail string `binding:"OmitEmpty;MinSize(3);MaxSize(254);Include(@)" locale:"install.admin_email"`
  55. }
  56. // Validate validates the fields
  57. func (f *InstallForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  58. return validate(errs, ctx.Data, f, ctx.Locale)
  59. }
  60. // _____ ____ _________________ ___
  61. // / _ \ | | \__ ___/ | \
  62. // / /_\ \| | / | | / ~ \
  63. // / | \ | / | | \ Y /
  64. // \____|__ /______/ |____| \___|_ /
  65. // \/ \/
  66. // RegisterForm form for registering
  67. type RegisterForm struct {
  68. UserName string `binding:"Required;AlphaDashDot;MaxSize(40)"`
  69. Email string `binding:"Required;Email;MaxSize(254)"`
  70. Password string `binding:"Required;MaxSize(255)"`
  71. Retype string
  72. GRecaptchaResponse string `form:"g-recaptcha-response"`
  73. }
  74. // Validate valideates the fields
  75. func (f *RegisterForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  76. return validate(errs, ctx.Data, f, ctx.Locale)
  77. }
  78. // IsEmailDomainWhitelisted validates that the email address
  79. // provided by the user matches what has been configured .
  80. // If the domain whitelist from the config is empty, it marks the
  81. // email as whitelisted
  82. func (f RegisterForm) IsEmailDomainWhitelisted() bool {
  83. if len(setting.Service.EmailDomainWhitelist) == 0 {
  84. return true
  85. }
  86. n := strings.LastIndex(f.Email, "@")
  87. if n <= 0 {
  88. return false
  89. }
  90. domain := strings.ToLower(f.Email[n+1:])
  91. for _, v := range setting.Service.EmailDomainWhitelist {
  92. if strings.ToLower(v) == domain {
  93. return true
  94. }
  95. }
  96. return false
  97. }
  98. // MustChangePasswordForm form for updating your password after account creation
  99. // by an admin
  100. type MustChangePasswordForm struct {
  101. Password string `binding:"Required;MaxSize(255)"`
  102. Retype string
  103. }
  104. // Validate valideates the fields
  105. func (f *MustChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  106. return validate(errs, ctx.Data, f, ctx.Locale)
  107. }
  108. // SignInForm form for signing in with user/password
  109. type SignInForm struct {
  110. UserName string `binding:"Required;MaxSize(254)"`
  111. Password string `binding:"Required;MaxSize(255)"`
  112. Remember bool
  113. }
  114. // Validate valideates the fields
  115. func (f *SignInForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  116. return validate(errs, ctx.Data, f, ctx.Locale)
  117. }
  118. // AuthorizationForm form for authorizing oauth2 clients
  119. type AuthorizationForm struct {
  120. ResponseType string `binding:"Required;In(code)"`
  121. ClientID string `binding:"Required"`
  122. RedirectURI string
  123. State string
  124. // PKCE support
  125. CodeChallengeMethod string // S256, plain
  126. CodeChallenge string
  127. }
  128. // Validate valideates the fields
  129. func (f *AuthorizationForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  130. return validate(errs, ctx.Data, f, ctx.Locale)
  131. }
  132. // GrantApplicationForm form for authorizing oauth2 clients
  133. type GrantApplicationForm struct {
  134. ClientID string `binding:"Required"`
  135. RedirectURI string
  136. State string
  137. }
  138. // Validate valideates the fields
  139. func (f *GrantApplicationForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  140. return validate(errs, ctx.Data, f, ctx.Locale)
  141. }
  142. // AccessTokenForm for issuing access tokens from authorization codes or refresh tokens
  143. type AccessTokenForm struct {
  144. GrantType string `json:"grant_type"`
  145. ClientID string `json:"client_id"`
  146. ClientSecret string `json:"client_secret"`
  147. RedirectURI string `json:"redirect_uri"`
  148. Code string `json:"code"`
  149. RefreshToken string `json:"refresh_token"`
  150. // PKCE support
  151. CodeVerifier string `json:"code_verifier"`
  152. }
  153. // Validate valideates the fields
  154. func (f *AccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  155. return validate(errs, ctx.Data, f, ctx.Locale)
  156. }
  157. // __________________________________________.___ _______ ________ _________
  158. // / _____/\_ _____/\__ ___/\__ ___/| |\ \ / _____/ / _____/
  159. // \_____ \ | __)_ | | | | | |/ | \/ \ ___ \_____ \
  160. // / \ | \ | | | | | / | \ \_\ \/ \
  161. // /_______ //_______ / |____| |____| |___\____|__ /\______ /_______ /
  162. // \/ \/ \/ \/ \/
  163. // UpdateProfileForm form for updating profile
  164. type UpdateProfileForm struct {
  165. Name string `binding:"AlphaDashDot;MaxSize(40)"`
  166. FullName string `binding:"MaxSize(100)"`
  167. Email string `binding:"Required;Email;MaxSize(254)"`
  168. KeepEmailPrivate bool
  169. Website string `binding:"ValidUrl;MaxSize(255)"`
  170. Location string `binding:"MaxSize(50)"`
  171. Language string `binding:"Size(5)"`
  172. Description string `binding:"MaxSize(255)"`
  173. }
  174. // Validate validates the fields
  175. func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  176. return validate(errs, ctx.Data, f, ctx.Locale)
  177. }
  178. // Avatar types
  179. const (
  180. AvatarLocal string = "local"
  181. AvatarByMail string = "bymail"
  182. )
  183. // AvatarForm form for changing avatar
  184. type AvatarForm struct {
  185. Source string
  186. Avatar *multipart.FileHeader
  187. Gravatar string `binding:"OmitEmpty;Email;MaxSize(254)"`
  188. Federavatar bool
  189. }
  190. // Validate validates the fields
  191. func (f *AvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  192. return validate(errs, ctx.Data, f, ctx.Locale)
  193. }
  194. // AddEmailForm form for adding new email
  195. type AddEmailForm struct {
  196. Email string `binding:"Required;Email;MaxSize(254)"`
  197. }
  198. // Validate validates the fields
  199. func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  200. return validate(errs, ctx.Data, f, ctx.Locale)
  201. }
  202. // UpdateThemeForm form for updating a users' theme
  203. type UpdateThemeForm struct {
  204. Theme string `binding:"Required;MaxSize(30)"`
  205. }
  206. // Validate validates the field
  207. func (f *UpdateThemeForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  208. return validate(errs, ctx.Data, f, ctx.Locale)
  209. }
  210. // IsThemeExists checks if the theme is a theme available in the config.
  211. func (f UpdateThemeForm) IsThemeExists() bool {
  212. var exists bool
  213. for _, v := range setting.UI.Themes {
  214. if strings.EqualFold(v, f.Theme) {
  215. exists = true
  216. break
  217. }
  218. }
  219. return exists
  220. }
  221. // ChangePasswordForm form for changing password
  222. type ChangePasswordForm struct {
  223. OldPassword string `form:"old_password" binding:"MaxSize(255)"`
  224. Password string `form:"password" binding:"Required;MaxSize(255)"`
  225. Retype string `form:"retype"`
  226. }
  227. // Validate validates the fields
  228. func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  229. return validate(errs, ctx.Data, f, ctx.Locale)
  230. }
  231. // AddOpenIDForm is for changing openid uri
  232. type AddOpenIDForm struct {
  233. Openid string `binding:"Required;MaxSize(256)"`
  234. }
  235. // Validate validates the fields
  236. func (f *AddOpenIDForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  237. return validate(errs, ctx.Data, f, ctx.Locale)
  238. }
  239. // AddKeyForm form for adding SSH/GPG key
  240. type AddKeyForm struct {
  241. Type string `binding:"OmitEmpty"`
  242. Title string `binding:"Required;MaxSize(50)"`
  243. Content string `binding:"Required"`
  244. IsWritable bool
  245. }
  246. // Validate validates the fields
  247. func (f *AddKeyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  248. return validate(errs, ctx.Data, f, ctx.Locale)
  249. }
  250. // NewAccessTokenForm form for creating access token
  251. type NewAccessTokenForm struct {
  252. Name string `binding:"Required;MaxSize(255)"`
  253. }
  254. // Validate valideates the fields
  255. func (f *NewAccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  256. return validate(errs, ctx.Data, f, ctx.Locale)
  257. }
  258. // EditOAuth2ApplicationForm form for editing oauth2 applications
  259. type EditOAuth2ApplicationForm struct {
  260. Name string `binding:"Required;MaxSize(255)" form:"application_name"`
  261. RedirectURI string `binding:"Required" form:"redirect_uri"`
  262. }
  263. // Validate valideates the fields
  264. func (f *EditOAuth2ApplicationForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  265. return validate(errs, ctx.Data, f, ctx.Locale)
  266. }
  267. // TwoFactorAuthForm for logging in with 2FA token.
  268. type TwoFactorAuthForm struct {
  269. Passcode string `binding:"Required"`
  270. }
  271. // Validate validates the fields
  272. func (f *TwoFactorAuthForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  273. return validate(errs, ctx.Data, f, ctx.Locale)
  274. }
  275. // TwoFactorScratchAuthForm for logging in with 2FA scratch token.
  276. type TwoFactorScratchAuthForm struct {
  277. Token string `binding:"Required"`
  278. }
  279. // Validate valideates the fields
  280. func (f *TwoFactorScratchAuthForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  281. return validate(errs, ctx.Data, f, ctx.Locale)
  282. }
  283. // U2FRegistrationForm for reserving an U2F name
  284. type U2FRegistrationForm struct {
  285. Name string `binding:"Required"`
  286. }
  287. // Validate valideates the fields
  288. func (f *U2FRegistrationForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  289. return validate(errs, ctx.Data, f, ctx.Locale)
  290. }
  291. // U2FDeleteForm for deleting U2F keys
  292. type U2FDeleteForm struct {
  293. ID int64 `binding:"Required"`
  294. }
  295. // Validate valideates the fields
  296. func (f *U2FDeleteForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  297. return validate(errs, ctx.Data, f, ctx.Locale)
  298. }