# Test users for the dev server — abby, betty, carol, daria.
#
# mix run --no-start priv/repo/seeds/dev_users.exs
#
# `--no-start` because the full app binds fixed ports (SSH 2222,
# metrics 9568) that a running dev server already holds; this only
# needs the Repo, which it starts itself.
#
# Idempotent: re-running leaves existing users alone rather than
# erroring, so it's safe to run whenever you want them back.
#
# Refuses outside :dev. These are confirmed accounts with a shared,
# published password; creating them anywhere else would be handing out
# four working logins.
alias GitGud.Accounts
alias GitGud.Accounts.User
alias GitGud.Repo
if Mix.env() != :dev do
raise "dev_users.exs seeds accounts with a known password; refusing to run in #{Mix.env()}"
end
# Under --no-start nothing is running yet; bring up just the Repo.
{:ok, _} = Application.ensure_all_started(:ecto_sql)
{:ok, _} = Application.ensure_all_started(:postgrex)
repo_started? =
case GitGud.Repo.start_link() do
{:ok, _pid} -> true
{:error, {:already_started, _pid}} -> false
end
password = "devpassword123!"
handles = ~w(abby betty carol daria)
for handle <- handles do
email = "#{handle}@example.test"
case Repo.get_by(User, email: email) do
%User{} = existing ->
IO.puts("· #{handle} already exists (id #{existing.id})")
nil ->
# Registration mode may be invite-only or closed on this
# instance; these are seeds, so go straight at the changeset
# rather than through the invite flow.
user =
%User{}
|> User.email_changeset(%{email: email, handle: handle})
|> Repo.insert!()
user =
user
|> User.password_changeset(%{password: password}, hash_password: true)
|> Repo.update!()
user =
user
|> User.confirm_changeset()
|> Repo.update!()
# The profile repo every real registration gets, so their profile
# pages aren't broken. Best-effort here as it is at signup — it
# writes to disk and can fail on a machine without the repo root.
case GitGud.Repositories.ensure_profile_repo(user) do
{:ok, _} -> :ok
other -> IO.puts(" (no profile repo: #{inspect(other)})")
end
IO.puts("✓ #{handle} <#{email}> (id #{user.id})")
end
end
IO.puts("""
Four dev users ready. Password for all of them: #{password}
Sign in at /users/log-in with the email above.
Registration mode is currently #{inspect(Accounts.registration_mode())} — for
testing invites, generate one from /users/settings/invites as any of them.
""")
if repo_started?, do: GitGud.Repo.stop()
neiam /gitgud
Git Gud
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Packages
⭐
Log in to mark this repository.
2.6 KiB · text
History
a23f026