Admin Confirmation Code
This commit is contained in:
parent
2dbcc791f9
commit
13481a4fbd
|
@ -1,3 +1,6 @@
|
||||||
|
require "net/http"
|
||||||
|
require "uri"
|
||||||
|
require 'json'
|
||||||
class ClientsController < ApplicationController
|
class ClientsController < ApplicationController
|
||||||
before_action :set_client, only: [:show, :edit, :update, :destroy]
|
before_action :set_client, only: [:show, :edit, :update, :destroy]
|
||||||
before_filter :authenticate_user!, except: [:confirm_client, :post_confirmation, :resend_confirmation, :reconfirm_client]
|
before_filter :authenticate_user!, except: [:confirm_client, :post_confirmation, :resend_confirmation, :reconfirm_client]
|
||||||
|
@ -24,12 +27,19 @@ class ClientsController < ApplicationController
|
||||||
|
|
||||||
def confirm_client
|
def confirm_client
|
||||||
client = Client.confirm_email(params[:token])
|
client = Client.confirm_email(params[:token])
|
||||||
|
if client[:success].eql?("true")
|
||||||
|
pass = confirm_client_site(client[:id])
|
||||||
|
if !pass
|
||||||
|
client[:success] = "false"
|
||||||
|
end
|
||||||
|
end
|
||||||
redirect_to post_confirmation_clients_path
|
redirect_to post_confirmation_clients_path
|
||||||
if client.first[:success].eql?("true")
|
if client[:success].eql?("true")
|
||||||
flash[:notice] = "You have confirmed successfully"
|
flash[:notice] = "You have confirmed successfully"
|
||||||
else
|
else
|
||||||
flash[:notice] = "Error in confirmation please try again."
|
flash[:notice] = "Error in confirmation please try again."
|
||||||
end
|
end
|
||||||
|
# render :json => client.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def resend_confirmation
|
def resend_confirmation
|
||||||
|
@ -85,7 +95,30 @@ class ClientsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def confirm_client_site(client_id = nil)
|
||||||
|
if client_id
|
||||||
|
client = Client.find(client_id)
|
||||||
|
url = client.url + "/store_confirmation/confirm?site_token=#{client.site_token}"
|
||||||
|
uri = URI.parse(url)
|
||||||
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
|
request = Net::HTTP::Post.new(uri.request_uri)
|
||||||
|
request.set_form_data({:site_token => client.site_token})
|
||||||
|
response = http.request(request)
|
||||||
|
success = response.body
|
||||||
|
success = JSON.parse(success)
|
||||||
|
if success["success"] == "true"
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_client
|
def set_client
|
||||||
@client = Client.find(params[:id])
|
@client = Client.find(params[:id])
|
||||||
|
|
|
@ -37,16 +37,20 @@ class Client
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.confirm_email(confirmation_token)
|
def self.confirm_email(confirmation_token = nil)
|
||||||
client = self.find_by(confirmation_token: confirmation_token) rescue nil
|
if confirmation_token
|
||||||
token_status = client.present?
|
client = self.find_by(confirmation_token: confirmation_token) rescue nil
|
||||||
case token_status
|
token_status = client.present?
|
||||||
when true
|
case token_status
|
||||||
client.confirmation_token = nil
|
when true
|
||||||
client.save
|
client.confirmation_token = nil
|
||||||
return [{:success => "true"}]
|
client.save
|
||||||
when false
|
return {:success => "true", :id => client.id.to_s}
|
||||||
return [{:success => "false"}]
|
when false
|
||||||
|
return {:success => "false"}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return {:success => "false"}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -77,4 +77,18 @@ Mtstore::Application.configure do
|
||||||
|
|
||||||
# Use default logging formatter so that PID and timestamp are not suppressed.
|
# Use default logging formatter so that PID and timestamp are not suppressed.
|
||||||
config.log_formatter = ::Logger::Formatter.new
|
config.log_formatter = ::Logger::Formatter.new
|
||||||
|
|
||||||
|
config.action_mailer.default_url_options = { :host => 'store.tp.rulingcom.com' }
|
||||||
|
config.action_mailer.delivery_method = :smtp
|
||||||
|
config.action_mailer.perform_deliveries = true
|
||||||
|
config.action_mailer.raise_delivery_errors = true
|
||||||
|
config.action_mailer.smtp_settings = {
|
||||||
|
:enable_starttls_auto => true,
|
||||||
|
:address => 'smtp.gmail.com',
|
||||||
|
:port => '587',
|
||||||
|
:domain => "store.tp.rulingcom.com",
|
||||||
|
:authentication => "plain",
|
||||||
|
:user_name => "service@rulingcom.com",
|
||||||
|
:password => "bjo4xjp6"
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue