Skip to content

Commit

Permalink
[bugfix] add in-use checks for admin cli account creation (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmethurst authored Oct 11, 2022
1 parent 832befd commit 5cd0872
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/gotosocial/action/admin/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ var Create action.GTSAction = func(ctx context.Context) error {
return err
}

usernameAvailable, err := dbConn.IsUsernameAvailable(ctx, username)
if err != nil {
return err
}
if !usernameAvailable {
return fmt.Errorf("username %s is already in use", username)
}

email := config.GetAdminAccountEmail()
if email == "" {
return errors.New("no email set")
Expand All @@ -54,6 +62,14 @@ var Create action.GTSAction = func(ctx context.Context) error {
return err
}

emailAvailable, err := dbConn.IsEmailAvailable(ctx, email)
if err != nil {
return err
}
if !emailAvailable {
return fmt.Errorf("email address %s is already in use", email)
}

password := config.GetAdminAccountPassword()
if password == "" {
return errors.New("no password set")
Expand Down

0 comments on commit 5cd0872

Please sign in to comment.