Merge branch 'develop' into oembed_provider
[akkoma] / lib / pleroma / web / router.ex
index ad26093acaf24ec5f8f2a0f5fca0e3bb8933c1f1..751624e80cc381adee8e85b8f0380521be369263 100644 (file)
@@ -85,6 +85,15 @@ defmodule Pleroma.Web.Router do
     plug(:accepts, ["html", "json"])
   end
 
+  pipeline :mailbox_preview do
+    plug(:accepts, ["html"])
+
+    plug(:put_secure_browser_headers, %{
+      "content-security-policy" =>
+        "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
+    })
+  end
+
   scope "/api/pleroma", Pleroma.Web.TwitterAPI do
     pipe_through(:pleroma_api)
     get("/password_reset/:token", UtilController, :show_password_reset)
@@ -268,6 +277,7 @@ defmodule Pleroma.Web.Router do
     get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
 
     post("/account/register", TwitterAPI.Controller, :register)
+    post("/account/password_reset", TwitterAPI.Controller, :password_reset)
 
     get("/search", TwitterAPI.Controller, :search)
     get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
@@ -434,6 +444,14 @@ defmodule Pleroma.Web.Router do
     get("/:sig/:url/:filename", MediaProxyController, :remote)
   end
 
+  if Mix.env() == :dev do
+    scope "/dev" do
+      pipe_through([:mailbox_preview])
+
+      forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
+    end
+  end
+
   scope "/", Fallback do
     get("/registration/:token", RedirectController, :registration_page)
     get("/*path", RedirectController, :redirector)
@@ -449,12 +467,12 @@ defmodule Fallback.RedirectController do
   def redirector(conn, _params) do
     conn
     |> put_resp_content_type("text/html")
-    |> send_file(200, Application.app_dir(:pleroma, "priv/static/index.html"))
+    |> send_file(200, index_file_path())
   end
 
   def redirector_with_meta(conn, params) do
-    {:ok, index_content } = File.read(Application.app_dir(:pleroma, "priv/static/index.html"))
-    tags = Metadata.build_tags(request_url(conn), params)
+    {:ok, index_content} = File.read(index_file_path())
+    tags = Metadata.build_tags(params)
     response = String.replace(index_content, "<!--server-generated-meta-->", tags)
 
     conn
@@ -462,6 +480,10 @@ defmodule Fallback.RedirectController do
     |> send_resp(200, response)
   end
 
+  def index_file_path do
+    Application.app_dir(:pleroma, "priv/static/index.html")
+  end
+
   def registration_page(conn, params) do
     redirector(conn, params)
   end