Created
June 8, 2021 12:44
-
-
Save TeijiW/d07473df76e5111b35841463da660cf5 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 ProjectWeb.UserSessionLive do | |
use ProjectWeb, :live_view | |
alias Project.Accounts | |
def mount(_params, _session, socket) do | |
{:ok, | |
assign(socket, | |
email_input_error: nil, | |
email: nil | |
)} | |
end | |
def handle_event("login", %{"user" => %{"email" => email}}, socket) do | |
Accounts.get_user_by_email(email) | |
|> handle_login_response(socket) | |
end | |
defp handle_login_response(%Accounts.User{} = user, socket)do | |
Accounts.send_access_code(user.email) | |
{:noreply, assign(socket, %{email: user.email, email_input_error: nil})} | |
end | |
defp handle_login_response(_user, socket), | |
do: {:noreply, assign(socket, :email_input_error, "E-mail not found")} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment