mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
Add verified routes to web
This commit is contained in:
parent
ca9cb3a50e
commit
9566b9b73f
6 changed files with 27 additions and 5 deletions
|
@ -17,6 +17,8 @@ defmodule PhilomenaWeb do
|
|||
and import those modules here.
|
||||
"""
|
||||
|
||||
def static_paths, do: ~w(assets images favicon.ico favicon.svg robots.txt)
|
||||
|
||||
def controller do
|
||||
quote do
|
||||
use Phoenix.Controller, namespace: PhilomenaWeb
|
||||
|
@ -26,6 +28,8 @@ defmodule PhilomenaWeb do
|
|||
import Canary.Plugs
|
||||
import PhilomenaWeb.ModerationLogPlug, only: [moderation_log: 2]
|
||||
alias PhilomenaWeb.Router.Helpers, as: Routes
|
||||
|
||||
unquote(verified_routes())
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,6 +51,8 @@ defmodule PhilomenaWeb do
|
|||
|
||||
# Wrong way around for convenience
|
||||
import PhilomenaWeb.AppView
|
||||
|
||||
unquote(verified_routes())
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -65,6 +71,15 @@ defmodule PhilomenaWeb do
|
|||
end
|
||||
end
|
||||
|
||||
def verified_routes do
|
||||
quote do
|
||||
use Phoenix.VerifiedRoutes,
|
||||
endpoint: PhilomenaWeb.Endpoint,
|
||||
router: PhilomenaWeb.Router,
|
||||
statics: PhilomenaWeb.static_paths()
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
When used, dispatch to the appropriate controller/view/etc.
|
||||
"""
|
||||
|
|
|
@ -39,7 +39,7 @@ defmodule PhilomenaWeb.ChannelController do
|
|||
|
||||
if user, do: Channels.clear_notification(channel, user)
|
||||
|
||||
redirect(conn, external: url(channel))
|
||||
redirect(conn, external: channel_url(channel))
|
||||
end
|
||||
|
||||
def new(conn, _params) do
|
||||
|
@ -101,15 +101,15 @@ defmodule PhilomenaWeb.ChannelController do
|
|||
defp maybe_show_nsfw(query, true), do: query
|
||||
defp maybe_show_nsfw(query, _falsy), do: where(query, [c], c.nsfw == false)
|
||||
|
||||
defp url(%{type: "LivestreamChannel", short_name: short_name}),
|
||||
defp channel_url(%{type: "LivestreamChannel", short_name: short_name}),
|
||||
do: "http://www.livestream.com/#{short_name}"
|
||||
|
||||
defp url(%{type: "PicartoChannel", short_name: short_name}),
|
||||
defp channel_url(%{type: "PicartoChannel", short_name: short_name}),
|
||||
do: "https://picarto.tv/#{short_name}"
|
||||
|
||||
defp url(%{type: "PiczelChannel", short_name: short_name}),
|
||||
defp channel_url(%{type: "PiczelChannel", short_name: short_name}),
|
||||
do: "https://piczel.tv/watch/#{short_name}"
|
||||
|
||||
defp url(%{type: "TwitchChannel", short_name: short_name}),
|
||||
defp channel_url(%{type: "TwitchChannel", short_name: short_name}),
|
||||
do: "https://www.twitch.tv/#{short_name}"
|
||||
end
|
||||
|
|
|
@ -7,6 +7,8 @@ defmodule PhilomenaWeb.TorPlug do
|
|||
plug PhilomenaWeb.TorPlug
|
||||
"""
|
||||
alias PhilomenaWeb.Router.Helpers, as: Routes
|
||||
use PhilomenaWeb, :verified_routes
|
||||
|
||||
alias Phoenix.Controller
|
||||
alias Plug.Conn
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ defmodule PhilomenaWeb.TotpPlug do
|
|||
"""
|
||||
|
||||
alias PhilomenaWeb.Router.Helpers, as: Routes
|
||||
use PhilomenaWeb, :verified_routes
|
||||
|
||||
@doc false
|
||||
@spec init(any()) :: any()
|
||||
|
|
|
@ -7,6 +7,8 @@ defmodule PhilomenaWeb.UserAuth do
|
|||
alias PhilomenaWeb.UserIpUpdater
|
||||
alias PhilomenaWeb.UserFingerprintUpdater
|
||||
|
||||
use PhilomenaWeb, :verified_routes
|
||||
|
||||
# Make the remember me cookie valid for 365 days.
|
||||
# If you want bump or reduce this value, also change
|
||||
# the token expiry itself in UserToken.
|
||||
|
|
|
@ -25,6 +25,8 @@ defmodule PhilomenaWeb.ConnCase do
|
|||
|
||||
# The default endpoint for testing
|
||||
@endpoint PhilomenaWeb.Endpoint
|
||||
|
||||
use PhilomenaWeb, :verified_routes
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue