Browse Source

Fix user add task, add change password task

master
Shadowfacts 1 year ago
parent
commit
7054b39937
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
1 changed files with 22 additions and 1 deletions
  1. +22
    -1
      lib/mix/tasks/clacks/user.ex

+ 22
- 1
lib/mix/tasks/clacks/user.ex View File

@ -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

Loading…
Cancel
Save