Skip to content

Commit 1819c4b

Browse files
techknowlogickdelvhjolheiser
authored
Add new user types reserved, bot, and remote (#24026)
This allows for usernames, and emails connected to them to be reserved and not reused. Use case, I manage an instance with open registration, and sometimes when users are deleted for spam (or other purposes), their usernames are freed up and they sign up again with the same information. This could also be used to reserve usernames, and block them from being registered (in case an instance would like to block certain things without hardcoding the list in code and compiling from scratch). This is an MVP, that will allow for future work where you can set something as reserved via the interface. --------- Co-authored-by: delvh <[email protected]> Co-authored-by: John Olheiser <[email protected]>
1 parent f200572 commit 1819c4b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

models/user/user.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ const (
4141

4242
// UserTypeOrganization defines an organization
4343
UserTypeOrganization
44+
45+
// UserTypeReserved reserves a (non-existing) user, i.e. to prevent a spam user from re-registering after being deleted, or to reserve the name until the user is actually created later on
46+
UserTypeUserReserved
47+
48+
// UserTypeOrganizationReserved reserves a (non-existing) organization, to be used in combination with UserTypeUserReserved
49+
UserTypeOrganizationReserved
50+
51+
// UserTypeBot defines a bot user
52+
UserTypeBot
53+
54+
// UserTypeRemoteUser defines a remote user for federated users
55+
UserTypeRemoteUser
4456
)
4557

4658
const (
@@ -312,6 +324,7 @@ func GetUserFollowers(ctx context.Context, u, viewer *User, listOptions db.ListO
312324
Select("`user`.*").
313325
Join("LEFT", "follow", "`user`.id=follow.user_id").
314326
Where("follow.follow_id=?", u.ID).
327+
And("`user`.type=?", UserTypeIndividual).
315328
And(isUserVisibleToViewerCond(viewer))
316329

317330
if listOptions.Page != 0 {
@@ -333,6 +346,7 @@ func GetUserFollowing(ctx context.Context, u, viewer *User, listOptions db.ListO
333346
Select("`user`.*").
334347
Join("LEFT", "follow", "`user`.id=follow.follow_id").
335348
Where("follow.user_id=?", u.ID).
349+
And("`user`.type=?", UserTypeIndividual).
336350
And(isUserVisibleToViewerCond(viewer))
337351

338352
if listOptions.Page != 0 {
@@ -959,7 +973,7 @@ func GetUserByName(ctx context.Context, name string) (*User, error) {
959973
if len(name) == 0 {
960974
return nil, ErrUserNotExist{0, name, 0}
961975
}
962-
u := &User{LowerName: strings.ToLower(name)}
976+
u := &User{LowerName: strings.ToLower(name), Type: UserTypeIndividual}
963977
has, err := db.GetEngine(ctx).Get(u)
964978
if err != nil {
965979
return nil, err

services/auth/source/db/authenticate.go

+8
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,13 @@ func Authenticate(user *user_model.User, login, password string) (*user_model.Us
4040
}
4141
}
4242

43+
// attempting to login as a non-user account
44+
if user.Type != user_model.UserTypeIndividual {
45+
return nil, user_model.ErrUserProhibitLogin{
46+
UID: user.ID,
47+
Name: user.Name,
48+
}
49+
}
50+
4351
return user, nil
4452
}

0 commit comments

Comments
 (0)