defmodule Mix.Tasks.Cartosnap.Invite do
@shortdoc "Create a registration invite link"
@moduledoc """
Create a single-use registration invite and print its link. Nothing is
emailed: hand the link over yourself.
mix cartosnap.invite
mix cartosnap.invite --email sam@example.com
mix cartosnap.invite --note "for Sam" --days 7
mix cartosnap.invite --by you@example.com
* `--email` whom it is for: the link then makes that address's account
in one click, counted as confirmed (if it already has one,
the link sends them to log in)
* `--note` a reminder of who it is for, shown on the Invites page
* `--days` expire after this many days (default: never)
* `--by` the user it belongs to, so it shows on their Invites page
With no `--by`, the invite belongs to nobody. It still works; it just
appears in no one's list, which is what the very first invite has to look
like when there is nobody to own it yet.
For a fresh link to an addressed invite, see `mix cartosnap.invite.link`.
In a release, the same thing is `bin/invite` (`CartosnapApp.Release.invite/0`).
"""
use Mix.Task
@requirements ["app.start"]
@impl Mix.Task
def run(args) do
{opts, _rest, _invalid} =
OptionParser.parse(args,
strict: [email: :string, note: :string, days: :integer, by: :string]
)
case CartosnapApp.Accounts.create_invite_from_cli(opts) do
{:ok, invite} ->
Mix.shell().info(CartosnapAppWeb.invite_url(invite))
Mix.shell().info(CartosnapApp.Release.describe(invite))
{:error, :no_such_user} ->
Mix.shell().error("No user with email #{opts[:by]}")
exit({:shutdown, 1})
{:error, changeset} ->
Mix.shell().error("Could not create invite: #{inspect(changeset.errors)}")
exit({:shutdown, 1})
end
end
end
neiam
/cartosnap_ex
public · Issues · Pulls · Labels · Forks · Compare · Actions queued · Badges · Packages
⭐
Log in to mark this repository.
1.8 KiB · text
History
e569b6d