-
-
Save shankardevy/cf79b1bafbdacc220525d598d1cfee6a 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 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment