+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.User do
use Ecto.Schema
timestamps()
end
- def auth_active?(%User{} = user), do: user.info && !user.info.confirmation_pending
+ def auth_active?(%User{} = user) do
+ (user.info && !user.info.confirmation_pending) ||
+ !Pleroma.Config.get([:instance, :account_activation_required])
+ end
+
+ def remote_or_auth_active?(%User{} = user), do: !user.local || auth_active?(user)
+ def visible_for?(%User{} = user, for_user \\ nil) do
+ User.remote_or_auth_active?(user) || (for_user && for_user.id == user.id) ||
+ User.superuser?(for_user)
+ end
+
+ def superuser?(nil), do: false
def superuser?(%User{} = user), do: user.info && User.Info.superuser?(user.info)
def avatar_url(user) do
|> validate_confirmation(:password)
|> unique_constraint(:email)
|> unique_constraint(:nickname)
+ |> validate_exclusion(:nickname, Pleroma.Config.get([Pleroma.User, :restricted_nicknames]))
|> validate_format(:nickname, local_nickname_regex())
|> validate_format(:email, @email_regex)
|> validate_length(:bio, max: 1000)
end
def try_send_confirmation_email(%User{} = user) do
- if user.info.confirmation_pending do
+ if user.info.confirmation_pending &&
+ Pleroma.Config.get([:instance, :account_activation_required]) do
user
|> Pleroma.UserEmail.account_confirmation_email()
|> Pleroma.Mailer.deliver()
end
end
- def get_by_confirmation_token(token) do
- Repo.one(from(u in User, where: fragment("? ->> 'confirmation_token' = ?", u.info, ^token)))
- end
-
def get_followers_query(%User{id: id, follower_address: follower_address}) do
from(
u in User,