license renew page

This commit is contained in:
Zin Moe
2020-06-04 10:10:04 +06:30
parent da75403437
commit bd18958b96
16 changed files with 181 additions and 55 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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"]

View File

@@ -59,7 +59,8 @@
</p>
<% end %>
<% end %>
<% end %>
<% end %>
<%= render 'shared/license_expire_warning' %>
<%= yield %>
</section>
</body>

View File

@@ -53,6 +53,7 @@
<%= message %>
</div>
<% end %>
<%= render 'shared/license_expire_warning' %>
<%= yield %>
</section>
</body>

View File

@@ -56,7 +56,8 @@
<p id="notify_message" class="hidden" data-placement-from="top" data-message="<%=message%>" data-placement-align="center"
data-animate-enter="" data-animate-exit="" data-color-name="<%=color%>" >
</p>
<% end %>
<% end %>
<%= render 'shared/license_expire_warning' %>
<%= yield %>
</section>
</body>

View File

@@ -51,7 +51,8 @@
</div>
<% end %>
<% end %>
<% end %>
<%= render 'shared/license_expire_warning' %>
<%= yield %>
</section>
</body>

View File

@@ -60,6 +60,7 @@
data-animate-enter="" data-animate-exit="" data-color-name="<%=color%>" >
</p>
<% end %>
<%= render 'shared/license_expire_warning' %>
<%= yield %>
</section>
</body>

View File

@@ -22,6 +22,7 @@
<%= message %>
</div>
<% end %>
<%= render 'shared/license_expire_warning' %>
<%= yield %>
</div>

View File

@@ -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
%>
<div class="container-fluid">
<div class="row">
<div class="col-sm-2"></div>
<div class="card col-md-8 h-100" style="padding-left: 60px;">
<div class="card-block">
<h3 class="pt-2 d-inline">Renew Your License</h3>
<%= link_to origami_dashboard_url do %>
<img src="/image/logo.png" style="margin-left: 25pc; width: 150px">
<% end %>
<% if params[:message].present?
if params[:status].to_i == 1
color = 'text-success'
else
color = 'text-danger'
end
%>
<p class="<%= color %> m-t--30" style="font-weight: bold; font-size: 18px;"><%= params[:message] %></p><br>
<% end %>
<% if text %>
<h6 class="mb-2 "><%= text %></h6><br>
<% end %>
<h6 class="mb-2">Call Center Phone No: <a href="tel:+6494461709">+959 445 665 311</a></h6>
<br>
<h6>License Info:</h6>
<br>
<div class="container">
<div class="form-group row">
<label class="card-subtitle mb-2 col-md-4">Business Name:</label>
<label class="card-subtitle mb-2 "><strong><%= @bis_name %></strong></label>
</div>
<div class="form-group row">
<label class="card-subtitle mb-2 col-md-4">Plan:</label>
<label class="card-subtitle mb-2 "><strong><%= @plan %></strong></label>
</div>
</div>
<div class="form-group row">
<label class="card-subtitle mb-2 col-md-4 pl-4">Expired At: </label>
<label class="card-subtitle mb-2 "><strong><%= @expired_at.to_date.strftime('%B %d, %Y') %></strong></label>
</div>
</div>
<div class="col-md-12" style="padding-bottom: 20px;">
<%= 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' %>
<button onclick="history.back();" type='button' class="btn btn-lg btn-default float-right">Cancel</button>
</div>
</div>
<div class="col-sm-2"></div>
</div>
</div>
<script>
$(document).ready(function() {
$('.alert-warning, .navbar').hide()
$('html, section').css('background-color', '#61B8C9')
$('html').css('overflow-x', 'hidden')
$('section.content').css('margin', '70px 0 0 0')
})
</script>

View File

@@ -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 %>
<div class="alert alert-warning fade show" role="alert" style="margin-top: -15px;">
<strong style="margin-left: 40px !important"><%= text %></strong>
<%= link_to 'Renew License', expire_url, class: 'btn btn-sm btn-primary', style: "margin-left: 40px !important"%>
<button type="button" class="close" data-dismiss="alert" aria-label="Close" style="padding-top: 5px;">
<span aria-hidden="true" class="text-white">&times;</span>
</button>
</div>
<% end %>