Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CommunitiesController < ApplicationController
- skip_before_action :fetch_community,
- :perform_redirect,
- :cannot_access_if_banned,
- :cannot_access_without_confirmation,
- :ensure_consent_given,
- :ensure_user_belongs_to_community
- # before_action :ensure_no_communities
- layout 'blank_layout'
- include CommunitiesHelper
- NewMarketplaceForm = Form::NewMarketplace
- # def filter_errors(errors,type)
- # @custom_errors = []
- # errors.each do |error|
- # @custom_errors << error if error.include? type
- # end
- # puts "&&&&&&&&&,#{custom_errors}"
- # if @custom_errors.present?
- # @custom_errors[0].join('<br />').html_safe
- # end
- # end
- def new
- render_form
- end
- def formatMarketPlaceName(s)
- s = s.downcase
- s = s.strip
- s = s.squeeze(" ")
- s = s.gsub(" ", "-")
- return s
- end
- def create
- if Rails.env.production?
- @url = "https://api.jungleworks.co/jungle/registerUser"
- @authKey = "hhjkdnnbhbdmd_76756_hdggfj"
- @yeloNodeUrl = "https://sharetribe-api.yelo.red/getDomain"
- @checkDomainUrl = "https://api.yelo.red/marketplace/checkDomain"
- @httpSsl = true
- else
- @url = "http://test-api.yelo.red:3014/jungle/registerUser"
- @authKey = "fgsdgdser54343654trtdgdgrd743f4dssuhgft4fe"
- @yeloNodeUrl = "https://rental-api-3004.yelo.red/getDomain"
- @checkDomainUrl = "https://api.yelo.red/marketplace/checkDomain"
- @httpSsl = false
- end
- form = NewMarketplaceForm.new(params)
- if form.valid?
- form_hash = form.to_hash
- @domain = formatMarketPlaceName(form_hash[:marketplace_name])
- uri = URI(@checkDomainUrl)
- https = Net::HTTP.new(uri.host, uri.port)
- https.use_ssl = true
- req = Net::HTTP::Post.new(uri.path, {'Content-Type' =>'application/json'})
- req.body = {
- :domain_name => @domain + ".yelo.red"
- }.to_json
- res = https.request(req)
- @domainRes = JSON.parse(res.body)
- if @domainRes["status"] == 200 and @domainRes["data"]["availability"] == true
- @email_new = Email.find_by(address: form_hash[:admin_email])
- if @email_new.nil?
- @community_new = Community.find_by(ident: @domain)
- if @community_new.nil?
- uri = URI(@url)
- https = Net::HTTP.new(uri.host, uri.port)
- https.use_ssl = @httpSsl
- req = Net::HTTP::Post.new(uri.path, {'Content-Type' =>'application/json'})
- @signupData = {
- :email => form_hash[:admin_email],
- :password => form_hash[:admin_password],
- :phone => '1213141516',
- :timezone => -330,
- :username => form_hash[:admin_first_name],
- :first_name => form_hash[:admin_first_name],
- :country_phone_code => "+91",
- :company_address => "CDCL",
- :company_latitude => "30.77",
- :company_longitude => "76.66",
- :auth_key => @authKey,
- :offering => 2,
- :ipconfig => { :country_code => form_hash[:marketplace_country],
- :continent_code => '12',
- :region_code => '3'
- }
- }
- makeMarketingParams
- req.body = @signupData.to_json
- res1 = https.request(req)
- puts "response ################################### #{res1.body}"
- @authBody = JSON.parse(res1.body)
- if @authBody && @authBody["status"]==200
- form_hash[:user_id] = @authBody["data"]["user_id"]
- marketplace = MarketplaceService.create(
- form_hash.slice(:marketplace_name,
- :marketplace_type,
- :marketplace_country,
- :marketplace_language,
- :user_id)
- )
- user = UserService::API::Users.create_user({
- given_name: form_hash[:admin_first_name],
- family_name: form_hash[:admin_last_name],
- email: form_hash[:admin_email],
- password: form_hash[:admin_password],
- is_admin: 1,
- locale: form_hash[:marketplace_language]},
- marketplace.id).data
- enablePaymentMethod(marketplace[:id])
- setDefaultFeature(marketplace[:id])
- uri = URI(@yeloNodeUrl)
- https = Net::HTTP.new(uri.host, uri.port)
- https.use_ssl = true
- req = Net::HTTP::Post.new(uri.path, {'Content-Type' =>'application/json'})
- puts 'the community_Name will be >>>>>>>>@@ ' , @domain
- req.body = {
- :domain_name => @domain
- }.to_json
- res = https.request(req)
- puts "req ########################### #{req.body}"
- puts "response from get domain ################################### #{res.body}"
- auth_token = UserService::API::AuthTokens.create_login_token(user[:id])
- @user_token = auth_token[:token]
- url = URLUtils.append_query_param(marketplace.full_domain({with_protocol: true}), "auth", @user_token)
- render action: :third_step, locals: {
- title: 'Create a new marketplace',
- url: url,
- domain: @domain + '.yelo.red'
- }
- else
- render_form(errors: ['email already exists from auth'])
- end
- else
- render_form(errors: ['Marketplace name Error : Already Exists , Choose Other ' ,'Already Contains'])
- end
- else
- render_form(errors: ['email already exists '])
- end
- elsif @domainRes["status"] == 1
- render_form(errors: ['Marketplace name Error : Domain Already Exists '])
- else
- render_form(errors: ['Marketplace name Error : Domain Already Exists ' ,'Already Contains'])
- end
- else
- render_form(errors: form.errors.full_messages)
- end
- end
- private
- def render_form(errors: nil)
- puts "#########,#{errors},#{communities_path}"
- queryStr = request.query_string
- render action: :new, locals: {
- title: 'Create a new marketplace',
- form_action: Maybe(communities_path).split("?")[0].or_else("") + (!queryStr.empty? ? queryStr.prepend("?") : ""),
- errors: errors
- }
- end
- def ensure_no_communities
- redirect_to landing_page_path if communities_exist?
- end
- def third_step
- puts "kunal@@###{session[:id]+session[:full_domain]}"
- auth_token = UserService::API::AuthTokens.create_login_token(session[:id])
- @user_token = auth_token[:token]
- # url = URLUtils.append_query_param(session[:full_domain], "auth", @user_token )
- end
- def enablePaymentMethod(marketplaceID)
- TransactionService::API::Api.processes.create(community_id: marketplaceID, process: :preauthorize, author_is_seller: true)
- TransactionService::API::Api.settings.provision(community_id: marketplaceID, payment_gateway: :stripe, payment_process: :preauthorize, active: true)
- end
- def setDefaultFeature(marketplaceID)
- FeatureFlagService::API::Api.features.enable(community_id: marketplaceID,features: [:topbar_v1])
- FeatureFlagService::API::Api.features.disable(community_id: marketplaceID,features: [:searchpage_v1])
- end
- def makeMarketingParams
- if params[:utm_source]
- @signupData[:source] = params[:utm_source];
- else
- @signupData[:source] = 'yelo_Dashboard_Direct';
- end
- if params[:utm_medium]
- @signupData[:medium] = params[:utm_medium];
- else
- @signupData[:medium] = 'Dashboard_Signup_Direct';
- end
- if params[:utm_campaign]
- @signupData[:utm_campaign] = params[:utm_campaign];
- end
- if params[:refferal_id]
- @signupData[:refferal_id] = params[:refferal_id];
- end
- if params[:l_source]
- @signupData[:l_source] = params[:l_source];
- end
- if params[:tarsan]
- @signupData[:tarsan] = params[:tarsan];
- end
- if params[:previous_page]
- @signupData[:previous_page] = params[:previous_page];
- end
- if params[:referrer]
- @signupData[:referrer] = params[:referrer];
- end
- if params[:vertical]
- @signupData[:vertical] = params[:vertical];
- end
- if params[:ad_campaign_name]
- @signupData[:ad_campaign_name] = params[:ad_campaign_name];
- end
- if params[:web_referrer]
- @signupData[:web_referrer] = params[:web_referrer];
- end
- if params[:old_source]
- @signupData[:old_source] = params[:old_source];
- end
- if params[:old_medium]
- @signupData[:old_medium] = params[:old_medium];
- end
- if params[:vertical_page]
- @signupData[:vertical_page] = params[:vertical_page];
- end
- if params[:utm_term]
- @signupData[:utm_term] = params[:utm_term];
- end
- if params[:gclid]
- @signupData[:gclid] = params[:gclid];
- end
- if params[:continent_code]
- @signupData[:continent_code] = params[:continent_code];
- end
- # if params[:old_utm_campaign]
- # @signupData[:old_utm_campaign] = params[:old_utm_campaign];
- # end
- end
- def communities_exist?
- Rails.env.test? ? false : Community.count > 0
- end
- end
Add Comment
Please, Sign In to add comment