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.
|
and import those modules here.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def static_paths, do: ~w(assets images favicon.ico favicon.svg robots.txt)
|
||||||
|
|
||||||
def controller do
|
def controller do
|
||||||
quote do
|
quote do
|
||||||
use Phoenix.Controller, namespace: PhilomenaWeb
|
use Phoenix.Controller, namespace: PhilomenaWeb
|
||||||
|
@ -26,6 +28,8 @@ defmodule PhilomenaWeb do
|
||||||
import Canary.Plugs
|
import Canary.Plugs
|
||||||
import PhilomenaWeb.ModerationLogPlug, only: [moderation_log: 2]
|
import PhilomenaWeb.ModerationLogPlug, only: [moderation_log: 2]
|
||||||
alias PhilomenaWeb.Router.Helpers, as: Routes
|
alias PhilomenaWeb.Router.Helpers, as: Routes
|
||||||
|
|
||||||
|
unquote(verified_routes())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,6 +51,8 @@ defmodule PhilomenaWeb do
|
||||||
|
|
||||||
# Wrong way around for convenience
|
# Wrong way around for convenience
|
||||||
import PhilomenaWeb.AppView
|
import PhilomenaWeb.AppView
|
||||||
|
|
||||||
|
unquote(verified_routes())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -65,6 +71,15 @@ defmodule PhilomenaWeb do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def verified_routes do
|
||||||
|
quote do
|
||||||
|
use Phoenix.VerifiedRoutes,
|
||||||
|
endpoint: PhilomenaWeb.Endpoint,
|
||||||
|
router: PhilomenaWeb.Router,
|
||||||
|
statics: PhilomenaWeb.static_paths()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
When used, dispatch to the appropriate controller/view/etc.
|
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)
|
if user, do: Channels.clear_notification(channel, user)
|
||||||
|
|
||||||
redirect(conn, external: url(channel))
|
redirect(conn, external: channel_url(channel))
|
||||||
end
|
end
|
||||||
|
|
||||||
def new(conn, _params) do
|
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, true), do: query
|
||||||
defp maybe_show_nsfw(query, _falsy), do: where(query, [c], c.nsfw == false)
|
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}"
|
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}"
|
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}"
|
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}"
|
do: "https://www.twitch.tv/#{short_name}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,8 @@ defmodule PhilomenaWeb.TorPlug do
|
||||||
plug PhilomenaWeb.TorPlug
|
plug PhilomenaWeb.TorPlug
|
||||||
"""
|
"""
|
||||||
alias PhilomenaWeb.Router.Helpers, as: Routes
|
alias PhilomenaWeb.Router.Helpers, as: Routes
|
||||||
|
use PhilomenaWeb, :verified_routes
|
||||||
|
|
||||||
alias Phoenix.Controller
|
alias Phoenix.Controller
|
||||||
alias Plug.Conn
|
alias Plug.Conn
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ defmodule PhilomenaWeb.TotpPlug do
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alias PhilomenaWeb.Router.Helpers, as: Routes
|
alias PhilomenaWeb.Router.Helpers, as: Routes
|
||||||
|
use PhilomenaWeb, :verified_routes
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec init(any()) :: any()
|
@spec init(any()) :: any()
|
||||||
|
|
|
@ -7,6 +7,8 @@ defmodule PhilomenaWeb.UserAuth do
|
||||||
alias PhilomenaWeb.UserIpUpdater
|
alias PhilomenaWeb.UserIpUpdater
|
||||||
alias PhilomenaWeb.UserFingerprintUpdater
|
alias PhilomenaWeb.UserFingerprintUpdater
|
||||||
|
|
||||||
|
use PhilomenaWeb, :verified_routes
|
||||||
|
|
||||||
# Make the remember me cookie valid for 365 days.
|
# Make the remember me cookie valid for 365 days.
|
||||||
# If you want bump or reduce this value, also change
|
# If you want bump or reduce this value, also change
|
||||||
# the token expiry itself in UserToken.
|
# the token expiry itself in UserToken.
|
||||||
|
|
|
@ -25,6 +25,8 @@ defmodule PhilomenaWeb.ConnCase do
|
||||||
|
|
||||||
# The default endpoint for testing
|
# The default endpoint for testing
|
||||||
@endpoint PhilomenaWeb.Endpoint
|
@endpoint PhilomenaWeb.Endpoint
|
||||||
|
|
||||||
|
use PhilomenaWeb, :verified_routes
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue