2012-02-09 21:45:26 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
|
|
|
module Preregistration
|
|
|
|
module Devise
|
|
|
|
module RegistrationsController
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
alias_method_chain :create, :token
|
|
|
|
alias_method_chain :new, :token
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_with_token
|
|
|
|
if params['invitation_token']
|
|
|
|
req = RegisterRequest.approved.where(:token => params['invitation_token'].strip).first
|
|
|
|
redirect_to new_register_request_path and return unless req
|
|
|
|
|
|
|
|
resource = build_resource({})
|
|
|
|
resource.name = req.name if resource.respond_to? :name
|
|
|
|
resource.email = req.email if resource.respond_to? :email
|
|
|
|
@invitation_token = req.token
|
|
|
|
|
2012-02-29 07:27:35 +00:00
|
|
|
respond_with_navigational(resource){ render :new }
|
2012-02-09 21:45:26 +00:00
|
|
|
else
|
|
|
|
redirect_to new_register_request_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_with_token
|
|
|
|
redirect_to new_register_request_path and return unless params['invitation_token']
|
|
|
|
req = RegisterRequest.approved.where(:token => params['invitation_token'].strip).first
|
|
|
|
|
|
|
|
build_resource
|
|
|
|
|
|
|
|
redirect_to new_register_request_path and return unless req and resource.email == req.email
|
|
|
|
|
|
|
|
@invitation_token = req.token
|
2012-03-27 14:45:09 +01:00
|
|
|
resource.skip_confirmation!
|
2012-02-09 21:45:26 +00:00
|
|
|
if resource.save
|
|
|
|
if resource.active_for_authentication?
|
|
|
|
set_flash_message :notice, :signed_up if is_navigational_format?
|
|
|
|
sign_in(resource_name, resource)
|
|
|
|
respond_with resource, :location => after_sign_up_path_for(resource)
|
|
|
|
else
|
|
|
|
set_flash_message :notice, :inactive_signed_up, :reason => inactive_reason(resource) 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)
|
2012-02-29 07:27:35 +00:00
|
|
|
respond_with_navigational(resource) { render :new }
|
2012-02-09 21:45:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-25 23:13:15 +00:00
|
|
|
end # RegistrationsController
|
|
|
|
end # Devise
|
|
|
|
end # Preregistration
|
2012-02-09 21:45:26 +00:00
|
|
|
|
|
|
|
Rails.application.config.to_prepare do
|
2013-03-25 23:13:15 +00:00
|
|
|
::Devise::RegistrationsController.send :include, Preregistration::Devise::RegistrationsController if APP_CONFIG['preregistration']
|
2012-02-09 21:45:26 +00:00
|
|
|
end
|