defmodule NolaWeb.UntappdController do use NolaWeb, :controller def callback(conn, %{"code" => code}) do with \ {:account, account_id} when is_binary(account_id) <- {:account, get_session(conn, :account)}, {:account, account} when not is_nil(account) <- {:account, IRC.Account.get(account_id)}, {:ok, auth_token} <- Untappd.auth_callback(code) do IRC.Account.put_meta(account, "untappd-token", auth_token) text(conn, "OK!") else {:account, _} -> text(conn, "Error: account not found") :error -> text(conn, "Error: untappd authentication failed") end end end