Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

64 Zeilen
1.8KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 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.Plugs.EnsurePublicOrAuthenticatedPlug
  8. alias Pleroma.Web.Plugs.OAuthScopesPlug
  9. plug(OAuthScopesPlug, %{scopes: ["write:accounts"]} when action == :put_settings)
  10. # Note: :index action handles attempt of unauthenticated access to private instance with redirect
  11. plug(:skip_plug, EnsurePublicOrAuthenticatedPlug when action == :index)
  12. plug(
  13. OAuthScopesPlug,
  14. %{scopes: ["read"], fallback: :proceed_unauthenticated}
  15. when action == :index
  16. )
  17. plug(
  18. :skip_plug,
  19. [OAuthScopesPlug, EnsurePublicOrAuthenticatedPlug] when action == :manifest
  20. )
  21. @doc "GET /web/*path"
  22. def index(%{assigns: %{user: user, token: token}} = conn, _params)
  23. when not is_nil(user) and not is_nil(token) do
  24. conn
  25. |> put_layout(false)
  26. |> render("index.html",
  27. token: token.token,
  28. user: user,
  29. custom_emojis: Pleroma.Emoji.get_all()
  30. )
  31. end
  32. def index(conn, _params) do
  33. conn
  34. |> put_session(:return_to, conn.request_path)
  35. |> redirect(to: "/web/login")
  36. end
  37. @doc "GET /web/manifest.json"
  38. def manifest(conn, _params) do
  39. conn
  40. |> render("manifest.json")
  41. end
  42. @doc "PUT /api/web/settings: Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere"
  43. def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
  44. with {:ok, _} <- User.mastodon_settings_update(user, settings) do
  45. json(conn, %{})
  46. else
  47. e ->
  48. conn
  49. |> put_status(:internal_server_error)
  50. |> json(%{error: inspect(e)})
  51. end
  52. end
  53. end