Add. Use params in pin_number.lua (#2112)

This commit is contained in:
Alexey Melnichuk
2016-11-21 13:54:19 -07:00
committed by FusionPBX
parent be35f689c3
commit 7a51e1e2be
+16 -12
View File
@@ -45,9 +45,12 @@
sounds_dir = session:getVariable("sounds_dir"); sounds_dir = session:getVariable("sounds_dir");
--connect to the database --connect to the database
if (pin_number == "database") then local Database = require "resources.functions.database";
require "resources.functions.database_handle"; dbh = Database.new('system');
dbh = database_handle('system');
--include json library
if (debug["sql"]) then
json = require "resources.functions.lunajson"
end end
end end
@@ -66,12 +69,12 @@
--get the domain_name --get the domain_name
domain_name = session:getVariable("domain_name"); domain_name = session:getVariable("domain_name");
--get the domain_uuid using the domain_name --get the domain_uuid using the domain_name
sql = [[SELECT domain_name FROM v_domains local sql = "SELECT domain_name FROM v_domains WHERE domain_name = :domain_name";
WHERE domain_name = ']] .. domain_name ..[[' ]]; local params = {domain_name = domain_name};
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "SQL: "..sql.."\n"); freeswitch.consoleLog("NOTICE", "[pin_number] SQL: "..sql.."; params: " .. json.encode(params) .. "\n");
end end
dbh:query(sql, function(row) dbh:query(sql, params, function(row)
domain_uuid = row["domain_uuid"]; domain_uuid = row["domain_uuid"];
end); end);
end end
@@ -83,15 +86,16 @@
--validate the user pin number --validate the user pin number
if (pin_number == "database") then if (pin_number == "database") then
sql = [[SELECT * FROM v_pin_numbers local sql = [[SELECT * FROM v_pin_numbers
WHERE pin_number = ']] .. digits ..[[' WHERE pin_number = :digits
AND domain_uuid = ']] .. domain_uuid .. [[' AND domain_uuid = :domain_uuid
AND enabled = 'true' ]]; AND enabled = 'true' ]];
local params = {digits = digits, domain_uuid = domain_uuid};
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "SQL: "..sql.."\n"); freeswitch.consoleLog("NOTICE", "[pin_number] SQL: "..sql.."; params: " .. json.encode(params) .. "\n");
end end
auth = false; auth = false;
dbh:query(sql, function(row) dbh:query(sql, params, function(row)
--get the values from the database --get the values from the database
accountcode = row["accountcode"]; accountcode = row["accountcode"];
--set the variable to true --set the variable to true