From 0b1ca6a584219083e2d312abe2c1bdd8fab98e38 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sun, 17 Jun 2018 14:30:07 +0300 Subject: [PATCH] Token-generating task --- lib/mix/tasks/generate_invite_token.ex | 25 +++++++++++++++++++ ...serInviteToken.ex => user_invite_token.ex} | 0 lib/pleroma/web/router.ex | 5 ++++ 3 files changed, 30 insertions(+) create mode 100644 lib/mix/tasks/generate_invite_token.ex rename lib/pleroma/{UserInviteToken.ex => user_invite_token.ex} (100%) diff --git a/lib/mix/tasks/generate_invite_token.ex b/lib/mix/tasks/generate_invite_token.ex new file mode 100644 index 000000000..a5f41ef0e --- /dev/null +++ b/lib/mix/tasks/generate_invite_token.ex @@ -0,0 +1,25 @@ +defmodule Mix.Tasks.GenerateInviteToken do + use Mix.Task + + @shortdoc "Generate password reset link for user" + def run([]) do + Mix.Task.run("app.start") + + with {:ok, token} <- Pleroma.UserInviteToken.create_token() do + IO.puts("Generated user invite token") + + IO.puts( + "Url: #{ + Pleroma.Web.Router.Helpers.redirect_url( + Pleroma.Web.Endpoint, + :registration_page, + token.token + ) + }" + ) + else + _ -> + IO.puts("Error creating token") + end + end +end diff --git a/lib/pleroma/UserInviteToken.ex b/lib/pleroma/user_invite_token.ex similarity index 100% rename from lib/pleroma/UserInviteToken.ex rename to lib/pleroma/user_invite_token.ex diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 127bf4d9e..dcbf7f008 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -344,6 +344,7 @@ def user_fetcher(username) do end scope "/", Fallback do + get("/registration/:token", RedirectController, :registration_page) get("/*path", RedirectController, :redirector) end end @@ -358,4 +359,8 @@ def redirector(conn, _params) do |> send_file(200, "priv/static/index.html") end end + + def registration_page(conn, params) do + redirector(conn, params) + end end