Move generate_invite to user.ex

This commit is contained in:
Rin Toshaka 2018-12-02 20:26:15 +01:00
parent d924b6cd3d
commit 57c71f8468
3 changed files with 26 additions and 25 deletions

View file

@ -1,24 +0,0 @@
defmodule Mix.Tasks.Pleroma.Gen.Invite do
use Mix.Task
@shortdoc "Generates a user invite token"
def run([]) do
Mix.Task.run("app.start")
with {:ok, token} <- Pleroma.UserInviteToken.create_token() do
Mix.shell().info("Generated user invite token")
url =
Pleroma.Web.Router.Helpers.redirect_url(
Pleroma.Web.Endpoint,
:registration_page,
token.token
)
IO.puts("URL: #{url}")
else
_ ->
Mix.shell().error("Could not create invite token.")
end
end
end

View file

@ -6,7 +6,7 @@ defmodule Mix.Tasks.Pleroma.Instance do
@moduledoc """
Manages Pleroma instance.
## Generate a new instance.
## Generate a new instance config.
mix pleroma.instance new [OPTION...]
@ -145,6 +145,7 @@ def run(["new" | rest]) do
end
end
defp escape_sh_path(path) do
~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
end

View file

@ -16,6 +16,10 @@ defmodule Mix.Tasks.Pleroma.User do
- `--password PASSWORD` - the user's password
- `--moderator`/`--no-moderator` - whether the user is a moderator
- `--admin`/`--no-admin` - whether the user is an admin
## Generate an invite link.
mix pleroma.user invite
## Delete the user's account.
@ -255,6 +259,26 @@ defp set_admin(nickname, value) do
end
end
def run(["invite"]) do
Mix.Task.run("app.start")
with {:ok, token} <- Pleroma.UserInviteToken.create_token() do
Mix.shell().info("Generated user invite token")
url =
Pleroma.Web.Router.Helpers.redirect_url(
Pleroma.Web.Endpoint,
:registration_page,
token.token
)
IO.puts(url)
else
_ ->
Mix.shell().error("Could not create invite token.")
end
end
defp set_locked(nickname, value) do
Mix.Ecto.ensure_started(Repo, [])