Add logging out

This commit is contained in:
Shadowfacts 2019-04-01 11:34:26 -04:00
parent 16884dffef
commit 7230b52563
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 15 additions and 4 deletions

View File

@ -96,7 +96,7 @@ defmodule FrenzyWeb.AccountController do
approved_client = Enum.find(user.approved_clients, fn c -> c.client_id == client_id end) approved_client = Enum.find(user.approved_clients, fn c -> c.client_id == client_id end)
if not is_nil(approved_client) do unless is_nil(approved_client) do
{:ok, _} = Repo.delete(approved_client) {:ok, _} = Repo.delete(approved_client)
end end

View File

@ -11,8 +11,6 @@ defmodule FrenzyWeb.LoginController do
}) })
end end
@error_message "Invalid username or password"
def login_post(conn, %{"username" => username, "password" => password} = params) do def login_post(conn, %{"username" => username, "password" => password} = params) do
user = Repo.get_by(User, username: username) user = Repo.get_by(User, username: username)
@ -26,8 +24,15 @@ defmodule FrenzyWeb.LoginController do
{:error, _reason} -> {:error, _reason} ->
conn conn
|> put_flash(:error, @error_message) |> put_flash(:error, "Invalid username or password.")
|> redirect(to: Routes.login_path(Endpoint, :login)) |> redirect(to: Routes.login_path(Endpoint, :login))
end end
end end
def logout(conn, params) do
conn
|> put_flash(:info, "Logged out.")
|> clear_session()
|> redirect(to: "/")
end
end end

View File

@ -27,6 +27,8 @@ defmodule FrenzyWeb.Router do
get "/login", LoginController, :login get "/login", LoginController, :login
post "/login", LoginController, :login_post post "/login", LoginController, :login_post
get "/logout", LoginController, :logout
get "/oauth/authorize", Fervor.OauthController, :authorize_get get "/oauth/authorize", Fervor.OauthController, :authorize_get
post "/oauth/authorize", Fervor.OauthController, :authorize_post post "/oauth/authorize", Fervor.OauthController, :authorize_post
end end

View File

@ -13,6 +13,10 @@
<nav role="navigation"> <nav role="navigation">
<ul> <ul>
<li><a href="/">Frenzy</a></li> <li><a href="/">Frenzy</a></li>
<%= unless is_nil(@conn.assigns[:user]) do %>
<li><a href="<%= Routes.account_path(@conn, :show) %>">Account</a></li>
<li><a href="<%= Routes.login_path(@conn, :logout) %>">Log Out</a></li>
<% end %>
</ul> </ul>
</nav> </nav>
</section> </section>