mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-27 02:10:40 +00:00
Split user creation and saving user to db
This commit is contained in:
parent
7f4667696f
commit
75ee273f40
1 changed files with 7 additions and 8 deletions
|
@ -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)
|
||||
if err != nil {
|
||||
return err
|
||||
return &user_model.User{}, err
|
||||
}
|
||||
|
||||
username, err := generateRemoteUserName(person)
|
||||
if err != nil {
|
||||
return err
|
||||
return &user_model.User{}, err
|
||||
}
|
||||
|
||||
password, err := generateRandomPassword()
|
||||
if err != nil {
|
||||
return err
|
||||
return &user_model.User{}, err
|
||||
}
|
||||
|
||||
user := &user_model.User{
|
||||
LowerName: strings.ToLower(username),
|
||||
Name: username,
|
||||
|
@ -166,12 +163,14 @@ func createFederatedUserFromPerson(ctx *context.APIContext, person ap.Person, re
|
|||
Type: user_model.UserTypeRemoteUser,
|
||||
IsAdmin: false,
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func saveFederatedUserRecord(ctx *context.APIContext, user *user_model.User) error {
|
||||
overwriteDefault := &user_model.CreateUserOverwriteOptions{
|
||||
IsActive: util.OptionalBoolFalse,
|
||||
IsRestricted: util.OptionalBoolFalse,
|
||||
}
|
||||
|
||||
if err := user_model.CreateUser(ctx, user, overwriteDefault); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue