1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastoFEController do
6 use Pleroma.Web, :controller
9 alias Pleroma.Web.MastodonAPI.AuthController
10 alias Pleroma.Web.OAuth.Token
11 alias Pleroma.Web.Plugs.OAuthScopesPlug
13 plug(OAuthScopesPlug, %{scopes: ["write:accounts"]} when action == :put_settings)
15 # Note: :index action handles attempt of unauthenticated access to private instance with redirect
16 plug(:skip_public_check when action == :index)
20 %{scopes: ["read"], fallback: :proceed_unauthenticated}
24 plug(:skip_auth when action == :manifest)
27 def index(conn, _params) do
28 with %{assigns: %{user: %User{} = user, token: %Token{app_id: token_app_id} = token}} <- conn,
29 {:ok, %{id: ^token_app_id}} <- AuthController.local_mastofe_app() do
32 |> render("index.html",
35 custom_emojis: Pleroma.Emoji.get_all()
40 |> put_session(:return_to, conn.request_path)
41 |> redirect(to: "/web/login")
45 @doc "GET /web/manifest.json"
46 def manifest(conn, _params) do
47 render(conn, "manifest.json")
50 @doc "PUT /api/web/settings: Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere"
51 def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
52 with {:ok, _} <- User.mastodon_settings_update(user, settings) do
57 |> put_status(:internal_server_error)
58 |> json(%{error: inspect(e)})