diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 956c90d0..aab3f86f 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception # lookup domain for db from provision - before_action :check_license, :lookup_domain, :set_locale + before_action :lookup_domain, :set_locale helper_method :current_company,:current_login_employee,:current_user # alias_method :current_user, :current_login_employee,:current_user diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index 1ffc0b2d..cf16adfe 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -1,8 +1,42 @@ class InstallController < BaseController + def index + end - def index + def create + restaurant = params[:restaurant_name] + license_key = params[:license_key] + admin_user = params[:admin_user] + admin_password = params[:admin_password] + end + + def lookup_domain + if request.subdomain.present? && request.subdomain != "www" + @license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) + if (!@license.nil?) + # logger.info "Location - " + @license.name + ActiveRecord::Base.establish_connection(website_connection(@license)) + # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema + else + # reconnect_default_db + logger.info 'License is nil' + # redirect_to root_url(:host => request.domain) + "store_error" + render :json => [{ status: false, message: 'Invalid Access!'}] + end + end end - def create + def current_license(url, key) + @license = License.new(url, key) + + ##creating md5 hash + md5_hostname = Digest::MD5.new + md5key = md5_hostname.update(request.host) + if (@license.detail_with_local_cache(key, md5key.to_s) == true) + #if (@license.detail == true) + + return @license + else + return nil + end end end diff --git a/app/controllers/settings/shops_controller.rb b/app/controllers/settings/shops_controller.rb new file mode 100644 index 00000000..25c8456d --- /dev/null +++ b/app/controllers/settings/shops_controller.rb @@ -0,0 +1,76 @@ +class Settings::ShopsController < ApplicationController + load_and_authorize_resource except: [:create] + before_action :set_shop, only: [:show, :edit, :update] + + # GET /settings/shops + # GET /settings/shops.json + def index + @settings_shops = Shop.all + end + + # GET /settings/shops/1 + # GET /settings/shops/1.json + def show + end + + # GET /settings/shops/new + def new + @settings_shop = Shop.new + end + + # GET /settings/shops/1/edit + def edit + end + + # POST /settings/shops + # POST /settings/shops.json + def create + @settings_shop = Shop.new(shop_params) + respond_to do |format| + if @settings_shop.save + format.html { redirect_to settings_shops_url, notice: 'Shop was successfully created.' } + format.json { render :index, status: :created, location: @settings_shop } + else + format.html { render :new } + format.json { render json: settings_shops_url.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /settings/shops/1 + # PATCH/PUT /settings/shops/1.json + def update + respond_to do |format| + if @settings_shop.update(shop_params) + format.html { redirect_to settings_shops_url, notice: 'Shop was successfully updated.' } + format.json { render :index, status: :ok, location: @settings_shop } + else + format.html { render :edit } + format.json { render json: settings_shops_url.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /settings/shops/1 + # DELETE /settings/shops/1.json + def destroy + @settings_shop.destroy + flash[:notice] = 'Shop was successfully destroyed.' + render :json => {:status=> "Success", :url => settings_shops_url }.to_json + # respond_to do |format| + # format.html { redirect_to settings_shops_url, notice: 'shop was successfully destroyed.' } + # format.json { head :no_content } + # end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_shop + @settings_shop = Shop.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def shop_params + params.require(:shop).permit(:name,:address,:city,:township,:state,:country,:phone_no,:reservation_no,:license,:activated_at,:license_data,:base_currency,:cloud_token,:cloud_url,:owner_token,:id_prefix,:is_rounding_adj,:quick_sale_summary,:calc_tax_order) + end +end diff --git a/app/models/AESEncDec.rb b/app/models/AESEncDec.rb index 54afbe1a..ec84dcb7 100644 --- a/app/models/AESEncDec.rb +++ b/app/models/AESEncDec.rb @@ -5,11 +5,27 @@ require 'uri' class AESEncDec { cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc") - def encrypt + def export_key + ENV['aes_key'] = cipher.key = cipher.random_key # stores the key in key, and also sets the generated key on the cipher + ENV['aes_iv'] = cipher.iv = cipher.random_iv # stores the iv in iv, and also sets the generated iv on the cipher + end + + def encrypt(data) cipher.encrypt + cipher.key = ENV["aes_key"] + cipher.iv = ENV["aes_iv"] + encrypted = cipher.update(data) + cipher.final + encrypted = Base64.urlsafe_encode64(encrypted) + return encrypted end def decrypt + cipher.decrypt + cipher.key = ENV["aes_key"] + cipher.iv = ENV["aes_iv"] + # Start the decryption + decoded = Base64.urlsafe_decode64(encrypted) + decrypted = cipher.update(decoded) + cipher.final end } \ No newline at end of file diff --git a/app/models/license.rb b/app/models/license.rb index b7e2a9bb..d7c23fbf 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -50,7 +50,7 @@ class License if cache_license.nil? ##change the d/e key # @options = { query: {device: "SXlite", lookup: lookup, skey: @secret, token: SECRETS_CONFIG['provision_key']} } - @params = { query: { device: "SXlite", token: SECRETS_CONFIG['provision_key']} } + @params = { query: { device: "SXlite", token: SECRETS_CONFIG['license_key']} } response = self.class.get("/request_license", @params) @license = response.parsed_response diff --git a/app/models/shop.rb b/app/models/shop.rb index 24f4bc1e..9e8217df 100755 --- a/app/models/shop.rb +++ b/app/models/shop.rb @@ -1,4 +1,3 @@ class Shop < ApplicationRecord - end diff --git a/app/views/install/_form.html.erb b/app/views/install/_form.html.erb index e1b78851..288c431a 100755 --- a/app/views/install/_form.html.erb +++ b/app/views/install/_form.html.erb @@ -1,17 +1,36 @@ -