diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pleroma/user.ex | 9 | ||||
| -rw-r--r-- | lib/pleroma/web/mastodon_api/controllers/account_controller.ex | 14 | 
2 files changed, 20 insertions, 3 deletions
| diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 5fe79333e..7531757f5 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -530,7 +530,14 @@ 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)}) diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index dc3b47415..88c997b9f 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -76,7 +76,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do    @doc "POST /api/v1/accounts"    def create(          %{assigns: %{app: app}} = conn, -        %{"username" => nickname, "email" => _, "password" => _, "agreement" => true} = params +        %{"username" => nickname, "password" => _, "agreement" => true} = params        ) do      params =        params @@ -93,7 +93,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do        |> Map.put("bio", params["bio"] || "")        |> Map.put("confirm", params["password"]) -    with {:ok, user} <- TwitterAPI.register_user(params, need_confirmation: true), +    with :ok <- validate_email_param(params), +         {:ok, user} <- TwitterAPI.register_user(params, need_confirmation: true),           {:ok, token} <- Token.create_token(app, user, %{scopes: app.scopes}) do        json(conn, %{          token_type: "Bearer", @@ -114,6 +115,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do      render_error(conn, :forbidden, "Invalid credentials")    end +  defp validate_email_param(%{"email" => _}), do: :ok + +  defp validate_email_param(_) do +    case Pleroma.Config.get([:instance, :account_activation_required]) do +      true -> {:error, %{"error" => "Missing parameters"}} +      _ -> :ok +    end +  end +    @doc "GET /api/v1/accounts/verify_credentials"    def verify_credentials(%{assigns: %{user: user}} = conn, _) do      chat_token = Phoenix.Token.sign(conn, "user socket", user.id) | 
