Split user creation and saving user to db

This commit is contained in:
erik 2023-12-07 13:18:33 +01:00 committed by Michael Jerger
parent 7f4667696f
commit 75ee273f40

View file

@ -139,22 +139,19 @@ func unmarshallPersonJSON(body []byte) (ap.Person, error) {
} }
func createFederatedUserFromPerson(ctx *context.APIContext, person ap.Person, remoteStargazer string) error { func createFederatedUserFromPerson(person ap.Person, remoteStargazer string) (*user_model.User, error) {
email, err := generateUUIDMail(person) email, err := generateUUIDMail(person)
if err != nil { if err != nil {
return err return &user_model.User{}, err
} }
username, err := generateRemoteUserName(person) username, err := generateRemoteUserName(person)
if err != nil { if err != nil {
return err return &user_model.User{}, err
} }
password, err := generateRandomPassword() password, err := generateRandomPassword()
if err != nil { if err != nil {
return err return &user_model.User{}, err
} }
user := &user_model.User{ user := &user_model.User{
LowerName: strings.ToLower(username), LowerName: strings.ToLower(username),
Name: username, Name: username,
@ -166,12 +163,14 @@ func createFederatedUserFromPerson(ctx *context.APIContext, person ap.Person, re
Type: user_model.UserTypeRemoteUser, Type: user_model.UserTypeRemoteUser,
IsAdmin: false, IsAdmin: false,
} }
return user, nil
}
func saveFederatedUserRecord(ctx *context.APIContext, user *user_model.User) error {
overwriteDefault := &user_model.CreateUserOverwriteOptions{ overwriteDefault := &user_model.CreateUserOverwriteOptions{
IsActive: util.OptionalBoolFalse, IsActive: util.OptionalBoolFalse,
IsRestricted: util.OptionalBoolFalse, IsRestricted: util.OptionalBoolFalse,
} }
if err := user_model.CreateUser(ctx, user, overwriteDefault); err != nil { if err := user_model.CreateUser(ctx, user, overwriteDefault); err != nil {
return err return err
} }