# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.User do
end
def maybe_validate_required_email(changeset, true), do: changeset
- def maybe_validate_required_email(changeset, _), do: validate_required(changeset, [:email])
+
+ def maybe_validate_required_email(changeset, _) do
+ if Pleroma.Config.get([:instance, :account_activation_required]) do
+ validate_required(changeset, [:email])
+ else
+ changeset
+ end
+ end
defp put_ap_id(changeset) do
ap_id = ap_id(%User{nickname: get_field(changeset, :nickname)})
Cachex.del(:user_cache, "nickname:#{user.nickname}")
end
+ @spec get_cached_by_ap_id(String.t()) :: User.t() | nil
def get_cached_by_ap_id(ap_id) do
key = "ap_id:#{ap_id}"
- Cachex.fetch!(:user_cache, key, fn _ -> get_by_ap_id(ap_id) end)
+
+ with {:ok, nil} <- Cachex.get(:user_cache, key),
+ user when not is_nil(user) <- get_by_ap_id(ap_id),
+ {:ok, true} <- Cachex.put(:user_cache, key, user) do
+ user
+ else
+ {:ok, user} -> user
+ nil -> nil
+ end
end
def get_cached_by_id(id) do