Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.26 KB | None | 0 0
  1. class AgreementsController < ApplicationController
  2.   include PrepareAgreementPage
  3.  
  4.   before_action :authenticate_user!, except: [:lead_conditional_loan_agreement]
  5.   before_action :parse_token, only: %i[lead_conditional_loan_agreement], unless: Proc.new { user_signed_in? }
  6.   before_action :set_infinity_clients
  7.  
  8.   after_action -> {
  9.     ahoy.track "lead_conditional_loan_agreement", {page: 'lead_conditional_loan_agreement'}
  10.   }, only: :lead_conditional_loan_agreement
  11.  
  12.   after_action -> {
  13.     ahoy.track "organic_conditional_loan_agreement", {page: 'organic_conditional_loan_agreement'}
  14.   }, only: :organic_conditional_loan_agreement
  15.  
  16.   def lead_conditional_loan_agreement
  17.     redirect_to loan_application_current_path and return if user_signed_in?
  18.     inf_customer_id = @attrs[:customer_id]
  19.     inf_loan_id     = @attrs[:loan_id]
  20.     loan            = @client.get_loan inf_customer_id, inf_loan_id
  21.     # DEV-147
  22.     if loan && loan[:creation_timestamp] < eval("#{LEADS_EXPIRE_IN}.ago")
  23.       redirect_to new_user_session_path, alert: I18n.t('please_login') and return
  24.     end
  25.  
  26.     if current_user = User.find_by_infinity_customer_id(inf_customer_id)
  27.       if la = current_user.loan_applications.where(infinity_loan_id: inf_loan_id).last
  28.         la.update! ip_address: request.remote_ip
  29.       elsif !LoanApplication.where(infinity_loan_id: inf_loan_id).exists?
  30.         inf_customer = @client.get_customer inf_customer_id
  31.         create_loan_application_for_user(current_user, inf_customer, loan, @attrs[:lead_id])
  32.         deny_loan_if_in_declines_store(loan,  @attrs[:lead_id])
  33.       else
  34.         found_loan_app = LoanApplication.where(infinity_loan_id: inf_loan_id).last
  35.         found_user = found_loan_app.user
  36.         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}")
  37.         login_method = if identity = found_user.social_identities.last
  38.           identity.provider
  39.         else
  40.           found_user.email
  41.         end
  42.         login_hint = I18n.t('please_login_with', login_method: login_method)
  43.         session[:login_hint] = login_hint
  44.         redirect_to new_user_session_path, alert: login_hint and return
  45.       end
  46.     else
  47.       begin
  48.         inf_customer = @client.get_customer inf_customer_id
  49.         current_user = find_or_create_user_with_loan_application! inf_customer, loan, @attrs[:lead_id]
  50.         ahoy.track "lead", page: 'lead_conditional_loan_agreement',
  51.                            infinity_customer_id: inf_customer[:id],
  52.                            infinity_loan_id: loan[:id],
  53.                            lead_id:  @attrs[:lead_id]
  54.       rescue ActiveRecord::RecordInvalid => e
  55.         return redirect_to(new_user_session_path, :alert => I18n.t('problem_creating'))
  56.       end
  57.     end
  58.  
  59.     sign_in(current_user)
  60.     ahoy.authenticate(current_user)
  61.     @loan_app = current_user.loan_application
  62.     redirect_to(loan_application_current_path) and return if @loan_app.declined_credit?
  63.  
  64.     path = declined_by_routing_number_with_path(@loan_app)
  65.     redirect_to path and return unless path.nil?
  66.  
  67.     process_conditional_loan_agreement(loan, @loan_app); return if performed?
  68.     render(:conditional_landing_page)
  69.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement