From bd18958b96e0d9e55bee95c382b911037076635c Mon Sep 17 00:00:00 2001 From: Zin Moe Date: Thu, 4 Jun 2020 10:10:04 +0630 Subject: [PATCH] license renew page --- Gemfile.lock | 2 - app/controllers/install_controller.rb | 53 +++++++------- app/controllers/renew_license_controller.rb | 17 +++++ app/helpers/application_helper.rb | 4 +- app/models/license.rb | 15 ++-- app/views/layouts/CRM.html.erb | 3 +- app/views/layouts/OQS.html.erb | 1 + app/views/layouts/application.html.erb | 3 +- app/views/layouts/inventory.html.erb | 3 +- app/views/layouts/origami.html.erb | 1 + app/views/layouts/waiter.html.erb | 1 + app/views/renew_license/expire.html.erb | 72 +++++++++++++++++++ .../shared/_license_expire_warning.html.erb | 21 ++++++ config/license.yml | 30 ++++---- config/routes.rb | 3 + config/shops.json | 7 ++ 16 files changed, 181 insertions(+), 55 deletions(-) create mode 100644 app/controllers/renew_license_controller.rb create mode 100644 app/views/renew_license/expire.html.erb create mode 100644 app/views/shared/_license_expire_warning.html.erb diff --git a/Gemfile.lock b/Gemfile.lock index f56a2d36..4cdc2ded 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -96,7 +96,6 @@ GEM concurrent-ruby (1.1.5) connection_pool (2.2.2) crass (1.0.5) - cups (0.0.7) database_cleaner (1.7.0) diff-lcs (1.3) erubi (1.9.0) @@ -335,7 +334,6 @@ DEPENDENCIES carrierwave (~> 1.0) chartkick coffee-rails (~> 4.2) - cups (~> 0.0.7) database_cleaner factory_girl_rails (~> 4.0) faker diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index 1ff003db..594c99ea 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -1,7 +1,6 @@ class InstallController < BaseController - skip_before_action :lookup_domain + # skip_before_action :set_current_tenant_by_subdomain_or_name skip_before_action :verify_authenticity_token - # before_action :check_license def index end @@ -9,7 +8,7 @@ class InstallController < BaseController def activate flag = "<%= ENV['AES_IV'] %>" key_base = "<%= ENV['secret_key_base'] %>" - + restaurant = params[:restaurant_name] license_key = params[:license_key] # admin_user = params[:admin_user] @@ -18,20 +17,20 @@ class InstallController < BaseController db_schema = params[:db_schema] db_user = params[:db_user] db_password = params[:db_password] - phrase = license_key - + phrase = license_key + # Check Exists IV # if flag == "<%= ENV['AES_IV'] %>" - # # Export for Key - # aes = MyAesCrypt.new + # # Export for Key + # aes = MyAesCrypt.new # aes_key, aes_iv = aes.export_key(phrase) - # else + # else # aes_key = ENV["AES_KEY"] # aes_iv = ENV["AES_IV"] # end - @license = License.new(ENV["SX_PROVISION_URL"]) - response = @license.license_activate(restaurant, license_key, db_host, db_schema, db_user, db_password) + @license = License.new(ENV["SX_PROVISION_URL"], request.host) + response = @license.license_activate(restaurant, license_key, db_host, db_schema, db_user, db_password) if response[:status] redirect_to root_url, notice: response["message"] else @@ -39,28 +38,24 @@ class InstallController < BaseController end end - def check_license - if License.check_license_file - redirect_to root_url + def lookup_domain + if ENV["SERVER_MODE"] == "cloud" + not_found + elsif ENV["SERVER_MODE"] == "application" + if check_license #(request.host) + redirect_to root_url + end + elsif request.subdomains.last && request.subdomains.last != "www" + if check_license #(request.host) + redirect_to root_url + elsif !check_subdomain(request.host) + not_found + end + else + not_found end 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 current_license(url, key) # @license = License.new(url, key) diff --git a/app/controllers/renew_license_controller.rb b/app/controllers/renew_license_controller.rb new file mode 100644 index 00000000..7ef245fe --- /dev/null +++ b/app/controllers/renew_license_controller.rb @@ -0,0 +1,17 @@ +class RenewLicenseController < ApplicationController + + def expire + @license = current_license + @plan = @license.read_license("plan_name") + @bis_name = @license.read_license_no_decrypt("shop_name") + @expired_at = @license.read_license("renewable_date") + @license_status = @license.detail_with_local_file + end + + def renew + status, message = current_license.verify_license + + redirect_to expire_url(message: message, status: status) + end + +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 16e44953..93664fef 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5,8 +5,8 @@ module ApplicationHelper case level when :notice then "alert alert-info fade-in" when :success then "alert alert-success fade-in" - when :error then "alert alert-error fade-in" - when :alert then "alert alert-error fade-in" + when :error then "alert alert-warning fade-in" + when :alert then "alert alert-danger fade-in" end end diff --git a/app/models/license.rb b/app/models/license.rb index e1129405..5335d6c4 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -78,7 +78,7 @@ class License def detail_with_local_file if expired? return 0 - elsif expire_in(30)? + elsif expire_in?(10) return 2 else return 1 @@ -151,15 +151,23 @@ class License def verify_license api_token = read_license_no_decrypt("api_token") @params = { query: {lookup_type: "application", api_token: api_token} } + old_renewable_date = read_license("renewable_date") begin response = self.class.get("/verify", @params) @varified = response.parsed_response Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s if (@varified["status"]) - if (!check_expired(@varified["renewable_date"])) - return true + if old_renewable_date.to_date == @varified['renewable_date'].to_date + message = "*** License couldn't be verified. ***" + status = 2 + elsif old_renewable_date.to_date < @varified['renewable_date'].to_date + update_license("renewable_date", @varified['renewable_date']) + status = 1 + message = "*** License could be verified. ***" end + return status, message + else delete_license_file end @@ -330,7 +338,6 @@ class License redis = Redis.new cache_shop = redis.get(cache_key) - puts Marshal.load(cache_shop) if !cache_shop.nil? @shop = Marshal.load(cache_shop) key = @shop["key"] diff --git a/app/views/layouts/CRM.html.erb b/app/views/layouts/CRM.html.erb index 955abc98..063080d5 100755 --- a/app/views/layouts/CRM.html.erb +++ b/app/views/layouts/CRM.html.erb @@ -59,7 +59,8 @@

