mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-11 17:42:48 +00:00
server/client - eu support for fetching characters
This commit is contained in:
@@ -8,7 +8,7 @@ defmodule MyAppWeb.PageController do
|
||||
# cache index.html if prod
|
||||
file = case System.get_env("MIX_ENV") do
|
||||
:prod ->
|
||||
file = Cachex.get(:myapp, "index.html")
|
||||
Cachex.get(:myapp, "index.html")
|
||||
|> get_file
|
||||
_ -> File.read!(Application.app_dir(:myapp, "priv/static/index.html"))
|
||||
end
|
||||
|
||||
@@ -34,22 +34,6 @@ defmodule MyAppWeb.ThreadController do
|
||||
|> Response.json(output)
|
||||
end
|
||||
|
||||
@spec update(map, map) :: any
|
||||
def update(conn, params) do
|
||||
user_id = conn
|
||||
|> MyApp.Guardian.Plug.current_claims
|
||||
|> Map.get("id")
|
||||
|
||||
{output, status} = params
|
||||
|> Map.put("user_id", user_id)
|
||||
|> Data.Thread.user_update
|
||||
|> Response.put_resp
|
||||
|
||||
conn
|
||||
|> put_status(status)
|
||||
|> Response.json(output)
|
||||
end
|
||||
|
||||
@spec get_collection(map, map) :: any
|
||||
def get_collection(conn, params) do
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@ defmodule MyAppWeb.UserController do
|
||||
alias MyApp.Data
|
||||
alias MyApp.Guardian.Auth
|
||||
|
||||
# https://us.battle.net/oauth/authorize?redirect_uri=https://localhost/api/battlenet/authorize&scope=wow.profile&client_id=vxqv32fddxsy6cmk6259amtymbuzmfrq&response_type=code
|
||||
|
||||
# this is for auth with username/password - currently only for admin
|
||||
def login(conn, params) do
|
||||
{output, status} = params
|
||||
@@ -25,7 +23,11 @@ defmodule MyAppWeb.UserController do
|
||||
|
||||
{output, status} = code
|
||||
|> BattleNet.Auth.get_access_token
|
||||
|> BattleNet.User.get_user
|
||||
# TODO: support for other regions maybe?
|
||||
# right now a US user can auth with the EU end point
|
||||
# maybe it works vice versa? Unable to test it out
|
||||
# because I don't have a test eu account
|
||||
|> BattleNet.User.get_user("us")
|
||||
|> Data.User.upsert_user
|
||||
|> Auth.Token.add_token_and_map_claims
|
||||
|> Response.put_resp
|
||||
@@ -35,13 +37,15 @@ defmodule MyAppWeb.UserController do
|
||||
|>Response.json(output)
|
||||
end
|
||||
|
||||
def characters(conn, _params) do
|
||||
def characters(conn, params) do
|
||||
region = Map.get(params, "region")
|
||||
|
||||
%{"access_token" => token, "id" => user_id} = conn
|
||||
|> MyApp.Guardian.Plug.current_claims
|
||||
|> Map.take(["access_token", "id"])
|
||||
|
||||
{output, status} = user_id
|
||||
|> BattleNet.User.get_user_characters(token)
|
||||
|> BattleNet.User.get_user_characters(token, region)
|
||||
|> Response.put_resp
|
||||
|
||||
conn
|
||||
@@ -55,7 +59,7 @@ defmodule MyAppWeb.UserController do
|
||||
|> Map.take(["id", "access_token"])
|
||||
|
||||
# validate the character exists in users WoW profile
|
||||
{:ok, characterList} = BattleNet.User.get_user_characters(user_id, access_token)
|
||||
{:ok, characterList} = BattleNet.User.get_user_characters(user_id, access_token, params["region"])
|
||||
exists = Enum.find(characterList["characters"], fn(char) ->
|
||||
char["name"] == params["character_name"] && char["realm"] == params["character_realm"]
|
||||
end)
|
||||
|
||||
@@ -38,7 +38,6 @@ defmodule MyAppWeb.Router do
|
||||
# authenticated routes
|
||||
pipe_through [:user_auth]
|
||||
post "/", ThreadController, :insert
|
||||
put "/", ThreadController, :update
|
||||
|
||||
pipe_through [:mod_auth]
|
||||
put "/mod", ThreadController, :mod_update
|
||||
|
||||
Reference in New Issue
Block a user