Skip to content

Instantly share code, notes, and snippets.

@rawkode
Last active September 6, 2017 01:53
Show Gist options
  • Save rawkode/466c324ace06bc91acd758d948442630 to your computer and use it in GitHub Desktop.
Save rawkode/466c324ace06bc91acd758d948442630 to your computer and use it in GitHub Desktop.
Elixir is Awesome
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