Fix user add task, add change password task

This commit is contained in:
Shadowfacts 2020-01-15 21:13:02 -05:00
parent 01d4e713bb
commit 7054b39937
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 22 additions and 1 deletions

View File

@ -12,7 +12,11 @@ defmodule Mix.Tasks.Clacks.User do
{:ok, public_key_pem} = Keys.public_key_pem(public) {:ok, public_key_pem} = Keys.public_key_pem(public)
changeset = changeset =
User.changeset(%User{}, %{username: username, private_key: pem, password: password}) User.registration_changeset(%User{}, %{
username: username,
private_key: pem,
password: password
})
# start the app so the DB connection is established # start the app so the DB connection is established
Mix.Task.run("app.start") Mix.Task.run("app.start")
@ -41,4 +45,21 @@ defmodule Mix.Tasks.Clacks.User do
IO.puts("User #{username} successfully created") IO.puts("User #{username} successfully created")
end end
@shortdoc "Changes the given user's password"
def run(["change_password", username]) do
case User.get_by_username(username) do
nil ->
IO.puts("No user found with username '#{username}'")
user ->
password = IO.gets("Password: ") |> String.trim()
changeset = User.change_password_changeset(user, %{password: password})
{:ok, user} = Repo.update(changeset)
IO.puts("Password updated")
end
end
end end