Send real ip address to telegram.
This commit is contained in:
parent
377bf5b2de
commit
76bf23d5e6
2 changed files with 4 additions and 3 deletions
|
@ -10,8 +10,8 @@ defmodule UiWeb.PageController do
|
||||||
render(conn, :instructions)
|
render(conn, :instructions)
|
||||||
end
|
end
|
||||||
|
|
||||||
def morse(%{remote_ip: ip} = conn, _params) do
|
def morse(conn, _params) do
|
||||||
ip = ip |> Tuple.to_list |> Enum.join(".")
|
ip = conn |> Plug.Conn.get_req_header("x-real-ip") |> hd()
|
||||||
LiveView.Controller.live_render(conn, UiWeb.MorseLive, session: %{ip: ip})
|
LiveView.Controller.live_render(conn, UiWeb.MorseLive, session: %{ip: ip})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,9 +13,10 @@ defmodule UiWeb.MorseLive do
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_event("toggle_morse", _value, %{assigns: %{ip: ip}} = socket) do
|
def handle_event("toggle_morse", _value, %{assigns: %{ip: ip}} = socket) do
|
||||||
if Morse.Server.in_progress?() and ip != "127.0.0.1" do
|
if not Morse.Server.in_progress?() and ip != "127.0.0.1" do
|
||||||
spawn fn -> Ui.TelegramBot.message("#{ip} pressed the button!") end
|
spawn fn -> Ui.TelegramBot.message("#{ip} pressed the button!") end
|
||||||
end
|
end
|
||||||
|
|
||||||
Morse.Server.toggle_morse()
|
Morse.Server.toggle_morse()
|
||||||
|
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
|
|
Loading…
Reference in a new issue