test for registered site

This commit is contained in:
Harry Bomrah 2014-10-28 16:57:06 +08:00
parent 8e44b7c3a8
commit 727d775d7b
2 changed files with 36 additions and 15 deletions

View File

@ -13,18 +13,17 @@ class Admin::RegisterApiController < ApplicationController
site.admin_email = email site.admin_email = email
site.generate_confirmation_token site.generate_confirmation_token
site.save site.save
if register_client_site(site.site_token) response["success"] = true
response["success"] = true
send_confirmation_email(site.admin_email, site.confirmation_token, site.site_token)
else
response["message"] = "Invalid site token."
response["error"] = "INVALID_SITE_TOKEN"
end
else else
response["message"] = "Site already registered." response["message"] = "Site already registered."
response["error"] = "SITE_ALREADY_REGISTERED" response["error"] = "SITE_ALREADY_REGISTERED"
end end
render :json => response.to_json render :json => response.to_json
if !site.nil?
p1 = fork {register_client_site(site.site_token) }
Process.detach(p1)
end
end end
def send_confirmation_email(email, confirmation_token, site_token) def send_confirmation_email(email, confirmation_token, site_token)
@ -33,6 +32,17 @@ class Admin::RegisterApiController < ApplicationController
email.deliver email.deliver
end end
def send_email
site_token = params[:store_token]
site = RegisteredSite.find_by(:uid => site_token) rescue nil
if !site.nil?
send_confirmation_email(site.admin_email, site.confirmation_token, site.site_token)
render :json => {"success" => true}.to_json
else
render :json => {"success" => false}.to_json
end
end
def check_permissions def check_permissions
response = {} response = {}
response["success"] = false response["success"] = false
@ -42,7 +52,7 @@ class Admin::RegisterApiController < ApplicationController
response["message"] = "Invalid site token." response["message"] = "Invalid site token."
response["error"] = "INVALID_SITE_TOKEN" response["error"] = "INVALID_SITE_TOKEN"
elsif !site.site_confirmed elsif !site.site_confirmed
response["message"] = "Site not confirmed, please confirm the email sent to #{site.admin_email} to proceed." response["message"] = "Site not confirmed, please confirm the email, sent to #{site.admin_email} to proceed."
response["error"] = "SITE_NOT_CONFIRMED" response["error"] = "SITE_NOT_CONFIRMED"
elsif !site.access_granted elsif !site.access_granted
response["message"] = "Store permissions reovked." response["message"] = "Store permissions reovked."
@ -60,12 +70,12 @@ class Admin::RegisterApiController < ApplicationController
request = Net::HTTP::Post.new("/store/confirmation") request = Net::HTTP::Post.new("/store/confirmation")
request.body = params_to_send.to_query request.body = params_to_send.to_query
response = http.request(request) response = http.request(request)
data = JSON.parse(response.body) # data = JSON.parse(response.body)
if data["success"] == true # if data["success"] == true
return true # return true
else # else
return false # return false
end # end
end end
def confirm_email def confirm_email
@ -83,3 +93,12 @@ class Admin::RegisterApiController < ApplicationController
end end
end end
# if
# response["success"] = true
# # send_confirmation_email(site.admin_email, site.confirmation_token, site.site_token)
# else
# response["message"] = "Invalid site token."
# response["error"] = "INVALID_SITE_TOKEN"
# end

View File

@ -0,0 +1,2 @@
<p>Thank you for registering your site with Orbit! Please click on the following link and confirm. This is to make sure we could provide you with a spam free experience. Thanks a lot.</p>
<a href="<%= @data['url'] %>" > Please click to confirm </a>