diff --git a/lib/postland.ex b/lib/postland.ex index d859635..4815dd2 100644 --- a/lib/postland.ex +++ b/lib/postland.ex @@ -9,6 +9,25 @@ defmodule Postland do alias Postland.Accounts + def temporary_password() do + :crypto.strong_rand_bytes(12) |> Base.encode64() + end + + def on_boot_setup() do + if !setup?() do + attrs = %{ + username: "welcome", + password: temporary_password() + } + + {:ok, _user} = Accounts.register_user(attrs) + + IO.puts( + "Your temporary username is #{attrs.username} and your temporary password is #{attrs.password}" + ) + end + end + def setup?() do Accounts.solo_user() != nil end diff --git a/lib/postland/application.ex b/lib/postland/application.ex index 651cff3..bc98395 100644 --- a/lib/postland/application.ex +++ b/lib/postland/application.ex @@ -17,7 +17,8 @@ defmodule Postland.Application do # Start a worker by calling: Postland.Worker.start_link(arg) # {Postland.Worker, arg}, # Start to serve requests, typically the last entry - PostlandWeb.Endpoint + PostlandWeb.Endpoint, + Postland.Setup ] # See https://hexdocs.pm/elixir/Supervisor.html diff --git a/lib/postland/setup.ex b/lib/postland/setup.ex new file mode 100644 index 0000000..38de804 --- /dev/null +++ b/lib/postland/setup.ex @@ -0,0 +1,16 @@ +defmodule Postland.Setup do + use GenServer + @compile_env Mix.env() + + def start_link(opts) do + GenServer.start_link(__MODULE__, opts, name: __MODULE__) + end + + def init(_opts) do + if @compile_env != :test do + Postland.on_boot_setup() + end + + {:ok, %{}} + end +end diff --git a/lib/postland_web/components/layouts/app.html.heex b/lib/postland_web/components/layouts/app.html.heex index e23bfc8..fec9a04 100644 --- a/lib/postland_web/components/layouts/app.html.heex +++ b/lib/postland_web/components/layouts/app.html.heex @@ -1,29 +1,3 @@ -
-
-
- - - -

- v<%= Application.spec(:phoenix, :vsn) %> -

-
- -
-
<.flash_group flash={@flash} /> diff --git a/lib/postland_web/components/layouts/root.html.heex b/lib/postland_web/components/layouts/root.html.heex index 81b9f99..8d2d1a6 100644 --- a/lib/postland_web/components/layouts/root.html.heex +++ b/lib/postland_web/components/layouts/root.html.heex @@ -12,47 +12,52 @@ - +
+
+ Postland +
+
    + <%= if @current_user do %> +
  • + <%= @current_user.username %> +
  • +
  • + <.link + href={~p"/users/settings"} + class="text-[0.8125rem] leading-6 font-semibold hover:text-purple-300" + > + Settings + +
  • +
  • + <.link + href={~p"/users/log_out"} + method="delete" + class="text-[0.8125rem] leading-6 font-semibold hover:text-purple-300" + > + Log out + +
  • + <% else %> +
  • + <.link + href={~p"/users/register"} + class="text-[0.8125rem] leading-6 font-semibold hover:text-purple-300" + > + Register + +
  • +
  • + <.link + href={~p"/users/log_in"} + class="text-[0.8125rem] leading-6 font-semibold hover:text-purple-300" + > + Log in + +
  • + <% end %> +
+
<%= @inner_content %> diff --git a/lib/postland_web/controllers/page_html/home.html.heex b/lib/postland_web/controllers/page_html/home.html.heex index dc1820b..e69de29 100644 --- a/lib/postland_web/controllers/page_html/home.html.heex +++ b/lib/postland_web/controllers/page_html/home.html.heex @@ -1,222 +0,0 @@ -<.flash_group flash={@flash} /> - -
-
- -

- Phoenix Framework - - v<%= Application.spec(:phoenix, :vsn) %> - -

-

- Peace of mind from prototype to production. -

-

- Build rich, interactive web applications quickly, with less code and fewer moving parts. Join our growing community of developers using Phoenix to craft APIs, HTML5 apps and more, for fun or at scale. -

- -
-
diff --git a/lib/postland_web/controllers/user_session_controller.ex b/lib/postland_web/controllers/user_session_controller.ex index e870663..8bf9b2b 100644 --- a/lib/postland_web/controllers/user_session_controller.ex +++ b/lib/postland_web/controllers/user_session_controller.ex @@ -14,6 +14,12 @@ defmodule PostlandWeb.UserSessionController do |> create(params, "Password updated successfully!") end + def create(conn, %{"user" => %{"username" => "welcome"}} = params) do + conn + |> put_session(:user_return_to, ~p"/users/settings") + |> create(params, "Welcome! You can change your username and password now.") + end + def create(conn, params) do create(conn, params, "Welcome back!") end