summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/chessh/schema/player.ex10
-rw-r--r--lib/chessh/web/web.ex12
2 files changed, 11 insertions, 11 deletions
diff --git a/lib/chessh/schema/player.ex b/lib/chessh/schema/player.ex
index d5bcab2..19142e9 100644
--- a/lib/chessh/schema/player.ex
+++ b/lib/chessh/schema/player.ex
@@ -43,6 +43,12 @@ defmodule Chessh.Player do
|> validate_discord_id()
end
+ def username_changeset(player, attrs) do
+ player
+ |> cast(attrs, [:username])
+ |> validate_username()
+ end
+
def registration_changeset(player, attrs, opts \\ []) do
player
|> cast(attrs, [:username, :password, :discord_id])
@@ -85,7 +91,9 @@ defmodule Chessh.Player do
changeset
|> validate_required([:username])
|> validate_length(:username, min: 2, max: 40)
- |> validate_format(:username, ~r/^.{3,32}#[0-9]{4}$/, message: "must match discord tag format")
+ |> validate_format(:username, ~r/^.{3,32}(#[0-9]{4})?$/,
+ message: "must match discord tag format"
+ )
|> unique_constraint(:username)
end
diff --git a/lib/chessh/web/web.ex b/lib/chessh/web/web.ex
index 5835ff2..d5e2be5 100644
--- a/lib/chessh/web/web.ex
+++ b/lib/chessh/web/web.ex
@@ -26,13 +26,6 @@ defmodule Chessh.Web.Endpoint do
redirect_uri
] = get_discord_configs()
- Logger.warn(
- inspect(
- {String.to_charlist(discord_login_url), [], ~c"application/x-www-form-urlencoded",
- ~c"scope=#{discord_scope}&client_id=#{client_id}&client_secret=#{client_secret}&code=#{req_token}&grant_type=authorization_code&redirect_uri=#{redirect_uri}"}
- )
- )
-
resp =
case conn.params do
%{"code" => req_token} ->
@@ -473,7 +466,7 @@ defmodule Chessh.Web.Endpoint do
[]
) do
{:ok, {{_, 200, ~c"OK"}, _, user_details}} ->
- %{"username" => username, "discriminator" => discriminator, "id" => discord_id} =
+ %{"username" => username, "id" => discord_id} =
Jason.decode!(String.Chars.to_string(user_details))
case Repo.get_by(Player, discord_id: discord_id) do
@@ -481,8 +474,7 @@ defmodule Chessh.Web.Endpoint do
player -> player
end
|> Player.discord_changeset(%{
- username: username <> "#" <> discriminator,
- discord_id: discord_id
+ username: username
})
|> Repo.insert_or_update()