frenzy/lib/mix/tasks/frenzy/user.ex

29 lines
733 B
Elixir
Raw Normal View History

2019-03-23 17:53:53 +00:00
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()
2019-03-24 15:00:46 +00:00
fever_password = IO.gets("Fever Password: ") |> String.trim()
2019-03-23 17:53:53 +00:00
changeset =
User.registration_changeset(%User{}, %{
username: username,
2019-03-24 15:00:46 +00:00
password: password,
fever_password: fever_password
2019-03-23 17:53:53 +00:00
})
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