better redirect logic
This commit is contained in:
@ -8,14 +8,23 @@ defmodule SomethingErlangWeb.PageController do
|
|||||||
def to_forum_path(conn, %{"to" => redir_params} = _params) do
|
def to_forum_path(conn, %{"to" => redir_params} = _params) do
|
||||||
%{"forum_path" => path} = redir_params
|
%{"forum_path" => path} = redir_params
|
||||||
|
|
||||||
with [_, thread] <- Regex.run(~r{threadid=(\d+)}, path),
|
{redirect_good, thread, page} =
|
||||||
[_, page] <- Regex.run(~r{pagenumber=(\d+)}, path) do
|
case {
|
||||||
|
Regex.run(~r{threadid=(\d+)}, path),
|
||||||
|
Regex.run(~r{pagenumber=(\d+)}, path)
|
||||||
|
} do
|
||||||
|
{[_, thread], nil} -> {:ok, thread, 1}
|
||||||
|
{[_, thread], [_, page]} -> {:ok, thread, page}
|
||||||
|
_ -> {:error, nil, nil}
|
||||||
|
end
|
||||||
|
|
||||||
|
if redirect_good == :ok do
|
||||||
redirect(conn,
|
redirect(conn,
|
||||||
to: Routes.thread_show_path(conn, :show, thread, page: page)
|
to: Routes.thread_show_path(conn, :show, thread, page: page)
|
||||||
)
|
)
|
||||||
|
else
|
||||||
|
put_flash(conn, :error, "Could not resolve URL")
|
||||||
|
render(conn, "index.html")
|
||||||
end
|
end
|
||||||
|
|
||||||
put_flash(conn, :error, "Could not resolve URL")
|
|
||||||
render(conn, "index.html")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user