summaryrefslogtreecommitdiff
path: root/lib/nola_web/controllers/untappd_controller.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nola_web/controllers/untappd_controller.ex')
-rw-r--r--lib/nola_web/controllers/untappd_controller.ex18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/nola_web/controllers/untappd_controller.ex b/lib/nola_web/controllers/untappd_controller.ex
new file mode 100644
index 0000000..d3a540d
--- /dev/null
+++ b/lib/nola_web/controllers/untappd_controller.ex
@@ -0,0 +1,18 @@
+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