smpallen99 / coherence

Coherence is a full featured, configurable authentication system for Phoenix
MIT License
1.27k stars 224 forks source link

Incoherent customization config for User Changeset #351

Closed jaimeiniesta closed 6 years ago

jaimeiniesta commented 6 years ago

In https://github.com/smpallen99/coherence#customizing-user-changeset it says that we should indicate where the changeset/3 function is located like that:

# config/config.exs
config :coherence,
  # ...
  changeset: {MyProject.User, :changeset}

In 5.4.0 this works fine for most controllers, but if we go to /passwords/new/ it fails with an argument error.

If we change the config to something like:

# config/config.exs
config :coherence,
  # ...
  changeset: :changeset

it will work fine for /passwords/new but fail for the other controllers.

I think the problem lies here, as we try to get this config in different, incompatible ways:

https://github.com/smpallen99/coherence/blob/master/lib/coherence/controllers/controller.ex#L289-L293

This problem is on 5.4.0 but it looks like it's still in master.

Is there a way to bypass this problem currently?

jaimeiniesta commented 6 years ago

This fixes it:

  def changeset(:password, module, model, params) do
    {_mod, fun} = Application.get_env(:coherence, :changeset, :changeset)
    apply(module, fun, [model, params, :password])
  end