Files
openfoodnetwork/app/controllers/user_registrations_controller.rb
luisramos0 5e960512ac Set user locale on user registrations #create
This is done so that user.locale is used in the first confirmation email. This also stores user.locale in the DB from registration.
2018-12-18 15:30:01 +00:00

51 lines
1.2 KiB
Ruby

require 'open_food_network/error_logger'
class UserRegistrationsController < Spree::UserRegistrationsController
I18N_SCOPE = 'devise.user_registrations.spree_user'.freeze
before_filter :set_checkout_redirect, only: :create
include I18nHelper
before_filter :set_locale
# POST /resource/sign_up
def create
@user = build_resource(params[:spree_user])
@user.locale = I18n.locale.to_s
unless resource.save
return render_error(@user.errors)
end
session[:spree_user_signup] = true
session[:confirmation_return_url] = params[:return_url]
associate_user
respond_to do |format|
format.html do
set_flash_message(:success, :signed_up_but_unconfirmed)
redirect_to after_sign_in_path_for(@user)
end
format.js do
render json: { email: @user.email }
end
end
rescue StandardError => error
OpenFoodNetwork::ErrorLogger.notify(error)
render_error(message: I18n.t('unknown_error', scope: I18N_SCOPE))
end
private
def render_error(errors = {})
clean_up_passwords(resource)
respond_to do |format|
format.html do
render :new
end
format.js do
render json: errors, status: :unauthorized
end
end
end
end