@@ -12,6 +12,7 @@ import (
12
12
"errors"
13
13
"fmt"
14
14
"image"
15
+ // Needed for jpeg support
15
16
_ "image/jpeg"
16
17
"image/png"
17
18
"os"
@@ -34,20 +35,35 @@ import (
34
35
"code.gitea.io/gitea/modules/setting"
35
36
)
36
37
38
+ // UserType defines the user type
37
39
type UserType int
38
40
39
41
const (
42
+ // UserTypeIndividual defines an individual user
40
43
UserTypeIndividual UserType = iota // Historic reason to make it starts at 0.
44
+
45
+ // UserTypeOrganization defines an organization
41
46
UserTypeOrganization
42
47
)
43
48
44
49
var (
45
- ErrUserNotKeyOwner = errors .New ("User does not the owner of public key" )
46
- ErrEmailNotExist = errors .New ("E-mail does not exist" )
47
- ErrEmailNotActivated = errors .New ("E-mail address has not been activated" )
48
- ErrUserNameIllegal = errors .New ("User name contains illegal characters" )
50
+ // ErrUserNotKeyOwner user does not own this key error
51
+ ErrUserNotKeyOwner = errors .New ("User does not own this public key" )
52
+
53
+ // ErrEmailNotExist e-mail does not exist error
54
+ ErrEmailNotExist = errors .New ("E-mail does not exist" )
55
+
56
+ // ErrEmailNotActivated e-mail address has not been activated error
57
+ ErrEmailNotActivated = errors .New ("E-mail address has not been activated" )
58
+
59
+ // ErrUserNameIllegal user name contains illegal characters error
60
+ ErrUserNameIllegal = errors .New ("User name contains illegal characters" )
61
+
62
+ // ErrLoginSourceNotActived login source is not actived error
49
63
ErrLoginSourceNotActived = errors .New ("Login source is not actived" )
50
- ErrUnsupportedLoginType = errors .New ("Login source is unknown" )
64
+
65
+ // ErrUnsupportedLoginType login source is unknown error
66
+ ErrUnsupportedLoginType = errors .New ("Login source is unknown" )
51
67
)
52
68
53
69
// User represents the object of individual and member of organization.
@@ -112,28 +128,32 @@ type User struct {
112
128
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
113
129
}
114
130
131
+ // BeforeInsert is invoked from XORM before inserting an object of this type.
115
132
func (u * User ) BeforeInsert () {
116
133
u .CreatedUnix = time .Now ().Unix ()
117
134
u .UpdatedUnix = u .CreatedUnix
118
135
}
119
136
137
+ // BeforeUpdate is invoked from XORM before updating this object.
120
138
func (u * User ) BeforeUpdate () {
121
139
if u .MaxRepoCreation < - 1 {
122
140
u .MaxRepoCreation = - 1
123
141
}
124
142
u .UpdatedUnix = time .Now ().Unix ()
125
143
}
126
144
127
- // Set time to last login
145
+ // SetLastLogin set time to last login
128
146
func (u * User ) SetLastLogin () {
129
147
u .LastLoginUnix = time .Now ().Unix ()
130
148
}
131
149
150
+ // UpdateDiffViewStyle updates the users diff view style
132
151
func (u * User ) UpdateDiffViewStyle (style string ) error {
133
152
u .DiffViewStyle = style
134
153
return UpdateUser (u )
135
154
}
136
155
156
+ // AfterSet is invoked from XORM after setting the value of a field of this object.
137
157
func (u * User ) AfterSet (colName string , _ xorm.Cell ) {
138
158
switch colName {
139
159
case "full_name" :
@@ -147,6 +167,7 @@ func (u *User) AfterSet(colName string, _ xorm.Cell) {
147
167
}
148
168
}
149
169
170
+ // APIFormat converts a User to api.User
150
171
func (u * User ) APIFormat () * api.User {
151
172
return & api.User {
152
173
ID : u .ID ,
@@ -157,7 +178,7 @@ func (u *User) APIFormat() *api.User {
157
178
}
158
179
}
159
180
160
- // returns true if user login type is LoginPlain.
181
+ // IsLocal returns true if user login type is LoginPlain.
161
182
func (u * User ) IsLocal () bool {
162
183
return u .LoginType <= LoginPlain
163
184
}
@@ -168,13 +189,15 @@ func (u *User) HasForkedRepo(repoID int64) bool {
168
189
return has
169
190
}
170
191
192
+ // RepoCreationNum returns the number of repositories created by the user
171
193
func (u * User ) RepoCreationNum () int {
172
194
if u .MaxRepoCreation <= - 1 {
173
195
return setting .Repository .MaxCreationLimit
174
196
}
175
197
return u .MaxRepoCreation
176
198
}
177
199
200
+ // CanCreateRepo returns if user login can create a repository
178
201
func (u * User ) CanCreateRepo () bool {
179
202
if u .MaxRepoCreation <= - 1 {
180
203
if setting .Repository .MaxCreationLimit <= - 1 {
@@ -261,15 +284,15 @@ func (u *User) GenerateRandomAvatar() error {
261
284
// which includes app sub-url as prefix. However, it is possible
262
285
// to return full URL if user enables Gravatar-like service.
263
286
func (u * User ) RelAvatarLink () string {
264
- defaultImgUrl := setting .AppSubURL + "/img/avatar_default.png"
287
+ defaultImgURL := setting .AppSubURL + "/img/avatar_default.png"
265
288
if u .ID == - 1 {
266
- return defaultImgUrl
289
+ return defaultImgURL
267
290
}
268
291
269
292
switch {
270
293
case u .UseCustomAvatar :
271
294
if ! com .IsExist (u .CustomAvatarPath ()) {
272
- return defaultImgUrl
295
+ return defaultImgURL
273
296
}
274
297
return setting .AppSubURL + "/avatars/" + com .ToStr (u .ID )
275
298
case setting .DisableGravatar , setting .OfflineMode :
@@ -293,7 +316,7 @@ func (u *User) AvatarLink() string {
293
316
return link
294
317
}
295
318
296
- // User.GetFollwoers returns range of user's followers.
319
+ // GetFollowers returns range of user's followers.
297
320
func (u * User ) GetFollowers (page int ) ([]* User , error ) {
298
321
users := make ([]* User , 0 , ItemsPerPage )
299
322
sess := x .
@@ -307,6 +330,7 @@ func (u *User) GetFollowers(page int) ([]*User, error) {
307
330
return users , sess .Find (& users )
308
331
}
309
332
333
+ // IsFollowing returns true if user is following followID.
310
334
func (u * User ) IsFollowing (followID int64 ) bool {
311
335
return IsFollowing (u .ID , followID )
312
336
}
@@ -418,13 +442,13 @@ func (u *User) IsOrganization() bool {
418
442
}
419
443
420
444
// IsUserOrgOwner returns true if user is in the owner team of given organization.
421
- func (u * User ) IsUserOrgOwner (orgId int64 ) bool {
422
- return IsOrganizationOwner (orgId , u .ID )
445
+ func (u * User ) IsUserOrgOwner (orgID int64 ) bool {
446
+ return IsOrganizationOwner (orgID , u .ID )
423
447
}
424
448
425
449
// IsPublicMember returns true if user public his/her membership in give organization.
426
- func (u * User ) IsPublicMember (orgId int64 ) bool {
427
- return IsPublicMembership (orgId , u .ID )
450
+ func (u * User ) IsPublicMember (orgID int64 ) bool {
451
+ return IsPublicMembership (orgID , u .ID )
428
452
}
429
453
430
454
func (u * User ) getOrganizationCount (e Engine ) (int64 , error ) {
@@ -444,7 +468,7 @@ func (u *User) GetRepositories(page, pageSize int) (err error) {
444
468
return err
445
469
}
446
470
447
- // GetRepositories returns mirror repositories that user owns, including private repositories.
471
+ // GetMirrorRepositories returns mirror repositories that user owns, including private repositories.
448
472
func (u * User ) GetMirrorRepositories () ([]* Repository , error ) {
449
473
return GetUserMirrorRepositories (u .ID )
450
474
}
@@ -481,6 +505,7 @@ func (u *User) DisplayName() string {
481
505
return u .Name
482
506
}
483
507
508
+ // ShortName ellipses username to length
484
509
func (u * User ) ShortName (length int ) string {
485
510
return base .EllipsisString (u .Name , length )
486
511
}
@@ -542,6 +567,7 @@ func isUsableName(names, patterns []string, name string) error {
542
567
return nil
543
568
}
544
569
570
+ // IsUsableUsername returns an error when a username is reserved
545
571
func IsUsableUsername (name string ) error {
546
572
return isUsableName (reservedUsernames , reservedUserPatterns , name )
547
573
}
@@ -630,7 +656,7 @@ func getVerifyUser(code string) (user *User) {
630
656
return nil
631
657
}
632
658
633
- // verify active code when active account
659
+ // VerifyUserActiveCode verifies active code when active account
634
660
func VerifyUserActiveCode (code string ) (user * User ) {
635
661
minutes := setting .Service .ActiveCodeLives
636
662
@@ -646,7 +672,7 @@ func VerifyUserActiveCode(code string) (user *User) {
646
672
return nil
647
673
}
648
674
649
- // verify active code when active account
675
+ // VerifyActiveEmailCode verifies active email code when active account
650
676
func VerifyActiveEmailCode (code , email string ) * EmailAddress {
651
677
minutes := setting .Service .ActiveCodeLives
652
678
@@ -1063,6 +1089,7 @@ func GetUserByEmail(email string) (*User, error) {
1063
1089
return nil , ErrUserNotExist {0 , email , 0 }
1064
1090
}
1065
1091
1092
+ // SearchUserOptions contains the options for searching
1066
1093
type SearchUserOptions struct {
1067
1094
Keyword string
1068
1095
Type UserType
@@ -1123,6 +1150,7 @@ type Follow struct {
1123
1150
FollowID int64 `xorm:"UNIQUE(follow)"`
1124
1151
}
1125
1152
1153
+ // IsFollowing returns true if user is following followID.
1126
1154
func IsFollowing (userID , followID int64 ) bool {
1127
1155
has , _ := x .Get (& Follow {UserID : userID , FollowID : followID })
1128
1156
return has
0 commit comments