29 lines
733 B
Elixir
29 lines
733 B
Elixir
defmodule Mix.Tasks.Frenzy.User do
|
|
use Mix.Task
|
|
alias Frenzy.{Repo, User}
|
|
|
|
@shortdoc "Adds a new user from the given username and password."
|
|
def run(["add"]) do
|
|
username = IO.gets("Username: ") |> String.trim()
|
|
password = IO.gets("Password: ") |> String.trim()
|
|
fever_password = IO.gets("Fever Password: ") |> String.trim()
|
|
|
|
changeset =
|
|
User.registration_changeset(%User{}, %{
|
|
username: username,
|
|
password: password,
|
|
fever_password: fever_password
|
|
})
|
|
|
|
Mix.Task.run("app.start")
|
|
|
|
{:ok, _user} = Repo.insert(changeset)
|
|
|
|
IO.puts("User #{username} successfully created")
|
|
end
|
|
|
|
def run(_) do
|
|
IO.puts("Invalid usage, expected is mix frenzy.user add")
|
|
end
|
|
end
|