Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AgreementsController < ApplicationController
- include PrepareAgreementPage
- before_action :authenticate_user!, except: [:lead_conditional_loan_agreement]
- before_action :parse_token, only: %i[lead_conditional_loan_agreement], unless: Proc.new { user_signed_in? }
- before_action :set_infinity_clients
- after_action -> {
- ahoy.track "lead_conditional_loan_agreement", {page: 'lead_conditional_loan_agreement'}
- }, only: :lead_conditional_loan_agreement
- after_action -> {
- ahoy.track "organic_conditional_loan_agreement", {page: 'organic_conditional_loan_agreement'}
- }, only: :organic_conditional_loan_agreement
- def lead_conditional_loan_agreement
- redirect_to loan_application_current_path and return if user_signed_in?
- inf_customer_id = @attrs[:customer_id]
- inf_loan_id = @attrs[:loan_id]
- loan = @client.get_loan inf_customer_id, inf_loan_id
- # DEV-147
- if loan && loan[:creation_timestamp] < eval("#{LEADS_EXPIRE_IN}.ago")
- redirect_to new_user_session_path, alert: I18n.t('please_login') and return
- end
- if current_user = User.find_by_infinity_customer_id(inf_customer_id)
- if la = current_user.loan_applications.where(infinity_loan_id: inf_loan_id).last
- la.update! ip_address: request.remote_ip
- elsif !LoanApplication.where(infinity_loan_id: inf_loan_id).exists?
- inf_customer = @client.get_customer inf_customer_id
- create_loan_application_for_user(current_user, inf_customer, loan, @attrs[:lead_id])
- deny_loan_if_in_declines_store(loan, @attrs[:lead_id])
- else
- found_loan_app = LoanApplication.where(infinity_loan_id: inf_loan_id).last
- found_user = found_loan_app.user
- logger.warn("Found account duplicate: #{found_user.email} with infinity_loan_id:#{found_loan_app.infinity_loan_id} for lead: #{@attrs[:lead_id]}, current_user: #{current_user.email}")
- login_method = if identity = found_user.social_identities.last
- identity.provider
- else
- found_user.email
- end
- login_hint = I18n.t('please_login_with', login_method: login_method)
- session[:login_hint] = login_hint
- redirect_to new_user_session_path, alert: login_hint and return
- end
- else
- begin
- inf_customer = @client.get_customer inf_customer_id
- current_user = find_or_create_user_with_loan_application! inf_customer, loan, @attrs[:lead_id]
- ahoy.track "lead", page: 'lead_conditional_loan_agreement',
- infinity_customer_id: inf_customer[:id],
- infinity_loan_id: loan[:id],
- lead_id: @attrs[:lead_id]
- rescue ActiveRecord::RecordInvalid => e
- return redirect_to(new_user_session_path, :alert => I18n.t('problem_creating'))
- end
- end
- sign_in(current_user)
- ahoy.authenticate(current_user)
- @loan_app = current_user.loan_application
- redirect_to(loan_application_current_path) and return if @loan_app.declined_credit?
- path = declined_by_routing_number_with_path(@loan_app)
- redirect_to path and return unless path.nil?
- process_conditional_loan_agreement(loan, @loan_app); return if performed?
- render(:conditional_landing_page)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement