logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

user_builder.ex (884B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Builders.UserBuilder do
  5. alias Pleroma.Repo
  6. alias Pleroma.User
  7. def build(data \\ %{}) do
  8. user = %User{
  9. email: "test@example.org",
  10. name: "Test Name",
  11. nickname: "testname",
  12. password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("test"),
  13. bio: "A tester.",
  14. ap_id: "some id",
  15. last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
  16. multi_factor_authentication_settings: %Pleroma.MFA.Settings{},
  17. notification_settings: %Pleroma.User.NotificationSetting{}
  18. }
  19. Map.merge(user, data)
  20. end
  21. def insert(data \\ %{}) do
  22. {:ok, user} = Repo.insert(build(data))
  23. User.invalidate_cache(user)
  24. {:ok, user}
  25. end
  26. end