gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2023 The Gitea Authors. All rights reserved.
  3. // SPDX-License-Identifier: MIT
  4. package structs
  5. import (
  6. "time"
  7. "code.gitea.io/gitea/modules/json"
  8. )
  9. // User represents a user
  10. // swagger:model
  11. type User struct {
  12. // the user's id
  13. ID int64 `json:"id"`
  14. // login of the user, same as `username`
  15. UserName string `json:"login"`
  16. // identifier of the user, provided by the external authenticator (if configured)
  17. // default: empty
  18. LoginName string `json:"login_name"`
  19. // The ID of the user's Authentication Source
  20. SourceID int64 `json:"source_id"`
  21. // the user's full name
  22. FullName string `json:"full_name"`
  23. // swagger:strfmt email
  24. Email string `json:"email"`
  25. // URL to the user's avatar
  26. AvatarURL string `json:"avatar_url"`
  27. // URL to the user's gitea page
  28. HTMLURL string `json:"html_url"`
  29. // User locale
  30. Language string `json:"language"`
  31. // Is the user an administrator
  32. IsAdmin bool `json:"is_admin"`
  33. // swagger:strfmt date-time
  34. LastLogin time.Time `json:"last_login"`
  35. // swagger:strfmt date-time
  36. Created time.Time `json:"created"`
  37. // Is user restricted
  38. Restricted bool `json:"restricted"`
  39. // Is user active
  40. IsActive bool `json:"active"`
  41. // Is user login prohibited
  42. ProhibitLogin bool `json:"prohibit_login"`
  43. // the user's location
  44. Location string `json:"location"`
  45. // the user's website
  46. Website string `json:"website"`
  47. // the user's description
  48. Description string `json:"description"`
  49. // User visibility level option: public, limited, private
  50. Visibility string `json:"visibility"`
  51. // user counts
  52. Followers int `json:"followers_count"`
  53. Following int `json:"following_count"`
  54. StarredRepos int `json:"starred_repos_count"`
  55. }
  56. // MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
  57. func (u User) MarshalJSON() ([]byte, error) {
  58. // Redeclaring User to avoid recursion
  59. type shadow User
  60. return json.Marshal(struct {
  61. shadow
  62. CompatUserName string `json:"username"`
  63. }{shadow(u), u.UserName})
  64. }
  65. // UserSettings represents user settings
  66. // swagger:model
  67. type UserSettings struct {
  68. FullName string `json:"full_name"`
  69. Website string `json:"website"`
  70. Description string `json:"description"`
  71. Location string `json:"location"`
  72. Language string `json:"language"`
  73. Theme string `json:"theme"`
  74. DiffViewStyle string `json:"diff_view_style"`
  75. // Privacy
  76. HideEmail bool `json:"hide_email"`
  77. HideActivity bool `json:"hide_activity"`
  78. }
  79. // UserSettingsOptions represents options to change user settings
  80. // swagger:model
  81. type UserSettingsOptions struct {
  82. FullName *string `json:"full_name" binding:"MaxSize(100)"`
  83. Website *string `json:"website" binding:"OmitEmpty;ValidUrl;MaxSize(255)"`
  84. Description *string `json:"description" binding:"MaxSize(255)"`
  85. Location *string `json:"location" binding:"MaxSize(50)"`
  86. Language *string `json:"language"`
  87. Theme *string `json:"theme"`
  88. DiffViewStyle *string `json:"diff_view_style"`
  89. // Privacy
  90. HideEmail *bool `json:"hide_email"`
  91. HideActivity *bool `json:"hide_activity"`
  92. }
  93. // RenameUserOption options when renaming a user
  94. type RenameUserOption struct {
  95. // New username for this user. This name cannot be in use yet by any other user.
  96. //
  97. // required: true
  98. // unique: true
  99. NewName string `json:"new_username" binding:"Required"`
  100. }
  101. // UpdateUserAvatarUserOption options when updating the user avatar
  102. type UpdateUserAvatarOption struct {
  103. // image must be base64 encoded
  104. Image string `json:"image" binding:"Required"`
  105. }
  106. // Badge represents a user badge
  107. // swagger:model
  108. type Badge struct {
  109. ID int64 `json:"id"`
  110. Slug string `json:"slug"`
  111. Description string `json:"description"`
  112. ImageURL string `json:"image_url"`
  113. }
  114. // UserBadge represents a user badge
  115. // swagger:model
  116. type UserBadge struct {
  117. ID int64 `json:"id"`
  118. BadgeID int64 `json:"badge_id"`
  119. UserID int64 `json:"user_id"`
  120. }
  121. // UserBadgeOption options for link between users and badges
  122. type UserBadgeOption struct {
  123. // example: ["badge1","badge2"]
  124. BadgeSlugs []string `json:"badge_slugs" binding:"Required"`
  125. }