re-integrate redirect
This commit is contained in:
@ -6,4 +6,28 @@ defmodule SomethingErlangWeb.PageController do
|
||||
# so skip the default app layout.
|
||||
render(conn, :home)
|
||||
end
|
||||
|
||||
def to_forum_path(conn, %{"forum_path" => path} = _params) do
|
||||
{redirect_good, thread, page} =
|
||||
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, to: ~p"/thread/#{thread}?page=#{page}")
|
||||
else
|
||||
put_flash(conn, :error, "Could not resolve URL")
|
||||
render(conn, :home)
|
||||
end
|
||||
end
|
||||
|
||||
def to_forum_path(conn, params) do
|
||||
params |> IO.inspect()
|
||||
render(conn, :home)
|
||||
end
|
||||
end
|
||||
|
@ -1,3 +1,8 @@
|
||||
<.form :let={f} for={@conn} action={~p"/"}>
|
||||
<input type="url" name="forum_path" />
|
||||
<input type="submit" class="btn btn-sm" value="Redirect">
|
||||
</.form>
|
||||
|
||||
<pre>
|
||||
<%= inspect(@current_user) %>
|
||||
<%= inspect(@current_user) %>
|
||||
</pre>
|
||||
|
@ -21,10 +21,12 @@ defmodule SomethingErlangWeb.Router do
|
||||
pipe_through [:browser]
|
||||
|
||||
get "/", PageController, :home
|
||||
post "/", PageController, :to_forum_path
|
||||
|
||||
live_session :user_browsing,
|
||||
on_mount: [{SomethingErlangWeb.UserAuth, :mount_current_user}] do
|
||||
live "/thread", ThreadLive
|
||||
live "/thread/:id", ThreadLive
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user