2019-06-04 13:33:00 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Handling a new user registration through the sign-up modal
|
2015-05-05 03:10:25 +02:00
|
|
|
class RegistrationsController < Devise::RegistrationsController
|
2019-06-04 13:33:00 +02:00
|
|
|
# POST /users.json
|
2015-05-05 03:10:25 +02:00
|
|
|
def create
|
2022-01-04 15:27:58 +01:00
|
|
|
# Is public registration allowed?
|
|
|
|
unless Setting.get('public_registrations')
|
|
|
|
render json: { errors: { signup: [t('errors.messages.registration_disabled')] } }, status: :forbidden and return
|
|
|
|
end
|
|
|
|
|
2019-09-23 17:46:46 +02:00
|
|
|
# first check the recaptcha
|
|
|
|
check = RecaptchaService.verify(params[:user][:recaptcha])
|
|
|
|
render json: check['error-codes'], status: :unprocessable_entity and return unless check['success']
|
|
|
|
|
|
|
|
# then create the user
|
2015-05-05 03:10:25 +02:00
|
|
|
build_resource(sign_up_params)
|
|
|
|
|
|
|
|
resource_saved = resource.save
|
|
|
|
yield resource if block_given?
|
|
|
|
if resource_saved
|
|
|
|
if resource.active_for_authentication?
|
|
|
|
set_flash_message :notice, :signed_up if is_flashing_format?
|
|
|
|
|
2016-03-23 18:39:41 +01:00
|
|
|
# Allows sending the confirmation email without blocking the access to the dashboard
|
2015-05-05 03:10:25 +02:00
|
|
|
resource.send_confirmation_instructions
|
|
|
|
|
2021-10-21 15:07:18 +02:00
|
|
|
sign_up(resource_name, resource) unless Setting.get('confirmation_required')
|
2015-05-05 03:10:25 +02:00
|
|
|
respond_with resource, location: after_sign_up_path_for(resource)
|
|
|
|
else
|
|
|
|
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
|
|
|
|
expire_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
|
|
|
|
end
|