<% end %> <% end %> - <% end %> + <% end %> + <%= render 'shared/license_expire_warning' %> <%= yield %> diff --git a/app/views/layouts/OQS.html.erb b/app/views/layouts/OQS.html.erb index de7c2d14..b8a3058d 100755 --- a/app/views/layouts/OQS.html.erb +++ b/app/views/layouts/OQS.html.erb @@ -53,6 +53,7 @@ <%= message %> <% end %> + <%= render 'shared/license_expire_warning' %> <%= yield %> \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d03889f7..4b30ef25 100755 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -56,7 +56,8 @@ - <% end %> + <% end %> + <%= render 'shared/license_expire_warning' %> <%= yield %> diff --git a/app/views/layouts/inventory.html.erb b/app/views/layouts/inventory.html.erb index fe49647e..4a117634 100755 --- a/app/views/layouts/inventory.html.erb +++ b/app/views/layouts/inventory.html.erb @@ -51,7 +51,8 @@ <% end %> - <% end %> + <% end %> + <%= render 'shared/license_expire_warning' %> <%= yield %> diff --git a/app/views/layouts/origami.html.erb b/app/views/layouts/origami.html.erb index 83081cbf..c3ada661 100755 --- a/app/views/layouts/origami.html.erb +++ b/app/views/layouts/origami.html.erb @@ -60,6 +60,7 @@ data-animate-enter="" data-animate-exit="" data-color-name="<%=color%>" >

<% end %> + <%= render 'shared/license_expire_warning' %> <%= yield %> diff --git a/app/views/layouts/waiter.html.erb b/app/views/layouts/waiter.html.erb index c6cc4d99..6ecfda70 100755 --- a/app/views/layouts/waiter.html.erb +++ b/app/views/layouts/waiter.html.erb @@ -22,6 +22,7 @@ <%= message %> <% end %> + <%= render 'shared/license_expire_warning' %> <%= yield %> diff --git a/app/views/renew_license/expire.html.erb b/app/views/renew_license/expire.html.erb new file mode 100644 index 00000000..67e9fe1a --- /dev/null +++ b/app/views/renew_license/expire.html.erb @@ -0,0 +1,72 @@ +<% renewable_date = current_license.read_license("renewable_date") %> +<% date_count = (renewable_date.to_date - Date.today).to_i %> +<% day = pluralize( date_count, 'day' )%> + +<% if @license_status == 0 + text = 'Your license has been expired.' + elsif @license_status == 2 + text = "Your license will expire in #{day}." + end +%> +
+
+
+ +
+
+

Renew Your License

+ <%= link_to origami_dashboard_url do %> + + <% end %> + <% if params[:message].present? + if params[:status].to_i == 1 + color = 'text-success' + else + color = 'text-danger' + end + %> +

<%= params[:message] %>


+ <% end %> + <% if text %> +
<%= text %>

+ <% end %> +
Call Center Phone No: +959 445 665 311
+
+
License Info:
+
+
+
+ + +
+ +
+ + +
+
+ +
+ + +
+
+ +
+ <%= link_to 'Home', origami_dashboard_url, class: 'btn btn-primary btn-lg' %> + <%= link_to 'Renew License', renew_url, class: 'btn btn-primary btn-lg float-right m-l-5 m-r-5' %> + +
+
+
+
+
+ + diff --git a/app/views/shared/_license_expire_warning.html.erb b/app/views/shared/_license_expire_warning.html.erb new file mode 100644 index 00000000..0949aff7 --- /dev/null +++ b/app/views/shared/_license_expire_warning.html.erb @@ -0,0 +1,21 @@ +<% license_status = current_license.detail_with_local_file %> +<% renewable_date = current_license.read_license("renewable_date") %> +<% date_count = (renewable_date.to_date - Date.today).to_i %> +<% day = pluralize( date_count, 'day' )%> + +<% if license_status == 0 + text = 'Your license has expired.' + elsif license_status == 2 + text = "Your license will expire in #{day}." + end +%> +<% if license_status == 0 || license_status == 2 %> + + +<% end %> \ No newline at end of file diff --git a/config/license.yml b/config/license.yml index f1861562..6148ed67 100644 --- a/config/license.yml +++ b/config/license.yml @@ -1,19 +1,19 @@ --- -'': &1 - iv_key: cHmsbixLckobLPvChZxYog== - shop_name: inyahappy - email: support@code2lab.com +localhost: + iv_key: c5bODYtxFPckKXr3bLPdnQ== + shop_name: scdemo3 + email: hanwintun@code2lab.com telephone: '' fax: '' address: '' - dbhost: T78U5MC1QxdtmrveA3dT5znI93KRZgEDv1YEAJLOBuYhF9Okg6IFGds7o0P2Jw0qRCVBAo2mL9zvqCmZ9sIYCQ== - dbschema: QwNWv33nV+/PI7mQ5vUwYpu7oLDVwCFv6E3xLchwDLM= - dbusername: xObcAQiPi19xCQbc0z5buQ== - dbpassword: UIscqcoVMXn4A/OfHnSU6A== - api_token: oHYLdtqtAAacxqAhTMfdVxCRyEkyxLzKcYY - app_token: qVYAxcvsklHlTMEBzgznEqdBZBPI - plan_sku: j3tTAFpFkYP3DNCHSinzqA== - renewable_date: fjyqVnVXXEoyvOVf1Ksa1Q== - plan_name: a3TIsOfLtnkDpqP/FCTjyk/viicooUnN4DJasj4jSF4= -192.168.1.125: *1 -192.168.43.132: *1 + dbhost: eFiEpFewQVPPylY1pefN2ZIVmxg9v7G1YrnHtNIPIbQQg7WtffKz35uCcOwgwzEvCTPUhPQama4B80FHyTpn3Q== + dbschema: PRMtXnRsDZQjF319ItO7Lw== + dbusername: QYngtMBsTBV/B17XiH5zhQ== + dbpassword: vXsZqV2sJQ+tjIiGBb7N8A== + api_token: UQFLAbMvJxUCnDVCOhIdqYZEGRqVQMvI + app_token: DvRXGlomaBFpGVLYsidekVVZyqosntouTA + plan_sku: AqCfY9X2C03i+XBLnvRz5w== + renewable_date: 'MXf+rRgjWFxIRgpf+Aa4JA== + +' + plan_name: bDYhVmEo9MNZmfIxwxE30BFHUKWTDVkVDnUiE6htM5Y= diff --git a/config/routes.rb b/config/routes.rb index 974a00d4..0507f976 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -29,6 +29,9 @@ scope "(:locale)", locale: /en|mm/ do delete 'logout' => 'home#destroy' get 'dashboard' => 'home#dashboard' + get 'expire' => 'renew_license#expire' + get 'renew' => 'renew_license#renew' + namespace :induties do # resources :assign_in_duties get ':booking_id/assign' => 'assign_in_duties#index', as: :assign_in_duties diff --git a/config/shops.json b/config/shops.json index 0c2cc02d..761a41af 100644 --- a/config/shops.json +++ b/config/shops.json @@ -1049,6 +1049,13 @@ "key": "MdrjwSyyNPqIU+HO3rwsHHSlG6xCKC5y3pQ1ywGbX2k=\n", "iv": "8+fEFUROBPpGp23jrRnb3Q==\n" } + }, + { + "lookup": "localhost", + "value": { + "key": "wyo9gq9KYY0FS1r1+cMmmAGEVGxQ2aTpVjfVYCoC9z4=\n", + "iv": "T2UNnKc4EFLiDiALvjybdg==\n" + } } ] }