Guest User

Untitled

a guest
Apr 11th, 2019
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.89 KB | None | 0 0
  1. class CommunitiesController < ApplicationController
  2. skip_before_action :fetch_community,
  3. :perform_redirect,
  4. :cannot_access_if_banned,
  5. :cannot_access_without_confirmation,
  6. :ensure_consent_given,
  7. :ensure_user_belongs_to_community
  8.  
  9. # before_action :ensure_no_communities
  10.  
  11. layout 'blank_layout'
  12. include CommunitiesHelper
  13. NewMarketplaceForm = Form::NewMarketplace
  14.  
  15. # def filter_errors(errors,type)
  16. # @custom_errors = []
  17. # errors.each do |error|
  18. # @custom_errors << error if error.include? type
  19. # end
  20. # puts "&&&&&&&&&,#{custom_errors}"
  21. # if @custom_errors.present?
  22. # @custom_errors[0].join('<br />').html_safe
  23. # end
  24. # end
  25.  
  26. def new
  27. render_form
  28. end
  29.  
  30. def formatMarketPlaceName(s)
  31. s = s.downcase
  32. s = s.strip
  33. s = s.squeeze(" ")
  34. s = s.gsub(" ", "-")
  35. return s
  36. end
  37.  
  38. def create
  39. if Rails.env.production?
  40. @url = "https://api.jungleworks.co/jungle/registerUser"
  41. @authKey = "hhjkdnnbhbdmd_76756_hdggfj"
  42. @yeloNodeUrl = "https://sharetribe-api.yelo.red/getDomain"
  43. @checkDomainUrl = "https://api.yelo.red/marketplace/checkDomain"
  44. @httpSsl = true
  45. else
  46. @url = "http://test-api.yelo.red:3014/jungle/registerUser"
  47. @authKey = "fgsdgdser54343654trtdgdgrd743f4dssuhgft4fe"
  48. @yeloNodeUrl = "https://rental-api-3004.yelo.red/getDomain"
  49. @checkDomainUrl = "https://api.yelo.red/marketplace/checkDomain"
  50. @httpSsl = false
  51. end
  52.  
  53. form = NewMarketplaceForm.new(params)
  54.  
  55.  
  56. if form.valid?
  57.  
  58.  
  59. form_hash = form.to_hash
  60.  
  61. @domain = formatMarketPlaceName(form_hash[:marketplace_name])
  62.  
  63.  
  64. uri = URI(@checkDomainUrl)
  65. https = Net::HTTP.new(uri.host, uri.port)
  66. https.use_ssl = true
  67. req = Net::HTTP::Post.new(uri.path, {'Content-Type' =>'application/json'})
  68.  
  69. req.body = {
  70. :domain_name => @domain + ".yelo.red"
  71. }.to_json
  72.  
  73.  
  74. res = https.request(req)
  75. @domainRes = JSON.parse(res.body)
  76.  
  77. if @domainRes["status"] == 200 and @domainRes["data"]["availability"] == true
  78. @email_new = Email.find_by(address: form_hash[:admin_email])
  79.  
  80. if @email_new.nil?
  81. @community_new = Community.find_by(ident: @domain)
  82. if @community_new.nil?
  83. uri = URI(@url)
  84. https = Net::HTTP.new(uri.host, uri.port)
  85. https.use_ssl = @httpSsl
  86. req = Net::HTTP::Post.new(uri.path, {'Content-Type' =>'application/json'})
  87. @signupData = {
  88. :email => form_hash[:admin_email],
  89. :password => form_hash[:admin_password],
  90. :phone => '1213141516',
  91. :timezone => -330,
  92. :username => form_hash[:admin_first_name],
  93. :first_name => form_hash[:admin_first_name],
  94. :country_phone_code => "+91",
  95. :company_address => "CDCL",
  96. :company_latitude => "30.77",
  97. :company_longitude => "76.66",
  98. :auth_key => @authKey,
  99. :offering => 2,
  100. :ipconfig => { :country_code => form_hash[:marketplace_country],
  101. :continent_code => '12',
  102. :region_code => '3'
  103. }
  104. }
  105.  
  106. makeMarketingParams
  107. req.body = @signupData.to_json
  108. res1 = https.request(req)
  109. puts "response ################################### #{res1.body}"
  110.  
  111. @authBody = JSON.parse(res1.body)
  112.  
  113. if @authBody && @authBody["status"]==200
  114.  
  115. form_hash[:user_id] = @authBody["data"]["user_id"]
  116.  
  117. marketplace = MarketplaceService.create(
  118. form_hash.slice(:marketplace_name,
  119. :marketplace_type,
  120. :marketplace_country,
  121. :marketplace_language,
  122. :user_id)
  123. )
  124. user = UserService::API::Users.create_user({
  125. given_name: form_hash[:admin_first_name],
  126. family_name: form_hash[:admin_last_name],
  127. email: form_hash[:admin_email],
  128. password: form_hash[:admin_password],
  129. is_admin: 1,
  130. locale: form_hash[:marketplace_language]},
  131. marketplace.id).data
  132.  
  133. enablePaymentMethod(marketplace[:id])
  134. setDefaultFeature(marketplace[:id])
  135.  
  136.  
  137. uri = URI(@yeloNodeUrl)
  138.  
  139. https = Net::HTTP.new(uri.host, uri.port)
  140. https.use_ssl = true
  141. req = Net::HTTP::Post.new(uri.path, {'Content-Type' =>'application/json'})
  142.  
  143. puts 'the community_Name will be >>>>>>>>@@ ' , @domain
  144.  
  145. req.body = {
  146. :domain_name => @domain
  147. }.to_json
  148.  
  149. res = https.request(req)
  150.  
  151. puts "req ########################### #{req.body}"
  152. puts "response from get domain ################################### #{res.body}"
  153.  
  154. auth_token = UserService::API::AuthTokens.create_login_token(user[:id])
  155. @user_token = auth_token[:token]
  156. url = URLUtils.append_query_param(marketplace.full_domain({with_protocol: true}), "auth", @user_token)
  157.  
  158. render action: :third_step, locals: {
  159. title: 'Create a new marketplace',
  160. url: url,
  161. domain: @domain + '.yelo.red'
  162. }
  163. else
  164. render_form(errors: ['email already exists from auth'])
  165. end
  166. else
  167. render_form(errors: ['Marketplace name Error : Already Exists , Choose Other ' ,'Already Contains'])
  168. end
  169. else
  170. render_form(errors: ['email already exists '])
  171. end
  172. elsif @domainRes["status"] == 1
  173. render_form(errors: ['Marketplace name Error : Domain Already Exists '])
  174. else
  175. render_form(errors: ['Marketplace name Error : Domain Already Exists ' ,'Already Contains'])
  176. end
  177. else
  178. render_form(errors: form.errors.full_messages)
  179. end
  180. end
  181.  
  182. private
  183.  
  184. def render_form(errors: nil)
  185. puts "#########,#{errors},#{communities_path}"
  186. queryStr = request.query_string
  187. render action: :new, locals: {
  188. title: 'Create a new marketplace',
  189. form_action: Maybe(communities_path).split("?")[0].or_else("") + (!queryStr.empty? ? queryStr.prepend("?") : ""),
  190. errors: errors
  191. }
  192. end
  193.  
  194. def ensure_no_communities
  195. redirect_to landing_page_path if communities_exist?
  196. end
  197.  
  198. def third_step
  199. puts "kunal@@###{session[:id]+session[:full_domain]}"
  200. auth_token = UserService::API::AuthTokens.create_login_token(session[:id])
  201. @user_token = auth_token[:token]
  202. # url = URLUtils.append_query_param(session[:full_domain], "auth", @user_token )
  203.  
  204. end
  205. def enablePaymentMethod(marketplaceID)
  206.  
  207.  
  208. TransactionService::API::Api.processes.create(community_id: marketplaceID, process: :preauthorize, author_is_seller: true)
  209. TransactionService::API::Api.settings.provision(community_id: marketplaceID, payment_gateway: :stripe, payment_process: :preauthorize, active: true)
  210.  
  211. end
  212.  
  213. def setDefaultFeature(marketplaceID)
  214.  
  215. FeatureFlagService::API::Api.features.enable(community_id: marketplaceID,features: [:topbar_v1])
  216. FeatureFlagService::API::Api.features.disable(community_id: marketplaceID,features: [:searchpage_v1])
  217.  
  218. end
  219.  
  220.  
  221. def makeMarketingParams
  222.  
  223. if params[:utm_source]
  224. @signupData[:source] = params[:utm_source];
  225. else
  226. @signupData[:source] = 'yelo_Dashboard_Direct';
  227. end
  228. if params[:utm_medium]
  229. @signupData[:medium] = params[:utm_medium];
  230. else
  231. @signupData[:medium] = 'Dashboard_Signup_Direct';
  232. end
  233. if params[:utm_campaign]
  234. @signupData[:utm_campaign] = params[:utm_campaign];
  235. end
  236. if params[:refferal_id]
  237. @signupData[:refferal_id] = params[:refferal_id];
  238. end
  239. if params[:l_source]
  240. @signupData[:l_source] = params[:l_source];
  241. end
  242. if params[:tarsan]
  243. @signupData[:tarsan] = params[:tarsan];
  244. end
  245. if params[:previous_page]
  246. @signupData[:previous_page] = params[:previous_page];
  247. end
  248. if params[:referrer]
  249. @signupData[:referrer] = params[:referrer];
  250. end
  251. if params[:vertical]
  252. @signupData[:vertical] = params[:vertical];
  253. end
  254. if params[:ad_campaign_name]
  255. @signupData[:ad_campaign_name] = params[:ad_campaign_name];
  256. end
  257. if params[:web_referrer]
  258. @signupData[:web_referrer] = params[:web_referrer];
  259. end
  260. if params[:old_source]
  261. @signupData[:old_source] = params[:old_source];
  262. end
  263. if params[:old_medium]
  264. @signupData[:old_medium] = params[:old_medium];
  265. end
  266. if params[:vertical_page]
  267. @signupData[:vertical_page] = params[:vertical_page];
  268. end
  269. if params[:utm_term]
  270. @signupData[:utm_term] = params[:utm_term];
  271. end
  272. if params[:gclid]
  273. @signupData[:gclid] = params[:gclid];
  274. end
  275. if params[:continent_code]
  276. @signupData[:continent_code] = params[:continent_code];
  277. end
  278. # if params[:old_utm_campaign]
  279. # @signupData[:old_utm_campaign] = params[:old_utm_campaign];
  280. # end
  281. end
  282.  
  283.  
  284.  
  285.  
  286. def communities_exist?
  287. Rails.env.test? ? false : Community.count > 0
  288. end
  289. end
Add Comment
Please, Sign In to add comment