X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fuser_invite_token.ex;h=a08ba99f1107710aa33e794f791c9562992ceaee;hb=e87cca97e62d8464c87c7335741f54c2299cc0d6;hp=6247831d51a3c407c70af0288ce86f5200d56ee6;hpb=d0696fdfd6acaee011f4011d69b8221448bfa89e;p=akkoma
diff --git a/lib/pleroma/user_invite_token.ex b/lib/pleroma/user_invite_token.ex
index 6247831d5..a08ba99f1 100644
--- a/lib/pleroma/user_invite_token.ex
+++ b/lib/pleroma/user_invite_token.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UserInviteToken do
@@ -24,7 +24,7 @@ defmodule Pleroma.UserInviteToken do
timestamps()
end
- @spec create_invite(map()) :: UserInviteToken.t()
+ @spec create_invite(map()) :: {:ok, UserInviteToken.t()}
def create_invite(params \\ %{}) do
%UserInviteToken{}
|> cast(params, [:max_use, :expires_at])
@@ -74,7 +74,7 @@ defmodule Pleroma.UserInviteToken do
@spec find_by_token(token()) :: {:ok, UserInviteToken.t()} | nil
def find_by_token(token) do
- with invite <- Repo.get_by(UserInviteToken, token: token) do
+ with %UserInviteToken{} = invite <- Repo.get_by(UserInviteToken, token: token) do
{:ok, invite}
end
end
@@ -96,9 +96,8 @@ defmodule Pleroma.UserInviteToken do
not_overdue_date?(invite) and invite.uses < invite.max_use and not invite.used
end
- defp not_overdue_date?(%{expires_at: expires_at} = invite) do
- Date.compare(Date.utc_today(), expires_at) in [:lt, :eq] ||
- (update_invite!(invite, %{used: true}) && false)
+ defp not_overdue_date?(%{expires_at: expires_at}) do
+ Date.compare(Date.utc_today(), expires_at) in [:lt, :eq]
end
@spec update_usage!(UserInviteToken.t()) :: nil | UserInviteToken.t() | no_return()