Request for a 'sign_up' hook #2104

Closed
bluemont opened this Issue Oct 16, 2012 · 3 comments

Projects

None yet

2 participants

@bluemont

I would like to see a sign_up hook inside the RegistrationsController. Here is what I propose -- a one line change to create and also a stub method definition that is easy to override in a controller or helper. See the line with the "# suggested hook" comment, below. What do you think?

My motivation is explained here: http://stackoverflow.com/questions/12916667/devise-hooks-that-distinguish-between-sign-up-sign-in

In short, as I understand it, Devise's current callbacks do not distinguish between sign up and sign in. If I need that, I currently have to override the RegistrationsController create method. But overriding and calling super does not give the granularity that I need. At present, the "best" option is copy and pasting the logic and adding the callback where I need it -- which is brittle.

# POST /resource
def create
  build_resource

  if resource.save
    if resource.active_for_authentication?
      set_flash_message :notice, :signed_up if is_navigational_format?
      sign_in(resource_name, resource)
      sign_up(resource_name, resource) # suggested hook
      respond_with resource, :location => after_sign_up_path_for(resource)
    else
      set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
      expire_session_data_after_sign_in!
      respond_with resource, :location => after_inactive_sign_up_path_for(resource)
    end
  else
    clean_up_passwords resource
    respond_with resource
  end
end
@josevalim
Member

I am fine with having a sign_up(resource_name, resource) in the registrations controller that by default is a simple call to sign_in(resource_name, resource). So you can customize and call super after you are done. What do you think?

@bluemont

Thanks! That sounds good to me.

How might this fit into the roadmap?

@josevalim
Member

Feel free to send a pull request and we will merge. I want to reserve some time, rather sooner than later, to tidy up and release a new version.

@pootsbook pootsbook added a commit to rubynortheast/devise that referenced this issue Oct 23, 2012
@pootsbook pootsbook Separates sign_up and sign_in on Registration
See #2104

Completed with the help of @rubynortheast
68dc20c
@josevalim josevalim closed this Oct 23, 2012
@oki oki added a commit to oki/devise that referenced this issue Jan 29, 2013
@pootsbook pootsbook Separates sign_up and sign_in on Registration
See #2104

Completed with the help of @rubynortheast
f9c45d4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment