fixed form
This commit is contained in:
@ -1,9 +1,46 @@
|
|||||||
defmodule SomethingErlangWeb.PageController do
|
defmodule SomethingErlangWeb.PageController do
|
||||||
use SomethingErlangWeb, :controller
|
use SomethingErlangWeb, :controller
|
||||||
|
|
||||||
def home(conn, _params) do
|
def home(conn, params) do
|
||||||
# The home page is often custom made,
|
# The home page is often custom made,
|
||||||
# so skip the default app layout.
|
# so skip the default app layout.
|
||||||
render(conn, :home, layout: false)
|
conn = assign(conn, :params, params)
|
||||||
|
render(conn, :home)
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_forum_path(conn, %{"forum_path" => path} = _params) do
|
||||||
|
with {:ok, thread, page} <- resolve_url(path) 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
|
||||||
|
render(conn, :home)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp resolve_url(url) do
|
||||||
|
threadid =
|
||||||
|
case Regex.run(~r{threadid=(\d+)}, url) do
|
||||||
|
[_, threadid] -> {:ok, threadid}
|
||||||
|
nil -> {:error, :nothreadid}
|
||||||
|
end
|
||||||
|
|
||||||
|
page =
|
||||||
|
case Regex.run(~r{pagenumber=(\d+)}, url) do
|
||||||
|
[_, page] -> {:ok, page}
|
||||||
|
nil -> {:ok, 1}
|
||||||
|
end
|
||||||
|
|
||||||
|
with {:ok, threadid} <- threadid,
|
||||||
|
{:ok, page} <- page do
|
||||||
|
{:ok, threadid, page}
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
{:error, :cantparseurl}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
<.flash_group flash={@flash} />
|
<.flash_group flash={@flash} />
|
||||||
<.form :let={f} for={@conn} action={~p"/"}>
|
|
||||||
<input type="url" name="forum_path" />
|
<.simple_form for={@conn.params} action={~p"/"} phx-submit="save">
|
||||||
<input type="submit" class="btn btn-sm" value="Redirect" />
|
<.input field={@conn.params[:forum_path]} name="forum_path" value="" label="SA Url" />
|
||||||
</.form>
|
<:actions>
|
||||||
|
<.button class="btn btn-sm">Redirect</.button>
|
||||||
|
</:actions>
|
||||||
|
</.simple_form>
|
||||||
|
|
||||||
<pre class="whitespace-pre-wrap w-full overflow-x-auto pb-8">
|
<pre class="whitespace-pre-wrap w-full overflow-x-auto pb-8">
|
||||||
<%= inspect(@current_user) %>
|
<%= inspect(@current_user) %>
|
||||||
|
Reference in New Issue
Block a user