mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-21 08:31:27 -05: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)
|
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue