diff --git a/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_replies_controller.rb b/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_replies_controller.rb index 9f1374bcd..743520dba 100644 --- a/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_replies_controller.rb +++ b/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_replies_controller.rb @@ -38,45 +38,32 @@ class Panel::Ask::BackEnd::AskRepliesController < OrbitBackendController require 'net/http' require 'uri' require 'json' - - uri_path = "/panel/ask/back_end/ask_requests/auth_request" + + uri_path = "/panel/ask/back_end/ask_requests/transfer_request" uri = URI.parse("http://" + dep_dns + uri_path) - - body = { - 'auth_token' => '3kjlfksjDFJ' - } - http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri) + body = { + # 'auth_token' => '3kjlfksjDFJ', + 'name' => current_question.name, + 'title' => current_question.title, + 'identity' => current_question.identity, + 'email' => current_question.email, + 'phone' => current_question.phone, + 'tax' => current_question.tax, + 'content' => current_question.content, + } request.set_form_data(body) + request.add_field 'X-Auth-Token', '3kjlfksjDFJ' response = http.request(request) - puts "Response #{response.code} #{response.message}: #{response.body}" - - if response.code == "200" - uri_path = "/panel/ask/back_end/ask_requests/transfer_request" - uri = URI.parse("http://" + dep_dns + uri_path) - http = Net::HTTP.new(uri.host, uri.port) - request = Net::HTTP::Post.new(uri.request_uri) - body = { - 'name' => current_question.name, - 'title' => current_question.title, - 'identity' => current_question.identity, - 'email' => current_question.email, - 'phone' => current_question.phone, - 'tax' => current_question.tax, - 'content' => current_question.content, - } - request.set_form_data(body) - response = http.request(request) - - if response.code != "200" - new_status = "轉介其他單位" + "(" + response.code + ")" - current_reply.update_attributes(status: new_status) - else - new_status = "轉介其他單位" + "(" + "success!" + ")" - current_reply.update_attributes(status: new_status) - end - end + # binding.pry + if response.code != "200" + new_status = "轉介其他單位" + "(" + response.code + ")" + current_reply.update_attributes(status: new_status) + else + new_status = "轉介其他單位" + "(" + "success!" + ")" + current_reply.update_attributes(status: new_status) + end puts "Response #{response.code} #{response.message}: #{response.body}" # flash[:notice] = response.body diff --git a/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_requests_controller.rb b/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_requests_controller.rb index eff47c5ff..ce98c0a98 100644 --- a/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_requests_controller.rb +++ b/vendor/built_in_modules/ask_new/app/controllers/panel/ask/back_end/ask_requests_controller.rb @@ -1,35 +1,33 @@ # encoding: utf-8 class Panel::Ask::BackEnd::AskRequestsController < OrbitBackendController - include AdminHelper include OrbitControllerLib::DivisionForDisable - - def auth_request - render :json => "#{params}" - end - + # skip_before_filter :verify_authenticity_token + def transfer_request - - if !AskCategory.where(key: "transfered_question").any? - @ask_category = AskCategory.new(name: "transfered_question", key: "transfered_question") - @ask_category.save! + + if request.headers["HTTP_X_AUTH_TOKEN"] == '3kjlfksjDFJ' + if !AskCategory.where(key: "transfered_question").any? + @ask_category = AskCategory.new(name: "transfered_question", key: "transfered_question") + @ask_category.save! + end + category = AskCategory.where(key: "transfered_question") + @transfered_question = AskQuestion.new( + name: params['name'], + identity: params['identity'], + email: params['email'], + phone: params['phone'], + tax: params['tax'], + title: params['title'], + content: params['content'], + ask_category_id: category.first.id) + @transfered_question.ask_reply = AskReply.new + @transfered_question.ask_reply.update_attributes(status: "待處理(轉)") + @transfered_question.save + render :nothing => true + else + render :status => 500 end - category = AskCategory.where(key: "transfered_question") - - @transfered_question = AskQuestion.new( - name: params['name'], - identity: params['identity'], - email: params['email'], - phone: params['phone'], - tax: params['tax'], - title: params['title'], - content: params['content'], - ask_category_id: category.first.id) - @transfered_question.ask_reply = AskReply.new - @transfered_question.ask_reply.update_attributes(status: "待處理(轉)") - @transfered_question.save - - render :json => "#{params}" end end \ No newline at end of file