Browse Source

clean up navigation, hide register when a user exists

main
Inhji Y. 10 months ago
parent
commit
f715829730
  1. 11
      lib/mirage/accounts.ex
  2. 34
      lib/mirage_web/templates/layout/_header.html.eex
  3. 6
      lib/mirage_web/templates/layout/_user_menu.html.eex

11
lib/mirage/accounts.ex

@ -59,6 +59,17 @@ defmodule Mirage.Accounts do
"""
def get_user!(id), do: Repo.get!(User, id)
@doc """
Returns true if a user has been created, false otherwise.
## Examples
iex> has_user?()
true
"""
def has_user?(), do: Repo.all(User) |> Enum.empty?() |> Kernel.not()
## User registration
@doc """

34
lib/mirage_web/templates/layout/_header.html.eex

@ -1,22 +1,16 @@
<header>
<section class="container">
<nav role="navigation">
<div>
<ul>
<li>
<a href="/">Home</a>
</li>
<li>
<a href="/notes">Notes</a>
</li>
<li>
<a href="/wiki">Wiki</a>
</li>
</ul>
</div>
<div>
<%= render "_user_menu.html", assigns %>
</div>
</nav>
</section>
<nav role="navigation">
<ul>
<li>
<a href="/">१ Home</a>
</li>
<li>
<a href="/notes">२ Notes</a>
</li>
<li>
<a href="/wiki">३ Wiki</a>
</li>
<%= render "_user_menu.html", assigns %>
</ul>
</nav>
</header>

6
lib/mirage_web/templates/layout/_user_menu.html.eex

@ -1,10 +1,10 @@
<ul>
<%= if @current_user do %>
<li><%= link @current_user.email, to: Routes.user_settings_path(@conn, :edit) %></li>
<li><%= link "Settings", to: Routes.setting_path(@conn, :index) %></li>
<li><%= link "Log out", to: Routes.user_session_path(@conn, :delete), method: :delete %></li>
<% else %>
<%= if not Mirage.Accounts.has_user? do %>
<li><%= link "Register", to: Routes.user_registration_path(@conn, :new) %></li>
<% end %>
<li><%= link "Log in", to: Routes.user_session_path(@conn, :new) %></li>
<% end %>
</ul>
<% end %>
Loading…
Cancel
Save