Sha256: 920d7134d57f24bc9369f3a2f86a2e89b462486e38478d2ba124690df4fc20e4

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 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 && IuguSDK::enable_subscription_features && !params[:plan]
      redirect_to pricing_index_path
    else
      if IuguSDK::enable_subscription_features
        ps = []
        Iugu::Api::Plan.all.each { |p| ps << p if p.identifier == (params[:plan] || IuguSDK::default_subscription_name) }
        if plan = ps.first
          @plan_id = plan.id
          plan.prices.each { |p| @price_id = p.id if p.currency == locale_to_currency(I18n.locale) }
        end
      end
      super
    end
  end

  def create
    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
      #respond_with @user, :location => sign_up_path_for(@user)
    else
      raise ActionController::RoutingError.new("Not found")
    end
  end

  def after_sign_up_path_for(resource)
    IuguSDK::app_main_url
  end

  private

  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

1 entries across 1 versions & 1 rubygems

Version Path
iugusdk-1.0.0.alpha.18 app/controllers/iugu/registrations_controller.rb