Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## v0.5.0 (TBA)

This release contains a large refactoring changing the user identity naming to just identity.

To upgrade, please update the following:

1. In your PowAssent config change `:user_identities_context` key, if it exists, to `:identities_context`
2. In your user schema module change:
- `user_identity_changeset` method name to `identity_changeset`
- `pow_assent_user_identity_changeset` method call to `pow_assent_identity_changeset`
- `:user_identities` association name to `:identities` in the user schema module
3. In your user identity schema module:
- Change the module name from `MyApp.UserIdentities.UserIdentity` to `MyApp.Users.UserIdentity`
- Change `PowAssent.Ecto.UserIdentities.Schema` module to `PowAssent.Ecto.Identities.Schema`
- Change `pow_assent_user_identity_fields` method call to `pow_assent_identity_fields`
- Move the file from `user_identities` to `users` directory
4. In your context identity modue, if any, change:
- `PowAssent.Ecto.UserIdentities.Context` module to `PowAssent.Ecto.Identities.Context`

## v0.4.8 (2020-05-18)

### Enhancements
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mix pow_assent.install
This will add the following files to your app:

```bash
LIB_PATH/user_identities/user_identity.ex
LIB_PATH/users/user_identity.ex
PRIV_PATH/repo/migrations/TIMESTAMP_create_user_identities.ex
```

Expand Down Expand Up @@ -236,7 +236,7 @@ Add `messages_backend: MyAppWeb.Pow.Messages` to your Pow configuration. You can

## Populate fields

To populate fields in your user struct that are fetched from the provider, you can override the `user_identity_changeset/4` method to cast them:
To populate fields in your user struct that are fetched from the provider, you can override the `identity_changeset/4` method to cast them:

```elixir
defmodule MyApp.Users.User do
Expand All @@ -252,10 +252,10 @@ defmodule MyApp.Users.User do
timestamps()
end

def user_identity_changeset(user_or_changeset, user_identity, attrs, user_id_attrs) do
def identity_changeset(user_or_changeset, identity, attrs, user_id_attrs) do
user_or_changeset
|> Ecto.Changeset.cast(attrs, [:custom_field])
|> pow_assent_user_identity_changeset(user_identity, attrs, user_id_attrs)
|> pow_assent_identity_changeset(identity, attrs, user_id_attrs)
end
end
```
Expand Down Expand Up @@ -338,7 +338,7 @@ defmodule MyApp.Lib.User do
use PowAssent.Ecto.Schema

schema "users" do
has_many :user_identities,
has_many :identities,
MyApp.Lib.UserIdentity,
on_delete: :delete_all,
foreign_key: :user_id
Expand All @@ -357,7 +357,7 @@ end
Otherwise you'll get an error that reads:

```elixir
warning: invalid association `user_identities` in schema MyApp.Lib.User: associated schema MyApp.UserIdentities.UserIdentity does not exist
warning: invalid association `identities` in schema MyApp.Lib.User: associated schema MyApp.Users.UserIdentity does not exist
```

## Callback URL with HTTPS behind proxy
Expand Down
14 changes: 7 additions & 7 deletions guides/capture_access_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ end
```

```elixir
# lib/my_app/user_identities/user_identity.ex
defmodule MyApp.UserIdentities.UserIdentity do
# lib/my_app/users/user_identity.ex
defmodule MyApp.Users.UserIdentity do
use Ecto.Schema
use PowAssent.Ecto.UserIdentities.Schema,
use PowAssent.Ecto.Identities.Schema,
user: MyApp.Users.User

schema "user_identities" do
field :access_token, :string
field :refresh_token, :string

pow_assent_user_identity_fields()
pow_assent_identity_fields()

timestamps()
end

def changeset(user_identity_or_changeset, attrs) do
def changeset(identity_or_changeset, attrs) do
token_params = Map.get(attrs, "token", attrs)

user_identity_or_changeset
identity_or_changeset
|> pow_assent_changeset(attrs)
|> Ecto.Changeset.cast(token_params, [:access_token, :refresh_token])
|> Ecto.Changeset.validate_required([:access_token])
Expand All @@ -46,5 +46,5 @@ end
Now access tokens can be retrieved by loading the user identity:

```elixir
user_identity = MyApp.Repo.get_by(MyApp.UserIdentities.UserIdentity, provider: provider, user_id: user.id)
identity = MyApp.Repo.get_by(MyApp.Users.UserIdentity, provider: provider, user_id: user.id)
```
4 changes: 2 additions & 2 deletions lib/mix/pow_assent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ defmodule Mix.PowAssent do
#{msg}

mix #{task} accepts both a module name and the plural of the resource:
mix #{task} UserIdentities.UserIdentity user_identities
mix #{task} Users.UserIdentity user_identities
""")
end

defp schema_options_from_args(_opts \\ [])
defp schema_options_from_args([schema, plural | _rest]), do: %{schema_name: schema, schema_plural: plural}
defp schema_options_from_args(_any), do: %{schema_name: "UserIdentities.UserIdentity", schema_plural: "user_identities"}
defp schema_options_from_args(_any), do: %{schema_name: "Users.UserIdentity", schema_plural: "user_identities"}
end
6 changes: 3 additions & 3 deletions lib/mix/tasks/ecto/pow_assent.ecto.gen.migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Migration do
"""
use Mix.Task

alias PowAssent.Ecto.UserIdentities.Schema.Migration, as: UserIdentitiesMigration
alias PowAssent.Ecto.Identities.Schema.Migration, as: IdentitiesMigration
alias Mix.{Ecto, Pow, Pow.Ecto.Migration, PowAssent}

@switches [binary_id: :boolean, users_table: :string]
Expand Down Expand Up @@ -52,8 +52,8 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Migration do

defp create_migration_file(%{repo: repo, binary_id: binary_id, users_table: users_table, schema_plural: schema_plural}) do
context_base = Pow.app_base(Pow.otp_app())
schema = UserIdentitiesMigration.new(context_base, schema_plural, repo: repo, binary_id: binary_id, users_table: users_table)
content = UserIdentitiesMigration.gen(schema)
schema = IdentitiesMigration.new(context_base, schema_plural, repo: repo, binary_id: binary_id, users_table: users_table)
content = IdentitiesMigration.gen(schema)

Migration.create_migration_file(repo, schema.migration_name, content)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mix/tasks/ecto/pow_assent.ecto.gen.schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Schema do
mix pow_assent.ecto.gen.schema -r MyApp.Repo Accounts.Identity identities

This generator will add a schema module file in
`lib/my_app/user_identities/user_identity.ex`.
`lib/my_app/users/user_identity.ex`.

## Arguments

Expand All @@ -18,7 +18,7 @@ defmodule Mix.Tasks.PowAssent.Ecto.Gen.Schema do
"""
use Mix.Task

alias PowAssent.Ecto.UserIdentities.Schema.Module, as: SchemaModule
alias PowAssent.Ecto.Identities.Schema.Module, as: SchemaModule
alias Mix.{Generator, Pow, PowAssent}

@switches [context_app: :string, binary_id: :boolean]
Expand Down
Loading