mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-08 18:04:14 +01:00
Move federated user creation to func
This commit is contained in:
parent
01506f9836
commit
d27cac5bae
1 changed files with 42 additions and 33 deletions
|
@ -130,6 +130,46 @@ func getPersonByRest(remoteStargazer, starReceiver string, ctx *context.APIConte
|
|||
|
||||
}
|
||||
|
||||
func createFederatedUserFromPerson(ctx *context.APIContext, person ap.Person, remoteStargazer string) error {
|
||||
email, err := generateUUIDMail(person)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
username, err := generateRemoteUserName(person)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
password, err := generateRandomPassword()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user := &user_model.User{
|
||||
LowerName: strings.ToLower(username),
|
||||
Name: username,
|
||||
Email: email,
|
||||
EmailNotificationsPreference: "disabled",
|
||||
Passwd: password,
|
||||
MustChangePassword: false,
|
||||
LoginName: remoteStargazer,
|
||||
Type: user_model.UserTypeRemoteUser,
|
||||
IsAdmin: false,
|
||||
}
|
||||
|
||||
overwriteDefault := &user_model.CreateUserOverwriteOptions{
|
||||
IsActive: util.OptionalBoolFalse,
|
||||
IsRestricted: util.OptionalBoolFalse,
|
||||
}
|
||||
|
||||
if err := user_model.CreateUser(ctx, user, overwriteDefault); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Info("User created!")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Repository function returns the Repository actor for a repo
|
||||
func Repository(ctx *context.APIContext) {
|
||||
// swagger:operation GET /activitypub/repository-id/{repository-id} activitypub activitypubRepository
|
||||
|
@ -242,42 +282,11 @@ func RepositoryInbox(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// create user
|
||||
email, err := generateUUIDMail(person)
|
||||
err = createFederatedUserFromPerson(ctx, person, remoteStargazer)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("generate user failed: %v", err))
|
||||
}
|
||||
|
||||
username, err := generateRemoteUserName(person)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("generate user failed: %v", err))
|
||||
}
|
||||
|
||||
password, err := generateRandomPassword()
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("generate password failed: %v", err))
|
||||
}
|
||||
|
||||
user := &user_model.User{
|
||||
LowerName: strings.ToLower(username),
|
||||
Name: username,
|
||||
Email: email,
|
||||
EmailNotificationsPreference: "disabled",
|
||||
Passwd: password,
|
||||
MustChangePassword: false,
|
||||
LoginName: remoteStargazer,
|
||||
Type: user_model.UserTypeRemoteUser,
|
||||
IsAdmin: false,
|
||||
}
|
||||
|
||||
overwriteDefault := &user_model.CreateUserOverwriteOptions{
|
||||
IsActive: util.OptionalBoolFalse,
|
||||
IsRestricted: util.OptionalBoolFalse,
|
||||
}
|
||||
|
||||
if err := user_model.CreateUser(ctx, user, overwriteDefault); err != nil {
|
||||
panic(fmt.Errorf("createUser: %w", err))
|
||||
}
|
||||
log.Info("User created!")
|
||||
|
||||
} else {
|
||||
// use first user
|
||||
user := users[0]
|
||||
|
|
Loading…
Reference in a new issue