-
-
Save shankardevy/15126fee0cdc0c2e451735334c708035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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