Add password reset task.
authorlain <lain@soykaf.club>
Wed, 21 Feb 2018 17:24:17 +0000 (18:24 +0100)
committerlain <lain@soykaf.club>
Wed, 21 Feb 2018 17:24:17 +0000 (18:24 +0100)
README.md
lib/mix/tasks/generate_password_reset.ex [new file with mode: 0644]

index fcf296c01c4c7b4a9c63dca698e4bc9baa76bc0a..5c6753b0a666108e98ead4d27fa9e0fe5cda51b2 100644 (file)
--- a/README.md
+++ b/README.md
@@ -59,3 +59,9 @@ Add the following to your `dev.secret.exs` or `prod.secret.exs` if you want to p
       proxy_url: "127.0.0.1:8123"
 
 This is useful for running pleroma inside Tor or i2p.
+
+## Admin Tasks
+
+### Password reset
+
+Run `mix generate_password_reset username` to generate a password reset link that you can then send to the user.
diff --git a/lib/mix/tasks/generate_password_reset.ex b/lib/mix/tasks/generate_password_reset.ex
new file mode 100644 (file)
index 0000000..b968b1f
--- /dev/null
@@ -0,0 +1,19 @@
+defmodule Mix.Tasks.GeneratePasswordReset do
+  use Mix.Task
+  import Mix.Ecto
+  alias Pleroma.{Repo, User}
+
+  @shortdoc "Generate password reset link for user"
+  def run([nickname]) do
+    Mix.Task.run("app.start")
+
+    with %User{local: true} = user <- User.get_by_nickname(nickname),
+         {:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do
+      IO.puts "Generated password reset token for #{user.nickname}"
+      IO.puts "Url: #{Pleroma.Web.Router.Helpers.util_url(Pleroma.Web.Endpoint, :show_password_reset, token.token)}"
+    else
+      _ ->
+        IO.puts "No local user #{nickname}"
+    end
+  end
+end