Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

user.go 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. // the user's username
  15. UserName string `json:"login"`
  16. // the user's authentication sign-in name.
  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. // User locale
  28. Language string `json:"language"`
  29. // Is the user an administrator
  30. IsAdmin bool `json:"is_admin"`
  31. // swagger:strfmt date-time
  32. LastLogin time.Time `json:"last_login,omitempty"`
  33. // swagger:strfmt date-time
  34. Created time.Time `json:"created,omitempty"`
  35. // Is user restricted
  36. Restricted bool `json:"restricted"`
  37. // Is user active
  38. IsActive bool `json:"active"`
  39. // Is user login prohibited
  40. ProhibitLogin bool `json:"prohibit_login"`
  41. // the user's location
  42. Location string `json:"location"`
  43. // the user's website
  44. Website string `json:"website"`
  45. // the user's description
  46. Description string `json:"description"`
  47. // User visibility level option: public, limited, private
  48. Visibility string `json:"visibility"`
  49. // user counts
  50. Followers int `json:"followers_count"`
  51. Following int `json:"following_count"`
  52. StarredRepos int `json:"starred_repos_count"`
  53. }
  54. // MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
  55. func (u User) MarshalJSON() ([]byte, error) {
  56. // Re-declaring User to avoid recursion
  57. type shadow User
  58. return json.Marshal(struct {
  59. shadow
  60. CompatUserName string `json:"username"`
  61. }{shadow(u), u.UserName})
  62. }
  63. // UserSettings represents user settings
  64. // swagger:model
  65. type UserSettings struct {
  66. FullName string `json:"full_name"`
  67. Website string `json:"website"`
  68. Description string `json:"description"`
  69. Location string `json:"location"`
  70. Language string `json:"language"`
  71. Theme string `json:"theme"`
  72. DiffViewStyle string `json:"diff_view_style"`
  73. // Privacy
  74. HideEmail bool `json:"hide_email"`
  75. ActivityVisibility ActivityVisibility `json:"activity_visibility"`
  76. }
  77. // UserSettingsOptions represents options to change user settings
  78. // swagger:model
  79. type UserSettingsOptions struct {
  80. FullName *string `json:"full_name" binding:"MaxSize(100)"`
  81. Website *string `json:"website" binding:"OmitEmpty;ValidUrl;MaxSize(255)"`
  82. Description *string `json:"description" binding:"MaxSize(255)"`
  83. Location *string `json:"location" binding:"MaxSize(50)"`
  84. Language *string `json:"language"`
  85. Theme *string `json:"theme"`
  86. DiffViewStyle *string `json:"diff_view_style"`
  87. // Privacy
  88. HideEmail *bool `json:"hide_email"`
  89. ActivityVisibility *ActivityVisibility `json:"activity_visibility"`
  90. }
  91. // RenameUserOption options when renaming a user
  92. type RenameUserOption struct {
  93. // New username for this user. This name cannot be in use yet by any other user.
  94. //
  95. // required: true
  96. // unique: true
  97. NewName string `json:"new_username" binding:"Required"`
  98. }
  99. // UpdateUserAvatarUserOption options when updating the user avatar
  100. type UpdateUserAvatarOption struct {
  101. // image must be base64 encoded
  102. Image string `json:"image" binding:"Required"`
  103. }
  104. // Badge represents a user badge
  105. // swagger:model
  106. type Badge struct {
  107. ID int64 `json:"id"`
  108. Slug string `json:"slug"`
  109. Description string `json:"description"`
  110. ImageURL string `json:"image_url"`
  111. }
  112. // UserBadge represents a user badge
  113. // swagger:model
  114. type UserBadge struct {
  115. ID int64 `json:"id"`
  116. BadgeID int64 `json:"badge_id"`
  117. UserID int64 `json:"user_id"`
  118. }
  119. // UserBadgeOption options for link between users and badges
  120. type UserBadgeOption struct {
  121. // example: ["badge1","badge2"]
  122. BadgeSlugs []string `json:"badge_slugs" binding:"Required"`
  123. }