Admin Confirmation Code

This commit is contained in:
Saurabh Bhatia 2014-03-03 15:22:40 +08:00
parent 2dbcc791f9
commit 13481a4fbd
3 changed files with 62 additions and 11 deletions

View File

@ -1,3 +1,6 @@
require "net/http"
require "uri"
require 'json'
class ClientsController < ApplicationController
before_action :set_client, only: [:show, :edit, :update, :destroy]
before_filter :authenticate_user!, except: [:confirm_client, :post_confirmation, :resend_confirmation, :reconfirm_client]
@ -24,12 +27,19 @@ class ClientsController < ApplicationController
def confirm_client
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
if client.first[:success].eql?("true")
if client[:success].eql?("true")
flash[:notice] = "You have confirmed successfully"
else
flash[:notice] = "Error in confirmation please try again."
end
# render :json => client.to_json
end
def resend_confirmation
@ -85,7 +95,30 @@ class ClientsController < ApplicationController
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
# Use callbacks to share common setup or constraints between actions.
def set_client
@client = Client.find(params[:id])

View File

@ -37,16 +37,20 @@ class Client
end
end
def self.confirm_email(confirmation_token)
client = self.find_by(confirmation_token: confirmation_token) rescue nil
token_status = client.present?
case token_status
when true
client.confirmation_token = nil
client.save
return [{:success => "true"}]
when false
return [{:success => "false"}]
def self.confirm_email(confirmation_token = nil)
if confirmation_token
client = self.find_by(confirmation_token: confirmation_token) rescue nil
token_status = client.present?
case token_status
when true
client.confirmation_token = nil
client.save
return {:success => "true", :id => client.id.to_s}
when false
return {:success => "false"}
end
else
return {:success => "false"}
end
end
end

View File

@ -77,4 +77,18 @@ Mtstore::Application.configure do
# Use default logging formatter so that PID and timestamp are not suppressed.
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