diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pleroma/user.ex | 43 | ||||
| -rw-r--r-- | lib/pleroma/web/mastodon_api/views/instance_view.ex | 1 | ||||
| -rw-r--r-- | lib/pleroma/web/twitter_api/views/remote_follow_view.ex | 6 | 
3 files changed, 38 insertions, 12 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 11c4d0684..4201fff12 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -741,7 +741,7 @@ defmodule Pleroma.User do      ])      |> validate_required([:name, :nickname])      |> unique_constraint(:nickname) -    |> validate_exclusion(:nickname, Config.get([User, :restricted_nicknames])) +    |> validate_not_restricted_nickname(:nickname)      |> validate_format(:nickname, local_nickname_regex())      |> put_ap_id()      |> unique_constraint(:ap_id) @@ -789,17 +789,9 @@ defmodule Pleroma.User do      |> validate_confirmation(:password)      |> unique_constraint(:email)      |> validate_format(:email, @email_regex) -    |> validate_change(:email, fn :email, email -> -      valid? = -        Config.get([User, :email_blacklist]) -        |> Enum.all?(fn blacklisted_domain -> -          !String.ends_with?(email, ["@" <> blacklisted_domain, "." <> blacklisted_domain]) -        end) - -      if valid?, do: [], else: [email: "Invalid email"] -    end) +    |> validate_email_not_in_blacklisted_domain(:email)      |> unique_constraint(:nickname) -    |> validate_exclusion(:nickname, Config.get([User, :restricted_nicknames])) +    |> validate_not_restricted_nickname(:nickname)      |> validate_format(:nickname, local_nickname_regex())      |> validate_length(:bio, max: bio_limit)      |> validate_length(:name, min: 1, max: name_limit) @@ -813,6 +805,35 @@ defmodule Pleroma.User do      |> put_following_and_follower_and_featured_address()    end +  def validate_not_restricted_nickname(changeset, field) do +    validate_change(changeset, field, fn _, value -> +      valid? = +        Config.get([User, :restricted_nicknames]) +        |> Enum.all?(fn restricted_nickname -> +          String.downcase(value) != String.downcase(restricted_nickname) +        end) + +      if valid?, do: [], else: [nickname: "Invalid nickname"] +    end) +  end + +  def validate_email_not_in_blacklisted_domain(changeset, field) do +    validate_change(changeset, field, fn _, value -> +      valid? = +        Config.get([User, :email_blacklist]) +        |> Enum.all?(fn blacklisted_domain -> +          blacklisted_domain_downcase = String.downcase(blacklisted_domain) + +          !String.ends_with?(String.downcase(value), [ +            "@" <> blacklisted_domain_downcase, +            "." <> blacklisted_domain_downcase +          ]) +        end) + +      if valid?, do: [], else: [email: "Invalid email"] +    end) +  end +    def maybe_validate_required_email(changeset, true), do: changeset    def maybe_validate_required_email(changeset, _) do diff --git a/lib/pleroma/web/mastodon_api/views/instance_view.ex b/lib/pleroma/web/mastodon_api/views/instance_view.ex index f89c95a1c..fa2dd4731 100644 --- a/lib/pleroma/web/mastodon_api/views/instance_view.ex +++ b/lib/pleroma/web/mastodon_api/views/instance_view.ex @@ -17,6 +17,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do        uri: Pleroma.Web.Endpoint.url(),        title: Keyword.get(instance, :name),        description: Keyword.get(instance, :description), +      short_description: Keyword.get(instance, :short_description),        version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})",        email: Keyword.get(instance, :email),        urls: %{ diff --git a/lib/pleroma/web/twitter_api/views/remote_follow_view.ex b/lib/pleroma/web/twitter_api/views/remote_follow_view.ex index bd33d4c0a..8902261b0 100644 --- a/lib/pleroma/web/twitter_api/views/remote_follow_view.ex +++ b/lib/pleroma/web/twitter_api/views/remote_follow_view.ex @@ -7,5 +7,9 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowView do    import Phoenix.HTML.Form    alias Pleroma.Web.Gettext -  defdelegate avatar_url(user), to: Pleroma.User +  def avatar_url(user) do +    user +    |> Pleroma.User.avatar_url() +    |> Pleroma.Web.MediaProxy.url() +  end  end  | 
