1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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.EnsurePublicOrAuthenticatedPlug
12 alias Pleroma.Web.Plugs.OAuthScopesPlug
14 plug(OAuthScopesPlug, %{scopes: ["write:accounts"]} when action == :put_settings)
16 # Note: :index action handles attempt of unauthenticated access to private instance with redirect
17 plug(:skip_plug, EnsurePublicOrAuthenticatedPlug when action == :index)
21 %{scopes: ["read"], fallback: :proceed_unauthenticated}
27 [OAuthScopesPlug, EnsurePublicOrAuthenticatedPlug] when action == :manifest
31 def index(conn, _params) do
32 with %{assigns: %{user: %User{} = user, token: %Token{app_id: token_app_id} = token}} <- conn,
33 {:ok, %{id: ^token_app_id}} <- AuthController.local_mastofe_app() do
36 |> render("index.html",
39 custom_emojis: Pleroma.Emoji.get_all()
44 |> put_session(:return_to, conn.request_path)
45 |> redirect(to: "/web/login")
49 @doc "GET /web/manifest.json"
50 def manifest(conn, _params) do
51 render(conn, "manifest.json")
54 @doc "PUT /api/web/settings: Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere"
55 def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
56 with {:ok, _} <- User.mastodon_settings_update(user, settings) do
61 |> put_status(:internal_server_error)
62 |> json(%{error: inspect(e)})