From b3ac9003db0bb56c0247fc40d383ec66ea312454 Mon Sep 17 00:00:00 2001 From: Mitchell Date: Sun, 28 Jan 2018 14:09:08 -0600 Subject: [PATCH] client/server - update message - update authentication --- client/app/pages/home/home.tsx | 8 ++++---- client/app/scss/style.scss | 2 +- lib/myapp/auth/token.ex | 7 +++++-- lib/myapp/data/user.ex | 2 +- test/myapp/data/user_test.exs | 2 ++ test/myapp_web/controllers/reply_controller_test.exs | 2 +- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/client/app/pages/home/home.tsx b/client/app/pages/home/home.tsx index 130c853..1b66627 100644 --- a/client/app/pages/home/home.tsx +++ b/client/app/pages/home/home.tsx @@ -6,7 +6,6 @@ import './home.scss'; import header_forms from '../../assets/header-forums.gif'; import support from '../../assets/support.gif'; -// import serverstatus from '../../assets/serverstatus.gif'; import uicustomizations from '../../assets/uicustomizations.gif'; import bugs from '../../assets/bugs.gif'; import realms from '../../assets/realms.gif'; @@ -94,9 +93,10 @@ export class Home extends React.Component { Welcome to the unofficial Classic WoW Forums!

- This site is made with the intention of providing a web forum - that replicates the World of Warcraft forums as they were - back in 2005. + I created this site with the intention of providing + a fully functional and accurate representation of + the World of Warcraft forums as they were + back in 2005. Please read this first!

diff --git a/client/app/scss/style.scss b/client/app/scss/style.scss index 3c12cf3..78bc1de 100644 --- a/client/app/scss/style.scss +++ b/client/app/scss/style.scss @@ -172,7 +172,7 @@ div { } .blue-post { - p { + p, li, { color: $bluePost; } } diff --git a/lib/myapp/auth/token.ex b/lib/myapp/auth/token.ex index 7e843b3..d81df26 100644 --- a/lib/myapp/auth/token.ex +++ b/lib/myapp/auth/token.ex @@ -1,15 +1,18 @@ defmodule MyApp.Guardian.Auth.Token do alias MyApp.Guardian + # one month in seconds + defp one_month(), do: 2592000 + @spec add_token_and_map_claims(map | {atom, any}) :: {:ok, map} | {:error, String.t} def add_token_and_map_claims(user) when is_map(user) do claims = user - |> Map.take([:id, :battletag, :battle_net_id, "access_token"]) # take values from user object to map to claims + |> Map.take([:id, :battletag, :battle_net_id, :access_token]) # take values from user object to map to claims |> Guardian.add_permissions(get_permissions(user)) # set token expiration to the same as the battlenet token - case Guardian.encode_and_sign(user, claims, ttl: {user["expires_in"], :seconds}) do + case Guardian.encode_and_sign(user, claims, ttl: {Map.get(user, :expires_in) || one_month(), :seconds}) do {:ok, token, _claims} -> {:ok, Map.merge(user, %{token: token})} {:error, error} -> {:error, error} end diff --git a/lib/myapp/data/user.ex b/lib/myapp/data/user.ex index 6cb929f..f8d67ef 100644 --- a/lib/myapp/data/user.ex +++ b/lib/myapp/data/user.ex @@ -82,7 +82,7 @@ defmodule MyApp.Data.User do # need to add token back to map because we don't store it in the database defp add_extra_params({:error, error}, _), do: {:error, error} defp add_extra_params({:ok, user}, params) do - {:ok, Map.merge(user, params)} + {:ok, Map.merge(user, %{access_token: params["access_token"], expires_in: params["expires_in"]})} end defp insert_battlenet_user(params) do diff --git a/test/myapp/data/user_test.exs b/test/myapp/data/user_test.exs index 2639195..36b3697 100644 --- a/test/myapp/data/user_test.exs +++ b/test/myapp/data/user_test.exs @@ -28,6 +28,7 @@ defmodule MyApp.Data.UserTest do battletag: "mgerb", id: user.id, permissions: "user", + expires_in: nil, } # call upsert again with same battletag @@ -41,6 +42,7 @@ defmodule MyApp.Data.UserTest do battletag: "mgerb", id: user.id, permissions: "user", + expires_in: nil, character_avatar: nil, character_class: nil, character_guild: nil, diff --git a/test/myapp_web/controllers/reply_controller_test.exs b/test/myapp_web/controllers/reply_controller_test.exs index 0a55bc5..19a3bf7 100644 --- a/test/myapp_web/controllers/reply_controller_test.exs +++ b/test/myapp_web/controllers/reply_controller_test.exs @@ -63,7 +63,7 @@ defmodule MyAppWeb.ReplyControllerTest do # new reply should work conn = post(new_conn, "/api/reply", %{"content" => "c", "thread_id" => thread_id}) - body = conn |> response(200) |> Poison.decode! + conn |> response(200) |> Poison.decode! end test "user update reply" do