mix pleroma.user invite [OPTION...]
Options:
- - `--expire_date DATE` - last day on which token is active (e.g. "2019-04-05")
- - `--max_use NUMBER` - maximum numbers of token use
+ - `--expires_at DATE` - last day on which token is active (e.g. "2019-04-05")
+ - `--max_use NUMBER` - maximum numbers of token uses
- ## Generated invites list
+ ## List generated invites
- mix pleroma.user invites_list
+ mix pleroma.user invites
## Revoke invite
- mix pleroma.user invite_revoke TOKEN OR TOKEN_ID
+ mix pleroma.user revoke_invite TOKEN OR TOKEN_ID
## Delete the user's account.
## Delete tags from a user.
mix pleroma.user untag NICKNAME TAGS
+
+ ## Toggle confirmation of the user's account.
+
+ mix pleroma.user toggle_confirmed NICKNAME
"""
def run(["new", nickname, email | rest]) do
{options, [], []} =
admin? = Keyword.get(options, :admin, false)
assume_yes? = Keyword.get(options, :assume_yes, false)
- Mix.shell().info("""
+ Common.shell_info("""
A user will be created with the following information:
- nickname: #{nickname}
- email: #{email}
- admin: #{if(admin?, do: "true", else: "false")}
""")
- proceed? = assume_yes? or Mix.shell().yes?("Continue?")
+ proceed? = assume_yes? or Common.shell_yes?("Continue?")
- unless not proceed? do
+ if proceed? do
Common.start_pleroma()
params = %{
bio: bio
}
- changeset = User.register_changeset(%User{}, params, confirmed: true)
+ changeset = User.register_changeset(%User{}, params, need_confirmation: false)
{:ok, _user} = User.register(changeset)
- Mix.shell().info("User #{nickname} created")
+ Common.shell_info("User #{nickname} created")
if moderator? do
run(["set", nickname, "--moderator"])
run(["reset_password", nickname])
end
else
- Mix.shell().info("User will not be created.")
+ Common.shell_info("User will not be created.")
end
end
def run(["rm", nickname]) do
Common.start_pleroma()
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
- User.delete(user)
- Mix.shell().info("User #{nickname} deleted.")
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
+ User.perform(:delete, user)
+ Common.shell_info("User #{nickname} deleted.")
else
_ ->
- Mix.shell().error("No local user #{nickname}")
+ Common.shell_error("No local user #{nickname}")
end
end
def run(["toggle_activated", nickname]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
{:ok, user} = User.deactivate(user, !user.info.deactivated)
- Mix.shell().info(
+ Common.shell_info(
"Activation status of #{nickname}: #{if(user.info.deactivated, do: "de", else: "")}activated"
)
else
_ ->
- Mix.shell().error("No user #{nickname}")
+ Common.shell_error("No user #{nickname}")
end
end
def run(["reset_password", nickname]) do
Common.start_pleroma()
- with %User{local: true} = user <- User.get_by_nickname(nickname),
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname),
{:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do
- Mix.shell().info("Generated password reset token for #{user.nickname}")
+ Common.shell_info("Generated password reset token for #{user.nickname}")
IO.puts(
"URL: #{
)
else
_ ->
- Mix.shell().error("No local user #{nickname}")
+ Common.shell_error("No local user #{nickname}")
end
end
def run(["unsubscribe", nickname]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
- Mix.shell().info("Deactivating #{user.nickname}")
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
+ Common.shell_info("Deactivating #{user.nickname}")
User.deactivate(user)
{:ok, friends} = User.get_friends(user)
Enum.each(friends, fn friend ->
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
- Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}")
+ Common.shell_info("Unsubscribing #{friend.nickname} from #{user.nickname}")
User.unfollow(user, friend)
end)
:timer.sleep(500)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
if Enum.empty?(user.following) do
- Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}")
+ Common.shell_info("Successfully unsubscribed all followers from #{user.nickname}")
end
else
_ ->
- Mix.shell().error("No user #{nickname}")
+ Common.shell_error("No user #{nickname}")
end
end
]
)
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
user =
case Keyword.get(options, :moderator) do
nil -> user
end
else
_ ->
- Mix.shell().error("No local user #{nickname}")
+ Common.shell_error("No local user #{nickname}")
end
end
def run(["tag", nickname | tags]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
user = user |> User.tag(tags)
- Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}")
+ Common.shell_info("Tags of #{user.nickname}: #{inspect(tags)}")
else
_ ->
- Mix.shell().error("Could not change user tags for #{nickname}")
+ Common.shell_error("Could not change user tags for #{nickname}")
end
end
def run(["untag", nickname | tags]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
user = user |> User.untag(tags)
- Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}")
+ Common.shell_info("Tags of #{user.nickname}: #{inspect(tags)}")
else
_ ->
- Mix.shell().error("Could not change user tags for #{nickname}")
+ Common.shell_error("Could not change user tags for #{nickname}")
end
end
{options, [], []} =
OptionParser.parse(rest,
strict: [
- expire_date: :string,
+ expires_at: :string,
max_use: :integer
]
)
- expire_at =
- with expire_date when expire_date != nil <- Keyword.get(options, :expire_date) do
- Date.from_iso8601!(expire_date)
- end
-
- options = Keyword.put(options, :expire_at, expire_at)
+ options =
+ options
+ |> Keyword.update(:expires_at, {:ok, nil}, fn
+ nil -> {:ok, nil}
+ val -> Date.from_iso8601(val)
+ end)
+ |> Enum.into(%{})
Common.start_pleroma()
- with {:ok, token} <- UserInviteToken.create_token(options) do
- Mix.shell().info(
- "Generated user invite token " <> String.replace(token.token_type, "_", " ")
+ with {:ok, val} <- options[:expires_at],
+ options = Map.put(options, :expires_at, val),
+ {:ok, invite} <- UserInviteToken.create_invite(options) do
+ Common.shell_info(
+ "Generated user invite token " <> String.replace(invite.invite_type, "_", " ")
)
url =
Pleroma.Web.Router.Helpers.redirect_url(
Pleroma.Web.Endpoint,
:registration_page,
- token.token
+ invite.token
)
IO.puts(url)
else
- _ ->
- Mix.shell().error("Could not create invite token.")
+ error ->
+ Common.shell_error("Could not create invite token: #{inspect(error)}")
end
end
- def run(["invites_list"]) do
+ def run(["invites"]) do
Common.start_pleroma()
- Mix.shell().info("Invites list:")
+ Common.shell_info("Invites list:")
UserInviteToken.list_invites()
|> Enum.each(fn invite ->
- expire_date =
- case invite.expire_at do
- nil -> nil
- date -> " | Expire date: #{Date.to_string(date)}"
+ expire_info =
+ with expires_at when not is_nil(expires_at) <- invite.expires_at do
+ " | Expires at: #{Date.to_string(expires_at)}"
end
using_info =
- case invite.max_use do
- nil -> nil
- max_use -> " | Max use: #{max_use} Left use: #{max_use - invite.uses}"
+ with max_use when not is_nil(max_use) <- invite.max_use do
+ " | Max use: #{max_use} Left use: #{max_use - invite.uses}"
end
- Mix.shell().info(
- "ID: #{invite.id} | Token: #{invite.token} | Token type: #{invite.token_type} | Used: #{
+ Common.shell_info(
+ "ID: #{invite.id} | Token: #{invite.token} | Token type: #{invite.invite_type} | Used: #{
invite.used
- }#{expire_date}#{using_info}"
+ }#{expire_info}#{using_info}"
)
end)
end
- def run(["invite_revoke", token]) do
+ def run(["revoke_invite", token]) do
Common.start_pleroma()
- with {:ok, _} <- UserInviteToken.mark_as_used(token) do
- Mix.shell().info("Invite for token #{token} was revoked.")
+ with {:ok, invite} <- UserInviteToken.find_by_token(token),
+ {:ok, _} <- UserInviteToken.update_invite(invite, %{used: true}) do
+ Common.shell_info("Invite for token #{token} was revoked.")
else
- _ -> Mix.shell().error("No invite found with token #{token}")
+ _ -> Common.shell_error("No invite found with token #{token}")
end
end
def run(["delete_activities", nickname]) do
Common.start_pleroma()
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
- User.delete_user_activities(user)
- Mix.shell().info("User #{nickname} statuses deleted.")
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
+ {:ok, _} = User.delete_user_activities(user)
+ Common.shell_info("User #{nickname} statuses deleted.")
+ else
+ _ ->
+ Common.shell_error("No local user #{nickname}")
+ end
+ end
+
+ def run(["toggle_confirmed", nickname]) do
+ Common.start_pleroma()
+
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
+ {:ok, user} = User.toggle_confirmation(user)
+
+ message = if user.info.confirmation_pending, do: "needs", else: "doesn't need"
+
+ Common.shell_info("#{nickname} #{message} confirmation.")
else
_ ->
- Mix.shell().error("No local user #{nickname}")
+ Common.shell_error("No local user #{nickname}")
end
end
{:ok, user} = User.update_and_set_cache(user_cng)
- Mix.shell().info("Moderator status of #{user.nickname}: #{user.info.is_moderator}")
+ Common.shell_info("Moderator status of #{user.nickname}: #{user.info.is_moderator}")
user
end
{:ok, user} = User.update_and_set_cache(user_cng)
- Mix.shell().info("Admin status of #{user.nickname}: #{user.info.is_admin}")
+ Common.shell_info("Admin status of #{user.nickname}: #{user.info.is_admin}")
user
end
{:ok, user} = User.update_and_set_cache(user_cng)
- Mix.shell().info("Locked status of #{user.nickname}: #{user.info.locked}")
+ Common.shell_info("Locked status of #{user.nickname}: #{user.info.locked}")
user
end
end