Skip to content

Instantly share code, notes, and snippets.

@shankardevy

shankardevy/session_controller.ex Secret

Last active Aug 18, 2017
Embed
What would you like to do?
defmodule MangoWeb.SessionController do
use MangoWeb, :controller
alias Mango.CRM
def new(conn, _params) do
render(conn, "new.html")
end
def create(conn, %{"session" => session_params}) do
case CRM.get_customer_by_credentials(session_params) do
:error ->
conn
|> put_flash(:error, "Invalid username/password combination")
|> render("new.html")
customer ->
conn
|> assign(:current_customer, customer)
|> put_session(:customer_id, customer.id)
|> configure_session(renew: true)
|> put_flash(:info, "Login successful")
|> redirect(to: page_path(conn, :index))
end
end
# Add new delete action as shown below:
def delete(conn, _) do
clear_session(conn)
|> put_flash(:info, "You have been logged out")
|> redirect(to: page_path(conn, :index))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment