Skip to content

Commit

Permalink
Merge pull request #53 from danschultzer/binary-id
Browse files Browse the repository at this point in the history
Fix binary id docs and support
  • Loading branch information
danschultzer committed Apr 9, 2019
2 parents 48fc171 + 2feed19 commit 96e333e
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Plug and Phoenix controller now handles `:session_params` rather than `:state` for any params that needs to be stored temporarily during authorization
* Added handling of `oauth_token_secret` to OAuth strategies
* Support any `:plug` version below `2.0.0`
* Fixed bug in `mix pow_assent.ecto.gen.migration` task where `--binary-id` flag didn't generate correct migration
* Support `:pow` version `1.0.5`

## v0.2.2 (2019-03-25)

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Run `mix deps.get` to install it.

It's required to set up [Pow](https://github.com/danschultzer/pow#getting-started-phoenix) first. You can [run these quick setup](guides/POW.md) instructions if Pow hasn't already been set up.

If your user schema uses binary id, then run the PowAssent mix task(s) with the `--binary-id` flag.

### Set up PowAssent

Install the necessary files:
Expand Down
12 changes: 6 additions & 6 deletions lib/pow_assent/phoenix/controllers/authorization_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ defmodule PowAssent.Phoenix.AuthorizationController do
conn
{:ok, _user, conn} ->
conn
|> put_flash(:info, messages(conn).user_has_been_created(conn))
|> put_flash(:info, extension_messages(conn).user_has_been_created(conn))
|> redirect(to: routes(conn).after_registration_path(conn))
end
end
Expand All @@ -108,13 +108,13 @@ defmodule PowAssent.Phoenix.AuthorizationController do
conn
{:ok, conn} ->
conn
|> put_flash(:info, messages(conn).signed_in(conn))
|> put_flash(:info, extension_messages(conn).signed_in(conn))
|> redirect(to: routes(conn).after_sign_in_path(conn))
end
end
def respond_callback({:error, {:bound_to_different_user, _changeset}, conn}) do
conn
|> put_flash(:error, messages(conn).account_already_bound_to_other_user(conn))
|> put_flash(:error, extension_messages(conn).account_already_bound_to_other_user(conn))
|> redirect(to: routes(conn).session_path(conn, :new))
end
def respond_callback({:error, {:invalid_user_id_field, _changeset}, %{params: %{"provider" => provider}, private: %{pow_assent_params: params}} = conn}) do
Expand All @@ -126,7 +126,7 @@ defmodule PowAssent.Phoenix.AuthorizationController do
do: respond_callback({:error, conn})
def respond_callback({:error, conn}) do
conn
|> put_flash(:error, messages(conn).could_not_sign_in(conn))
|> put_flash(:error, extension_messages(conn).could_not_sign_in(conn))
|> redirect(to: routes(conn).session_path(conn, :new))
end

Expand All @@ -145,12 +145,12 @@ defmodule PowAssent.Phoenix.AuthorizationController do
@spec respond_delete({:ok, map(), Conn.t()}) :: Conn.t()
def respond_delete({:ok, _deleted, conn}) do
conn
|> put_flash(:info, messages(conn).authentication_has_been_removed(conn))
|> put_flash(:info, extension_messages(conn).authentication_has_been_removed(conn))
|> redirect(to: after_delete_path(conn))
end
def respond_delete({:error, {:no_password, _changeset}, conn}) do
conn
|> put_flash(:error, messages(conn).identity_cannot_be_removed_missing_user_password(conn))
|> put_flash(:error, extension_messages(conn).identity_cannot_be_removed_missing_user_password(conn))
|> redirect(to: after_delete_path(conn))
end

