Site Registration - some finishing required
This commit is contained in:
parent
702b46f416
commit
e76d177ff8
2
Gemfile
2
Gemfile
|
@ -20,7 +20,7 @@ gem "acts_as_unvlogable"
|
|||
gem 'youtube_it'
|
||||
gem 'gotcha'
|
||||
gem "geocoder"
|
||||
|
||||
gem 'httparty'
|
||||
#database
|
||||
gem 'mini_magick'
|
||||
gem 'mongoid', '> 2.1', '< 3.0.0'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Admin::ModuleStoreController < OrbitBackendController
|
||||
|
||||
before_filter :check_central_server_connection
|
||||
@@store = STORE_CONFIG[:store_settings]["url"]
|
||||
|
||||
def index
|
||||
|
@ -85,7 +85,7 @@ class Admin::ModuleStoreController < OrbitBackendController
|
|||
protected
|
||||
|
||||
def get_extensions
|
||||
extensions = JSON.parse(open("#{@@store}/api/extensions").read)
|
||||
extensions = JSON.parse(open("#{@@store}/extensions").read)
|
||||
|
||||
exist_exts = []
|
||||
ext_file = File.new("#{Rails.root}/downloaded_extensions.rb", "r")
|
||||
|
@ -112,7 +112,7 @@ class Admin::ModuleStoreController < OrbitBackendController
|
|||
end
|
||||
|
||||
def get_extension(id)
|
||||
JSON.parse(open("#{@@store}/api/extensions/#{id}").read)
|
||||
JSON.parse(open("#{@@store}/extensions/#{id}").read)
|
||||
end
|
||||
|
||||
def get_downloaded_extension
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class Admin::RegisterSiteController < OrbitBackendController
|
||||
def index
|
||||
end
|
||||
|
||||
def register_site
|
||||
site = Site.first
|
||||
site.register_site
|
||||
redirect_to admin_module_store_path
|
||||
end
|
||||
end
|
|
@ -147,13 +147,6 @@ class Admin::SitesController < OrbitBackendController
|
|||
render :text => "success"
|
||||
end
|
||||
|
||||
def generate_site_token
|
||||
begin
|
||||
self.site_token = SecureRandom.uuid.gsub('-','')
|
||||
self.save
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def update_design(design)
|
||||
|
|
|
@ -480,10 +480,10 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def check_central_server_connection
|
||||
site = Site.first
|
||||
if site.site_token?
|
||||
if @site.site_token?
|
||||
flash[:notice]="Connected to the Store"
|
||||
else
|
||||
redirect_to admin_register_site_index_path
|
||||
flash[:notice]="To Access the Store Please Connect It"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -98,10 +98,17 @@ class Site
|
|||
end
|
||||
|
||||
def generate_site_token
|
||||
begin
|
||||
if self.site_token.nil?
|
||||
self.site_token = SecureRandom.uuid.gsub('-','')
|
||||
self.save
|
||||
end
|
||||
end
|
||||
|
||||
def register_site
|
||||
api_key = STORE_CONFIG[:store_settings]["api_key"]
|
||||
self.generate_site_token
|
||||
store = Store.new(self.id.to_s,self.site_token,api_key)
|
||||
store.post_client(self.id.to_s,self.site_token,self.name)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<%= link_to "Register", register_site_admin_register_site_index_path, :class => "btn btn-primary"%>
|
|
@ -220,6 +220,7 @@ Orbit::Application.routes.draw do
|
|||
get 'update_orbit'
|
||||
get 'restart_server'
|
||||
end
|
||||
match 'sites/register_site' => "sites#register_site"
|
||||
|
||||
resources :tags do
|
||||
collection do
|
||||
|
@ -271,6 +272,12 @@ Orbit::Application.routes.draw do
|
|||
match 'template_store' => 'template_store#index'
|
||||
match 'template_store/download_theme' => "template_store#download_theme"
|
||||
match 'template_store/template/:id' => 'template_store#show', :as => :template_store_template
|
||||
|
||||
resources :register_site, only: [:index] do
|
||||
collection do
|
||||
post 'register_site'
|
||||
end
|
||||
end
|
||||
# match 'template_store/cool_method' => "template_store#cool_method"
|
||||
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
store_settings:
|
||||
url: "http://store.tp.rulingcom.com"
|
||||
api_key: "cc6ae8d0aa0a730792cf519225c40099"
|
||||
url: "http://192.168.1.250:3000/api"
|
||||
api_key: 'Token token="b38ba5f588a7c5072e88ee15737a4d33"'
|
||||
|
|
42
lib/store.rb
42
lib/store.rb
|
@ -1,9 +1,41 @@
|
|||
require 'httparty'
|
||||
class Store
|
||||
include HTTParty
|
||||
base_uri 'http://localhost:3000'
|
||||
|
||||
def post(text)
|
||||
options = { :body => {:status => text}, :token => @auth }
|
||||
self.class.post('/api/clients', options)
|
||||
end
|
||||
format :json
|
||||
base_uri STORE_CONFIG[:store_settings]["url"]
|
||||
|
||||
def initialize(site_id,site_token,api_key)
|
||||
@options_for_get = {
|
||||
headers: {
|
||||
"Authorization" => api_key,
|
||||
"X_SiteToken" => site_token,
|
||||
"X_SiteId" => site_id,
|
||||
"Content-Type" => "application/json"
|
||||
}
|
||||
}
|
||||
|
||||
@options_for_client = {
|
||||
headers: {
|
||||
"Authorization" => api_key,
|
||||
"Content-Type" => "application/json"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def templates(options={})
|
||||
options = @options_for_get
|
||||
response = self.class.get('/templates', options)
|
||||
puts response.request.last_uri.to_s
|
||||
end
|
||||
|
||||
def extensions(options={})
|
||||
options = @options_for_get
|
||||
self.class.get('/extensions', options)
|
||||
end
|
||||
|
||||
def post_client(site_id,site_token,site_name)
|
||||
options = @options_for_client.merge({ :body => {:site_name => site_name, :site_id => site_id, :site_token => site_token}.to_json })
|
||||
self.class.post('/clients', options )
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue