diff --git a/app/assets/javascripts/admin/store_manager.js b/app/assets/javascripts/admin/store_manager.js new file mode 100644 index 0000000..93dfedd --- /dev/null +++ b/app/assets/javascripts/admin/store_manager.js @@ -0,0 +1,191 @@ +var StoreManager = function(section){ + var storeArea = $("#store-area"), + loadingArea = storeArea.find(".loading-store"), + loadingAreaStatus = loadingArea.find(".loading-status"), + waitForStoreResponseCount = 0, + section = section, + formArea = storeArea.find(".form-area"); + + var initialize = function(){ + loadingArea.find("img").show(); + loadingAreaStatus.text("Contacting Ruling Store."); + loadingArea.find("p").eq(1).html("Please wait..."); + setTimeout(step1,1000); + } + + var step1 = function(){ + $.ajax({ + "type" : "get", + "dataType" : "json", + "url" : "/admin/store/check_credentials" + }).done(function(status){ + if(status.success == true){ + loadingAreaStatus.text("Checking permissions."); + setTimeout(step2,1000); + }else if(status.success == false){ + setTimeout(loadRegisterForm,1000); + } + }).fail(showError); + } + + var step2 = function(){ + $.ajax({ + "type" : "get", + "dataType" : "json", + "url" : "/admin/store/check_permissions" + }).done(function(data){ + if(data.success){ + loadingAreaStatus.text("Fetching store data."); + if(section == "templates"){ + setTimeout(loadTemplateStore,1000); + }else if(section == "apps"){ + setTimeout(loadAppStore,1000); + } + }else if(!data.success){ + loadingArea.find("img").hide(); + loadingAreaStatus.text(data.message); + if(data.error == "SITE_NOT_CONFIRMED"){ + var resentBtn = $("Resend Email"); + resentBtn.on("click",function(){ + resendEmail(); + return false; + }) + loadingArea.find("p").eq(1).html(resentBtn); + }else if(data.error == "SITE_PERMISSION_DENIED"){ + loadingArea.find("p").eq(1).html("Please contact www.rulingcom.com."); + }else{ + loadingArea.find("p").eq(1).html("Please contact www.rulingcom.com."); + } + } + }).fail(showError); + } + + var loadTemplateStore = function(){ + $.ajax({ + "type" : "get", + "dataType" : "html", + "url" : "/admin/store/template_store" + }).done(function(html){ + storeArea.html(html); + }).fail(showError); + } + + var loadAppStore = function(){ + $.ajax({ + "type" : "get", + "dataType" : "html", + "url" : "/admin/store/app_store" + }).done(function(html){ + storeArea.html(html); + }).fail(showError); + } + + var loadTemplateStore = function(){ + $.ajax({ + "type" : "get", + "dataType" : "html", + "url" : "/admin/store/template_store" + }).done(function(html){ + storeArea.html(html); + }).fail(showError); + } + + var loadRegisterForm = function(){ + loadingAreaStatus.text("Loading registeration form.") + $.ajax({ + "type" : "get", + "dataType" : "html", + "url" : "/admin/store/register_form" + }).done(function(html){ + loadingArea.hide(); + formArea.html(html); + var form = formArea.find("form"); + new FormValidator(form); + form.on("submit",function(){ + var email = form.find("#inputEmail").val(); + if(email){ + loadingAreaStatus.text("Registering with Orbit Store.") + formArea.hide(); + loadingArea.show(); + $.ajax({ + "type" : "post", + "url" : form.attr("action"), + "dataType" : "json", + "data" : {"email" : email} + }).done(function(data){ + if(data.success){ + loadingAreaStatus.text("Waiting for Store."); + setTimeout(waitForStoreResponse,500); + }else{ + loadingArea.find("img").hide(); + loadingAreaStatus.text(data.message); + loadingArea.find("p").eq(1).html("Please contact www.rulingcom.com."); + } + }).fail(showError) + } + return false; + }) + }) + } + + var waitForStoreResponse = function(){ + $.ajax({ + "type" : "get", + "dataType" : "json", + "url" : "/admin/store/check_credentials" + }).done(function(status){ + if(status.success == true){ + resendEmail(); + }else if(status.success == false){ + waitForStoreResponseCount++; + if(waitForStoreResponseCount > 5){ + loadingArea.find("img").hide(); + loadingAreaStatus.text("Orbit Store couldn't contact your server."); + loadingArea.find("p").eq(1).html("Please try again later or contact www.rulingcom.com."); + }else{ + setTimeout(waitForStoreResponse,500); + } + } + }).fail(showError); + } + + var resendEmail = function(){ + loadingArea.find("img").show(); + loadingAreaStatus.text("Sending verification email."); + loadingArea.find("p").eq(1).html("Please wait..."); + $.ajax({ + "url" : "/admin/store/send_email", + "dataType" : "json", + "type" : "get" + }).done(function(data){ + if(data.success){ + loadingArea.find("img").hide(); + loadingAreaStatus.text("Email sent. Please confirm and click on link below or refresh the page."); + var checkAgainBtn = $("Check Again"); + checkAgainBtn.on("click",function(){ + initialize(); + return false; + }) + loadingArea.find("p").eq(1).html(checkAgainBtn); + }else{ + loadingArea.find("img").hide(); + loadingAreaStatus.text("Email couldn't be sent. You can try again or contact www.rulingcom.com"); + loadingArea.find("p").eq(1).html("Please contact www.rulingcom.com."); + } + }).fail(showError); + } + + + var showError = function(){ + loadingArea.find("img").hide(); + loadingAreaStatus.text("There was some unknown error."); + loadingArea.find("p").eq(1).html("Please try again later or contact www.rulingcom.com."); + } + + initialize(); +} + + + +// step 1 -> check connection to store server +// step 2 -> check for site confirmation and access permission \ No newline at end of file diff --git a/app/assets/javascripts/validator.js b/app/assets/javascripts/validator.js index 2cd0f65..847a6d4 100644 --- a/app/assets/javascripts/validator.js +++ b/app/assets/javascripts/validator.js @@ -25,8 +25,9 @@ var FormValidator = function(form){ nospace : function(value){ return (/\s/.test(value) ? false : true); }, - email : function(){ - + email : function(value){ + var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + return re.test(value); } } diff --git a/app/controllers/admin/module_store_controller.rb b/app/controllers/admin/module_store_controller.rb index b08c4c8..c6ac85f 100644 --- a/app/controllers/admin/module_store_controller.rb +++ b/app/controllers/admin/module_store_controller.rb @@ -3,20 +3,21 @@ class Admin::ModuleStoreController < OrbitAdminController def index @extensions = [] - if current_site.site_token? - if current_site.store_confirmation - @extensions = get_extensions - @store_confirmation = true - else - @extensions = [] - @store_confirmation = false - end - @downloaded_extensions = get_downloaded_extension - else - @store_confirmation = true - @extensions = [] - @downloaded_extensions = get_downloaded_extension - end + @downloaded_extensions = get_downloaded_extension + # if current_site.site_token? + # if current_site.store_confirmation + # @extensions = get_extensions + # @store_confirmation = true + # else + # @extensions = [] + # @store_confirmation = false + # end + + # else + # @store_confirmation = true + # @extensions = [] + # @downloaded_extensions = get_downloaded_extension + # end end def show diff --git a/app/controllers/admin/store_controller.rb b/app/controllers/admin/store_controller.rb new file mode 100644 index 0000000..c98c930 --- /dev/null +++ b/app/controllers/admin/store_controller.rb @@ -0,0 +1,69 @@ +require "uri" +require "net/http" +class Admin::StoreController < OrbitAdminController + layout false + before_action :store_url + def check_credentials + if current_site.store_token.nil? + render :json => {"success" => false}.to_json + else + render :json => {"success" => true}.to_json + end + end + + def register_form + + end + + def template_store + + end + + def app_store + + end + + def send_email + params_to_send = {'store_token' => current_site.store_token} + uri = URI.parse(@store_url) + http = Net::HTTP.new(uri.host,uri.port) + request = Net::HTTP::Get.new("/site/send_email") + request.body = params_to_send.to_query + response = http.request(request) + data = JSON.parse(response.body) + render :json => data.to_json + end + + def check_permissions + params_to_send = {'store_token' => current_site.store_token} + uri = URI.parse(@store_url) + http = Net::HTTP.new(uri.host,uri.port) + request = Net::HTTP::Get.new("/site/permissions") + request.body = params_to_send.to_query + response = http.request(request) + data = JSON.parse(response.body) + if !data["success"] && data["error"] == "INVALID_SITE_TOKEN" + current_site.store_token = nil + current_site.save + end + render :json => data.to_json + end + + def register_site + params_to_send = {'site_domain' => request.host_with_port, 'admin_email' => params["email"], "site_token" => current_site.uid} + uri = URI.parse(@store_url) + http = Net::HTTP.new(uri.host,uri.port) + request = Net::HTTP::Post.new("/register/site") + request.body = params_to_send.to_query + response = http.request(request) + data = JSON.parse(response.body) + render :json => data.to_json + end + + + private + def store_url + @store_url = "http://store.tp.rulingcom.com" + # @store_url = "http://localhost:3000" + end +end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bfbc6cf..b02e70f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -29,7 +29,7 @@ class ApplicationController < ActionController::Base if !params[:locale] and !session[:locale] if current_site.enable_language_detection browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].split(',').first.underscore rescue nil - session[:locale] = in_use_locales.include?(browser_locale.to_sym) ? browser_locale : nil + session[:locale] = (in_use_locales.include?(browser_locale.to_sym) ? browser_locale : nil) rescue nil elsif current_site.default_locale session[:locale] = current_site.default_locale end diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 3f60282..79e5751 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -157,6 +157,7 @@ class MembersController < ApplicationController def member_data(member, fields_to_show) profile_data = [] fields_to_show.each do |field| + # debugger case field['type'] when 'profile' field_data = member.get_attribute_data(field) rescue {} @@ -166,7 +167,7 @@ class MembersController < ApplicationController field_data = member.attribute_values.find_by(:key=>field['key']).get_field_value rescue {} end next if field_data.blank? or field_data['value'].blank? - + if field['sort_order'] field_data['sort_value'] = field_data['val'].blank? ? field_data['value'] : field_data['val'] field_data['sort_value'] = (field_data['sort_value'].is_i? ? field_data['sort_value'].to_i : field_data['sort_value'] rescue field_data['sort_value']) diff --git a/app/controllers/store_api_controller.rb b/app/controllers/store_api_controller.rb new file mode 100644 index 0000000..50eb645 --- /dev/null +++ b/app/controllers/store_api_controller.rb @@ -0,0 +1,14 @@ +class StoreApiController < ApplicationController + def confirmation + site_token = params[:site_token] + store_token = params[:store_token] + puts current_site.to_s + if current_site.uid.eql?(site_token) + current_site.store_token = store_token + current_site.save + render :json => {"success" => true}.to_json + else + render :json => {"success" => false}.to_json + end + end +end \ No newline at end of file diff --git a/app/models/attribute_field.rb b/app/models/attribute_field.rb index 84af526..fba461a 100644 --- a/app/models/attribute_field.rb +++ b/app/models/attribute_field.rb @@ -101,8 +101,16 @@ class AttributeField if field_status.eql?(true) @attribute_field_counter = role.attribute_fields.count rescue nil @attribute_field = self.find(attribute_field_id) rescue nil + old_key = @attribute_field.key @attribute_field.update(role_param) @attribute_field.save + attribute_values = @attribute_field.attribute_values + if attribute_values.count > 0 + attribute_values.each do |av| + av.key = role_param["key"] + av.save + end + end @attribute_field[:af_count] = @attribute_field_counter else @attribute_field_counter = role.attribute_fields.count rescue nil diff --git a/app/models/attribute_value.rb b/app/models/attribute_value.rb index 0cb6e61..5bb74b5 100644 --- a/app/models/attribute_value.rb +++ b/app/models/attribute_value.rb @@ -199,7 +199,7 @@ def unset_all_lang_values end #of data_proc def check_key - self.key = attribute_field.key + self.key = self.attribute_field.key end def method_missing(*field) diff --git a/app/models/site.rb b/app/models/site.rb index fbd8b3f..139bd27 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -32,8 +32,7 @@ class Site field :search,:type => Hash field :site_settings field :template, type: String - field :site_token - field :store_confirmation, type: Boolean, default: false + field :store_token field :month_traffic_cache @@ -42,20 +41,6 @@ class Site mount_uploader :favicon, ImageUploader mount_uploader :mobile_icon, ImageUploader - def confirm_store(site_token) - if self.site_token.eql?(site_token) - self.store_confirmation = true - self.save - end - end - - def generate_site_token - if self.site_token.nil? - self.site_token = SecureRandom.uuid.gsub('-','') - self.save - end - end - def register_site(url,university,department,email,country) api_key = STORE_CONFIG[:store_settings]["api_key"] self.generate_site_token diff --git a/app/views/admin/designs/index.html.erb b/app/views/admin/designs/index.html.erb index bf7a9ce..072cc2a 100644 --- a/app/views/admin/designs/index.html.erb +++ b/app/views/admin/designs/index.html.erb @@ -143,7 +143,7 @@ @@ -152,18 +152,7 @@
<%= t(:template_store) %>
- - - - - - -
- <%= image_tag("preloader.gif", size: "50") %> - Loading template store... - -
- + <%= render :partial => "admin/store/store", :locals => {:section => "templates"} %>
@@ -176,58 +165,3 @@
<%#= link_to content_tag(:i, nil, :class => 'icon-plus icon-white') + t(:upload), upload_package_admin_designs_path, :class => 'btn btn-primary pull-right' %>
- - - diff --git a/app/views/admin/module_store/index.html.erb b/app/views/admin/module_store/index.html.erb index 578ab71..1b1614f 100644 --- a/app/views/admin/module_store/index.html.erb +++ b/app/views/admin/module_store/index.html.erb @@ -180,49 +180,10 @@
<%= t(:module_store) %>
- <% if @extensions.empty? %> - <% if @store_confirmation %> - <%#= render :partial => "admin/site_registration/site_registration" %> - <% else %> - <%#= render :partial => "admin/site_registration/not_confirmed_store" %> - <% end %> - <% else %> - - - - - - - - - - <% @extensions.each do |extension|%> - - - - <% @module_installed = File.read("downloaded_extensions.rb").include?(extension["key"])%> - <% if @module_installed.eql?(true)%> - - <% else %> - - <% end %> - - <% end %> - -
Module TitleDescriptionActive
-
- -
-
<%=link_to extension["title"], admin_module_store_show_path(:id => extension["_slugs"][0])%>
-

<%=extension["author"]%>

-
- <%= extension["description"].html_safe%> <%=link_to extension["title"], admin_module_store_show_path(:id => extension["_slugs"][0])%> - Installed<%= link_to t(:install), admin_module_store_download_path(:id => extension["_slugs"][0]), :class=>"act btn btn-success" %>
- <% end %> -
+ <%= render :partial => "admin/store/store", :locals => {:section => "apps"} %> +
-
diff --git a/app/views/admin/store/_store.html.erb b/app/views/admin/store/_store.html.erb new file mode 100644 index 0000000..0af6591 --- /dev/null +++ b/app/views/admin/store/_store.html.erb @@ -0,0 +1,36 @@ +<%= javascript_include_tag "admin/store_manager" %> +<%= javascript_include_tag "validator" %> + +
+
+ <%= image_tag("preloader.gif", size: "50") %> +

+

Please wait ...

+
+
+
+
+ + \ No newline at end of file diff --git a/app/views/admin/store/app_store.html.erb b/app/views/admin/store/app_store.html.erb new file mode 100644 index 0000000..314c765 --- /dev/null +++ b/app/views/admin/store/app_store.html.erb @@ -0,0 +1 @@ +This is app store. \ No newline at end of file diff --git a/app/views/admin/store/register_form.html.erb b/app/views/admin/store/register_form.html.erb new file mode 100644 index 0000000..cc311e9 --- /dev/null +++ b/app/views/admin/store/register_form.html.erb @@ -0,0 +1,28 @@ +

Store Registration Form

+
+
+
+ +
+ <%= request.host_with_port %> +
+
+
+ +
+ +
+
+
+ +
+ <%= current_site.uid %> +
+
+
+
+
+ +
+
+
\ No newline at end of file diff --git a/app/views/admin/store/template_store.html.erb b/app/views/admin/store/template_store.html.erb new file mode 100644 index 0000000..d23470e --- /dev/null +++ b/app/views/admin/store/template_store.html.erb @@ -0,0 +1 @@ +This is template store. \ No newline at end of file diff --git a/app/views/email/user_confirmation_email.html.erb b/app/views/email/user_confirmation_email.html.erb index 7f0bd9f..3cd25ec 100644 --- a/app/views/email/user_confirmation_email.html.erb +++ b/app/views/email/user_confirmation_email.html.erb @@ -1,2 +1,2 @@ -

Thank you for registering your site with Orbit! Please click on the following link and confirm. This is to make sure we could provide you with a spam free experience. Thanks a lot.

+

Thank you for registering! Please click on the following link and confirm. This is to make sure we could provide you with a spam free experience. Thanks a lot.

Please click to confirm \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index d58c675..cd62b5e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,8 @@ Orbit::Application.routes.draw do get "/module/:name" => "home#index" get "/module/:name/show" => "home#show" + post "/store/confirmation" => "store_api#confirmation" + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". @@ -216,6 +218,16 @@ Orbit::Application.routes.draw do get 'module_store/toggle_module' => 'module_store#toggle_module' get 'module_store/restart_server' => 'module_store#restart_server' + #store routes + + get "/store/check_credentials" => "store#check_credentials" + get "/store/register_form" => "store#register_form" + post "/store/register_site" => "store#register_site" + get "/store/check_permissions" => "store#check_permissions" + get "/store/template_store" => "store#template_store" + get "/store/app_store" => "store#app_store" + get "/store/send_email" => "store#send_email" + get "import" => "import#index" get "import/check_url" => "import#check_url"