mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-21 08:31:27 -05:00
WIP create user if not exists
This commit is contained in:
parent
159f3dc3aa
commit
edd7fb77fd
1 changed files with 7 additions and 7 deletions
|
@ -18,6 +18,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
|
|
||||||
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
ap "github.com/go-ap/activitypub"
|
ap "github.com/go-ap/activitypub"
|
||||||
//f3 "lab.forgefriends.org/friendlyforgeformat/gof3"
|
//f3 "lab.forgefriends.org/friendlyforgeformat/gof3"
|
||||||
)
|
)
|
||||||
|
@ -136,7 +137,9 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
|
|
||||||
// create_user_from_person (if not alreaydy present)
|
// create_user_from_person (if not alreaydy present)
|
||||||
|
|
||||||
// ToDo
|
// Check if user already exists
|
||||||
|
|
||||||
|
// Create user
|
||||||
email := generateUUIDMail(person)
|
email := generateUUIDMail(person)
|
||||||
username := getUserName(person)
|
username := getUserName(person)
|
||||||
|
|
||||||
|
@ -150,17 +153,16 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
Type: UserType.UserTypeRemoteUser,
|
Type: UserType.UserTypeRemoteUser,
|
||||||
Location: getUserLocation(person),
|
Location: getUserLocation(person),
|
||||||
Website: getAPUserID(person),
|
Website: getAPUserID(person),
|
||||||
IsActive: false,
|
|
||||||
IsAdmin: false,
|
IsAdmin: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
overwriteDefault := &user_model.CreateUserOverwriteOptions{
|
overwriteDefault := &user_model.CreateUserOverwriteOptions{
|
||||||
IsActive: util.OptionalBoolTrue,
|
IsActive: util.OptionalBoolFalse,
|
||||||
IsRestricted: restricted,
|
IsRestricted: util.OptionalBoolFalse,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := user_model.CreateUser(ctx, u, overwriteDefault); err != nil {
|
if err := user_model.CreateUser(ctx, u, overwriteDefault); err != nil {
|
||||||
return fmt.Errorf("CreateUser: %w", err)
|
panic(fmt.Errorf("CreateUser: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -180,8 +182,6 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
|
|
||||||
We need a remote server with federation enabled to test this
|
We need a remote server with federation enabled to test this
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
The "if not already present" part might be easy:
|
The "if not already present" part might be easy:
|
||||||
Check the user database for given user id.
|
Check the user database for given user id.
|
||||||
This could happen with something like: user_model.SearchUsers() as seen in routers/api/v1/user.go
|
This could happen with something like: user_model.SearchUsers() as seen in routers/api/v1/user.go
|
||||||
|
|
Loading…
Reference in a new issue