Sha256: a85409057bee6c494f60f57895b90b06b8497208bebc8c18c9543efe654d21aa

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

class Iugu::RegistrationsController < Devise::RegistrationsController
  after_filter :select_account, :only => [:create,:update]
  before_filter :verify_private_api_secret, :only => [:create]

  layout IuguSDK.alternative_layout

  def new
    if IuguSDK::default_subscription_name.blank? && IuguSDK::enable_subscription_features && !params[:plan]
      redirect_to pricing_index_path
    else
      if IuguSDK::enable_subscription_features
        @plan_identifier = params[:plan] || IuguSDK::default_subscription_name
        @currency = locale_to_currency I18n.locale
      end
      super
    end
  end

  def create
    if !params[:user][:user_invitation].blank? 
      invite = UserInvitation.find_by_invitation_token(params[:user][:user_invitation])
      return invalid_invitation if !invite or invite.try(:used)
    end
    cookies[:signup] = 1
    params[:user][:locale] = @matched_locale_from_browser unless params[:user][:locale]
    super
  end

  def try_first
    if IuguSDK::enable_guest_user
      @user = User.create_guest
      @user.remember_me = true
      sign_in @user
      select_account
      flash[:notice] = I18n.t("iugu.notices.guest_login")
      redirect_to IuguSDK::app_main_url
    else
      raise ActionController::RoutingError.new("Not found")
    end
  end

  def after_sign_up_path_for(resource)
    IuguSDK::app_main_url
  end

  private

  def invalid_invitation
    redirect_to new_user_registration_path, flash: { error: I18n.t("errors.messages.invalid_invitation") }
  end

  def verify_private_api_secret
    if request.format.json?
      render :json=>{:errors=>"Unauthorized"}, :status=>401 unless params[:private_api_secret] == IuguSDK::private_api_secret 
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
iugusdk-1.0.11 app/controllers/iugu/registrations_controller.rb
iugusdk-1.0.10 app/controllers/iugu/registrations_controller.rb
iugusdk-1.0.9 app/controllers/iugu/registrations_controller.rb
iugusdk-1.0.8 app/controllers/iugu/registrations_controller.rb