-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
registration_create callback isn't called when allow_unconfirmed_access is enabled #320
Comments
@smpallen99 -> I'm also in the position where I need to do some additional setup work when a user is created. How do you feel about adding in a configurable callback like the registration_success_callback detailed below? The big advantage to making it a configuration option is that it avoids the need to generate and maintain the Coherence controllers. I'd be more than happy to take this on if its something you would be interested in seeing done. # %% Coherence Configuration %% Don't remove this line
config :coherence,
user_schema: MyApp.Coherence.User,
repo: MyApp.Repo,
module: MyApp,
web_module: MyAppWeb,
router: MyAppWeb.Router,
messages_backend: MyAppWeb.Coherence.Messages,
logged_out_url: "/",
registration_permitted_attributes: ["email","name","password","current_password","password_confirmation"],
invitation_permitted_attributes: ["name","email"],
password_reset_permitted_attributes: ["reset_password_token","password","password_confirmation"],
session_permitted_attributes: ["remember","email","password"],
email_from_name: "Your Name",
email_from_email: "[email protected]",
opts: [:authenticatable, :recoverable, :lockable, :trackable, :unlockable_with_token, :confirmable, :registerable],
layout: {MyAppWeb.LayoutView, :auth},
registration_success_callback: &MyApp.do_extra_work/3
config :coherence, MyAppWeb.Coherence.Mailer,
adapter: Swoosh.Adapters.Sendgrid,
api_key: "your api key here"
# %% End Coherence Configuration %% I added @doc """
Create the new user account.
Creates the new user account. Create and send a confirmation if
this option is enabled.
"""
@spec create(conn, params) :: conn
def create(conn, %{"registration" => registration_params} = params) do
user_schema = Config.user_schema
:registration
|> Controller.changeset(user_schema, user_schema.__struct__,
Controller.permit(registration_params, Config.registration_permitted_attributes() ||
Schema.permitted_attributes_default(:registration)))
|> Schemas.create
|> case do
{:ok, user} ->
conn
|> registration_success_callback(user, user_schema, Config.registration_success_callback())
|> send_confirmation(user, user_schema)
|> redirect_or_login(user, params, Config.allow_unconfirmed_access_for)
{:error, changeset} ->
respond_with(conn, :registration_create_error, %{changeset: changeset})
end
end
defp registration_success_callback(conn, _user, _user_schema, nil), do: conn
defp registration_success_callback(conn, user, user_schema, callback) do
callback.(conn, user, user_schema)
conn
end The create function above is found in |
any updates on this? |
Is this expected behavior? I would like to perform some one-time setup for a user and thus don't really know where to put it.
Thanks for your help, I'm loving this library so far, great work 👍
The text was updated successfully, but these errors were encountered: