docbrown/app/controllers/invitations_controller.rb
Suzanne Aitchison 25bf8a0711
Remove name from invitation flow (#17438)
* remove name from invite user flow

* remove name from invitation instructions

* update invitations spec

* update specs and invitation actions overflow menu name

* allow users to set name when accepting invite
2022-05-03 09:33:12 +01:00

30 lines
1.3 KiB
Ruby

class InvitationsController < Devise::InvitationsController
# Copied from https://github.com/scambra/devise_invitable/blob/master/app/controllers/devise/invitations_controller.rb
# And edited. This is a common devise pattern, similar to OmniauthCallbacksController.
# PUT /resource/invitation
def update
raw_invitation_token = update_resource_params[:invitation_token]
self.resource = accept_resource
invitation_accepted = resource.errors.empty?
yield resource if block_given?
if invitation_accepted
resource.update!(registered_at: Time.current, registered: true, name: params[:user][:name])
if resource.class.allow_insecure_sign_in_after_accept
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message :notice, flash_message if is_flashing_format?
resource.after_database_authentication
sign_in(resource_name, resource)
respond_with resource, location: after_accept_path_for(resource)
else
set_flash_message :notice, :updated_not_active if is_flashing_format?
respond_with resource, location: new_session_path(resource_name)
end
else
resource.invitation_token = raw_invitation_token
respond_with_navigational(resource) { render :edit }
end
end
end