Created
June 8, 2021 12:52
-
-
Save TeijiW/4cf271c66c8d79ed29df3dc24d75461f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ProjectWeb.UserSessionController do | |
use ProjectWeb, :controller | |
alias Project.Accounts | |
alias ProjectWeb.UserAuth | |
def create( | |
conn, | |
%{ | |
"user" => %{"email" => email, "code" => code} = user_params | |
} | |
) do | |
if user = Accounts.verify_code_and_email(email, code) do | |
conn | |
|> put_session( | |
:user_return_to, | |
"/home" | |
) | |
|> UserAuth.log_in_user(user, user_params) | |
else | |
conn | |
|> put_flash(:error, "Invalid credentials") | |
|> redirect(to: "/login") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment