|
@@ -1,10 +1,11 @@
|
|
defmodule FourlettersWeb.FourlettersController do
|
|
defmodule FourlettersWeb.FourlettersController do
|
|
use FourlettersWeb, :controller
|
|
use FourlettersWeb, :controller
|
|
|
|
+ require Logger
|
|
# import Fourletters.Troll
|
|
# import Fourletters.Troll
|
|
# import ABCD.Fourletters
|
|
# import ABCD.Fourletters
|
|
|
|
|
|
def fourletters(conn, %{"fourletters" => fourletters}) do
|
|
def fourletters(conn, %{"fourletters" => fourletters}) do
|
|
- if String.length(fourletters) == 4 do
|
|
|
|
|
|
+ if String.length(fourletters) == 4 and fourletters =~ ~r(^[a-z!]*$) do
|
|
|
|
|
|
pid = case Supervisor.start_child(
|
|
pid = case Supervisor.start_child(
|
|
Fourletters.Troll,
|
|
Fourletters.Troll,
|
|
@@ -20,7 +21,7 @@ defmodule FourlettersWeb.FourlettersController do
|
|
end
|
|
end
|
|
|
|
|
|
def getmessages(conn, %{"fourletters" => fourletters}) do
|
|
def getmessages(conn, %{"fourletters" => fourletters}) do
|
|
- if String.length(fourletters) == 4 do
|
|
|
|
|
|
+ if String.length(fourletters) == 4 and fourletters =~ ~r(^[a-z!]*$) do
|
|
|
|
|
|
pid = case Supervisor.start_child(
|
|
pid = case Supervisor.start_child(
|
|
Fourletters.Troll,
|
|
Fourletters.Troll,
|
|
@@ -38,8 +39,9 @@ defmodule FourlettersWeb.FourlettersController do
|
|
def addletters(conn, _params) do
|
|
def addletters(conn, _params) do
|
|
%{params: params} = conn
|
|
%{params: params} = conn
|
|
%{"fourletters" => fourletters, "message" => message} = params
|
|
%{"fourletters" => fourletters, "message" => message} = params
|
|
- if String.length(fourletters) == 4 and String.length(message) < 101 do
|
|
|
|
|
|
+ if String.length(fourletters) == 4 and String.length(message) < 101 and fourletters =~ ~r(^[a-z!]*$) do
|
|
|
|
|
|
|
|
+ Logger.info params
|
|
pid = case Supervisor.start_child(
|
|
pid = case Supervisor.start_child(
|
|
Fourletters.Troll,
|
|
Fourletters.Troll,
|
|
%{id: String.to_atom(fourletters), start: {ABCD.Fourletters, :start_link, [[]]}}) do
|
|
%{id: String.to_atom(fourletters), start: {ABCD.Fourletters, :start_link, [[]]}}) do
|
|
@@ -62,8 +64,11 @@ defmodule FourlettersWeb.FourlettersController do
|
|
def apiaddletters(conn, _params) do
|
|
def apiaddletters(conn, _params) do
|
|
%{params: params} = conn
|
|
%{params: params} = conn
|
|
%{"fourletters" => fourletters, "message" => message} = params
|
|
%{"fourletters" => fourletters, "message" => message} = params
|
|
- if String.length(fourletters) == 4 and String.length(message) < 101 do
|
|
|
|
|
|
+ if String.length(fourletters) == 4 and fourletters =~ ~r(^[a-z!]*$) and String.length(message) < 101 do
|
|
|
|
|
|
|
|
+ Logger.info fn ->
|
|
|
|
+ "#{DateTime.utc_now} #{inspect(params)}"
|
|
|
|
+ end
|
|
pid = case Supervisor.start_child(
|
|
pid = case Supervisor.start_child(
|
|
Fourletters.Troll,
|
|
Fourletters.Troll,
|
|
%{id: String.to_atom(fourletters), start: {ABCD.Fourletters, :start_link, [[]]}}) do
|
|
%{id: String.to_atom(fourletters), start: {ABCD.Fourletters, :start_link, [[]]}}) do
|
|
@@ -87,7 +92,7 @@ defmodule FourlettersWeb.FourlettersController do
|
|
def apiclearletters(conn, _params) do
|
|
def apiclearletters(conn, _params) do
|
|
%{params: params} = conn
|
|
%{params: params} = conn
|
|
%{"fourletters" => fourletters} = params
|
|
%{"fourletters" => fourletters} = params
|
|
- if String.length(fourletters) == 4 do
|
|
|
|
|
|
+ if String.length(fourletters) == 4 and fourletters =~ ~r(^[a-z!]*$) do
|
|
pid = case Supervisor.start_child(
|
|
pid = case Supervisor.start_child(
|
|
Fourletters.Troll,
|
|
Fourletters.Troll,
|
|
%{id: String.to_atom(fourletters), start: {ABCD.Fourletters, :start_link, [[]]}}) do
|
|
%{id: String.to_atom(fourletters), start: {ABCD.Fourletters, :start_link, [[]]}}) do
|
|
@@ -95,19 +100,19 @@ defmodule FourlettersWeb.FourlettersController do
|
|
{:error, {:already_started, pid}} -> pid
|
|
{:error, {:already_started, pid}} -> pid
|
|
end
|
|
end
|
|
ABCD.Fourletters.clear(pid)
|
|
ABCD.Fourletters.clear(pid)
|
|
- conn
|
|
|
|
- |> put_status(:ok)
|
|
|
|
- |> json(%{fourletters: fourletters, clear: true})
|
|
|
|
- |> redirect(to: "/#{fourletters}")
|
|
|
|
|
|
+ # conn
|
|
|
|
+ # |> put_status(:ok)
|
|
|
|
+ # |> json(%{fourletters: fourletters, clear: true})
|
|
|
|
+ # |> redirect(to: "/#{fourletters}")
|
|
# redirect(conn, to: "/redirect_test")
|
|
# redirect(conn, to: "/redirect_test")
|
|
- # redirect(conn, to: "/#{fourletters}")
|
|
|
|
|
|
+ redirect(conn, to: "/#{fourletters}")
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
def clearletters(conn, _params) do
|
|
def clearletters(conn, _params) do
|
|
%{params: params} = conn
|
|
%{params: params} = conn
|
|
%{"fourletters" => fourletters} = params
|
|
%{"fourletters" => fourletters} = params
|
|
- if String.length(fourletters) == 4 do
|
|
|
|
|
|
+ if String.length(fourletters) == 4 and fourletters =~ ~r(^[a-z!]*$) do
|
|
pid = case Supervisor.start_child(
|
|
pid = case Supervisor.start_child(
|
|
Fourletters.Troll,
|
|
Fourletters.Troll,
|
|
%{id: String.to_atom(fourletters), start: {ABCD.Fourletters, :start_link, [[]]}}) do
|
|
%{id: String.to_atom(fourletters), start: {ABCD.Fourletters, :start_link, [[]]}}) do
|
|
@@ -123,7 +128,7 @@ defmodule FourlettersWeb.FourlettersController do
|
|
end
|
|
end
|
|
|
|
|
|
def nothing(conn, %{"fourletters" => fourletters}) do
|
|
def nothing(conn, %{"fourletters" => fourletters}) do
|
|
- if String.length(fourletters) == 4 do
|
|
|
|
|
|
+ if String.length(fourletters) == 4 and fourletters =~ ~r(^[a-z!]*$) do
|
|
redirect(conn, to: "/#{fourletters}")
|
|
redirect(conn, to: "/#{fourletters}")
|
|
else
|
|
else
|
|
render(conn, "nothing.html")
|
|
render(conn, "nothing.html")
|