Skip to content
Snippets Groups Projects
Verified Commit 9415237a authored by Alex Gleason's avatar Alex Gleason
Browse files

Make POST /api/v1/accounts "agreement" field more lenient

parent 1b5f8d19
No related branches found
No related tags found
No related merge requests found
Pipeline #24796 failed
......@@ -88,7 +88,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
@doc "POST /api/v1/accounts"
def create(
%{assigns: %{app: app}} = conn,
%{"username" => nickname, "password" => _, "agreement" => true} = params
%{"username" => nickname, "password" => _, "agreement" => _} = params
) do
params =
params
......@@ -106,7 +106,8 @@ def create(
|> Map.put("confirm", params["password"])
|> Map.put("trusted_app", app.trusted)
with :ok <- validate_email_param(params),
with :ok <- validate_agreement_param(params),
: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, %{
......@@ -128,6 +129,17 @@ def create(conn, _) do
render_error(conn, :forbidden, "Invalid credentials")
end
defp validate_agreement_param(%{"agreement" => a}) do
case a == true || a == "true" || a == "on" do
true -> :ok
_ -> {:error, %{"error" => "Agreement must be accepted"}}
end
end
defp validate_agreement_param(%{"agreement" => _}) do
{:error, %{"error" => "Agreement must be accepted"}}
end
defp validate_email_param(%{"email" => _}), do: :ok
defp validate_email_param(_) do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment