From 7054b399376a6a135909390cd16d04fc17cc1fc2 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 15 Jan 2020 21:13:02 -0500 Subject: [PATCH] Fix user add task, add change password task --- lib/mix/tasks/clacks/user.ex | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/mix/tasks/clacks/user.ex b/lib/mix/tasks/clacks/user.ex index 8033a9c..2a85718 100644 --- a/lib/mix/tasks/clacks/user.ex +++ b/lib/mix/tasks/clacks/user.ex @@ -12,7 +12,11 @@ defmodule Mix.Tasks.Clacks.User do {:ok, public_key_pem} = Keys.public_key_pem(public) 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 Mix.Task.run("app.start") @@ -41,4 +45,21 @@ defmodule Mix.Tasks.Clacks.User do IO.puts("User #{username} successfully created") 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