Mastodon-based auth error messages. Defaulted User#auth_active?/1 to true
.
This commit is contained in:
parent
15aa94f40f
commit
263ca3dea2
3 changed files with 9 additions and 10 deletions
|
@ -60,14 +60,10 @@ defmodule Pleroma.User do
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
def auth_active?(%User{local: false}), do: true
|
|
||||||
|
|
||||||
def auth_active?(%User{info: %User.Info{confirmation_pending: false}}), do: true
|
|
||||||
|
|
||||||
def auth_active?(%User{info: %User.Info{confirmation_pending: true}}),
|
def auth_active?(%User{info: %User.Info{confirmation_pending: true}}),
|
||||||
do: !Pleroma.Config.get([:instance, :account_activation_required])
|
do: !Pleroma.Config.get([:instance, :account_activation_required])
|
||||||
|
|
||||||
def auth_active?(_), do: false
|
def auth_active?(%User{}), do: true
|
||||||
|
|
||||||
def visible_for?(user, for_user \\ nil)
|
def visible_for?(user, for_user \\ nil)
|
||||||
|
|
||||||
|
|
|
@ -83,14 +83,16 @@ def create_authorization(conn, %{
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
{scopes_issue, _} when scopes_issue in [:unsupported_scopes, :missing_scopes] ->
|
{scopes_issue, _} when scopes_issue in [:unsupported_scopes, :missing_scopes] ->
|
||||||
|
# Per https://github.com/tootsuite/mastodon/blob/51e154f5e87968d6bb115e053689767ab33e80cd/app/controllers/api/base_controller.rb#L39
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "Permissions not specified.")
|
|> put_flash(:error, "This action is outside the authorized scopes")
|
||||||
|> put_status(:unauthorized)
|
|> put_status(:unauthorized)
|
||||||
|> authorize(auth_params)
|
|> authorize(auth_params)
|
||||||
|
|
||||||
{:auth_active, false} ->
|
{:auth_active, false} ->
|
||||||
|
# Per https://github.com/tootsuite/mastodon/blob/51e154f5e87968d6bb115e053689767ab33e80cd/app/controllers/api/base_controller.rb#L76
|
||||||
conn
|
conn
|
||||||
|> put_flash(:error, "Account confirmation pending.")
|
|> put_flash(:error, "Your login is missing a confirmed e-mail address")
|
||||||
|> put_status(:forbidden)
|
|> put_status(:forbidden)
|
||||||
|> authorize(auth_params)
|
|> authorize(auth_params)
|
||||||
|
|
||||||
|
@ -149,9 +151,10 @@ def token_exchange(
|
||||||
json(conn, response)
|
json(conn, response)
|
||||||
else
|
else
|
||||||
{:auth_active, false} ->
|
{:auth_active, false} ->
|
||||||
|
# Per https://github.com/tootsuite/mastodon/blob/51e154f5e87968d6bb115e053689767ab33e80cd/app/controllers/api/base_controller.rb#L76
|
||||||
conn
|
conn
|
||||||
|> put_status(:forbidden)
|
|> put_status(:forbidden)
|
||||||
|> json(%{error: "Account confirmation pending"})
|
|> json(%{error: "Your login is missing a confirmed e-mail address"})
|
||||||
|
|
||||||
_error ->
|
_error ->
|
||||||
put_status(conn, 400)
|
put_status(conn, 400)
|
||||||
|
|
|
@ -87,7 +87,7 @@ test "returns 401 for missing scopes", %{conn: conn} do
|
||||||
assert result =~ app.redirect_uris
|
assert result =~ app.redirect_uris
|
||||||
|
|
||||||
# Error message
|
# Error message
|
||||||
assert result =~ "Permissions not specified"
|
assert result =~ "This action is outside the authorized scopes"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns 401 for scopes beyond app scopes", %{conn: conn} do
|
test "returns 401 for scopes beyond app scopes", %{conn: conn} do
|
||||||
|
@ -113,7 +113,7 @@ test "returns 401 for scopes beyond app scopes", %{conn: conn} do
|
||||||
assert result =~ app.redirect_uris
|
assert result =~ app.redirect_uris
|
||||||
|
|
||||||
# Error message
|
# Error message
|
||||||
assert result =~ "Permissions not specified"
|
assert result =~ "This action is outside the authorized scopes"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "issues a token for an all-body request" do
|
test "issues a token for an all-body request" do
|
||||||
|
|
Loading…
Reference in a new issue