Last active
September 6, 2017 01:53
-
-
Save rawkode/466c324ace06bc91acd758d948442630 to your computer and use it in GitHub Desktop.
Elixir is Awesome
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 UserService.Http.Endpoints.Login do | |
@moduledoc """ | |
<Purged for Gist> | |
""" | |
use Plug.Builder | |
use Eidetic.CommandBus, command: UserService.User.Commands.Login | |
alias UserService.User | |
def index(connection) do | |
%{"email" => email, "password" => password} = connection.body_params | |
message = case run_command(email, password) do | |
{:logged_in, user = %User{}, jwt} | |
-> %{success: :true, jwt: jwt} | |
error when error in [ | |
:user_not_found, | |
:user_email_not_verified, | |
:user_authentication_failed | |
] | |
-> %{success: :false, message: error} | |
_ | |
-> %{success: :false, message: "Exceptional Error. No idea what happened :smile:" | |
end | |
send_resp(connection, 200, message) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment