1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.UserInviteToken do
10 alias Pleroma.{UserInviteToken, Repo}
12 schema "user_invite_tokens" do
13 field(:token, :string)
14 field(:used, :boolean, default: false)
20 token = :crypto.strong_rand_bytes(32) |> Base.url_encode64()
22 token = %UserInviteToken{
30 def used_changeset(struct) do
33 |> put_change(:used, true)
36 def mark_as_used(token) do
37 with %{used: false} = token <- Repo.get_by(UserInviteToken, %{token: token}),
38 {:ok, token} <- Repo.update(used_changeset(token)) do