logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

masto_fe_controller.ex (1844B)


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