Expand Down
6 changes: 3 additions & 3 deletions lib/pow_assent/phoenix/controllers/registration_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ defmodule PowAssent.Phoenix.RegistrationController do
conn
{:ok, _user, conn} ->
conn
|> put_flash(:info, messages(conn).user_has_been_created(conn))
|> put_flash(:info, extension_messages(conn).user_has_been_created(conn))
|> redirect(to: routes(conn).after_registration_path(conn))
end
end
def respond_create({:error, {:bound_to_different_user, _changeset}, conn}) do
conn
|> put_flash(:error, messages(conn).account_already_bound_to_other_user(conn))
|> put_flash(:error, extension_messages(conn).account_already_bound_to_other_user(conn))
|> redirect(to: routes(conn).registration_path(conn, :new))
end
def respond_create({:error, {:invalid_user_id_field, changeset}, conn}),
Expand All @@ -64,7 +64,7 @@ defmodule PowAssent.Phoenix.RegistrationController do

_ ->
conn
|> put_flash(:error, messages(conn).invalid_request(conn))
|> put_flash(:error, extension_messages(conn).invalid_request(conn))
|> redirect(to: routes(conn).after_sign_out_path(conn))
|> halt()
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pow_assent/phoenix/views/view_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ defmodule PowAssent.Phoenix.ViewHelpers do
defp oauth_signin_link(conn, provider), do: do_oauth_signin_link(conn, provider)

defp do_oauth_signin_link(conn, provider, query_params \\[]) do
msg = AuthorizationController.messages(conn).login_with_provider(%{conn | params: %{"provider" => provider}})
msg = AuthorizationController.extension_messages(conn).login_with_provider(%{conn | params: %{"provider" => provider}})
path = AuthorizationController.routes(conn).path_for(conn, AuthorizationController, :new, [provider], query_params)

Link.link(msg, to: path)
end

defp oauth_remove_link(conn, provider) do
msg = AuthorizationController.messages(conn).remove_provider_authentication(%{conn | params: %{"provider" => provider}})
msg = AuthorizationController.extension_messages(conn).remove_provider_authentication(%{conn | params: %{"provider" => provider}})
path = AuthorizationController.routes(conn).path_for(conn, AuthorizationController, :delete, [provider])

Link.link(msg, to: path, method: :delete)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule PowAssent.MixProject do

defp deps do
[
{:pow, "~> 1.0.4"},
{:pow, "~> 1.0.5"},

{:oauther, "~> 1.1"},

Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"plug_cowboy": {:hex, :plug_cowboy, "2.0.2", "6055f16868cc4882b24b6e1d63d2bada94fb4978413377a3b32ac16c18dffba2", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.14.1", "63247d4a5ad6b9de57a0bac5d807e1c32d41e39c04b8a4156a26c63bcd8a2e49", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"pow": {:hex, :pow, "1.0.4", "8186c3eca543b5c38511c3c684e8eec951a024a324cc7c2b07e712df8cb8c64b", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.3.0 or ~> 1.4.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, ">= 2.0.0 and <= 3.0.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:plug, ">= 1.5.0 and < 1.8.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm"},
"pow": {:hex, :pow, "1.0.5", "1f64dc1979e6ff83e76f3354968374695f7bb9826ccb2360b6b17ee88a7dd217", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.3.0 or ~> 1.4.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, ">= 2.0.0 and <= 3.0.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:plug, ">= 1.5.0 and < 2.0.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm"},
"ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"},
"telemetry": {:hex, :telemetry, "0.3.0", "099a7f3ce31e4780f971b4630a3c22ec66d22208bc090fe33a2a3a6a67754a73", [:rebar3], [], "hexpm"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.MigrationTest do

assert file =~ "defmodule #{inspect(Repo)}.Migrations.CreateUserIdentities do"
assert file =~ "create table(:user_identities)"
assert file =~ "add :user_id, references(\"users\"), on_delete: :nothing"
assert file =~ "add :user_id, references(\"users\", on_delete: :nothing)"
assert file =~ "timestamps(updated_at: false)"
end)
end
Expand Down Expand Up @@ -58,7 +58,7 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.MigrationTest do

assert file =~ "create table(:user_identities, primary_key: false)"
assert file =~ "add :id, :binary_id, primary_key: true"
assert file =~ "add :user_id, references(\"users\"), on_delete: :nothing, type: :binary_id"
assert file =~ "add :user_id, references(\"users\", on_delete: :nothing, type: :binary_id)"
end)
end
end

0 comments on commit 96e333e

Please sign in to comment.