Add max tries to pin_number.lua so that if the pin number is wrong it will request the pin number again up to the maximum tries.

This commit is contained in:
Mark Crane 2014-10-21 05:48:27 +00:00
parent 34a4ddb878
commit 1c63e46608
1 changed files with 41 additions and 27 deletions

View File

@ -22,8 +22,10 @@
-- Contributor(s):
-- Mark J Crane <markjcrane@fusionpbx.com>
max_tries = "3";
digit_timeout = "5000";
max_tries = 3;
digit_timeout = 5000;
max_retries = 3;
tries = 0;
function trim (s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
@ -39,6 +41,41 @@ function explode ( seperator, str )
return arr
end
function check_pin_number()
--sleep
session:sleep(500);
--increment the number of tries
tries = tries + 1;
--get the user pin number
min_digits = 2;
max_digits = 20;
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
--validate the user pin number
pin_number_table = explode(",",pin_number);
for index,pin_number in pairs(pin_number_table) do
if (digits == pin_number) then
--set the variable to true
auth = true;
--set the authorized pin number that was used
session:setVariable("pin_number", pin_number);
--end the loop
break;
end
end
--if not authorized play a message and then hangup
if (not auth) then
if (tries < max_tries) then
session:streamFile("phrase:voicemail_fail_auth:#");
check_pin_number();
else
session:streamFile("phrase:voicemail_fail_auth:#");
session:hangup("NORMAL_CLEARING");
return;
end
end
end
if ( session:ready() ) then
session:answer( );
pin_number = session:getVariable("pin_number");
@ -67,29 +104,6 @@ if ( session:ready() ) then
--if the pin number is provided then require it
if (pin_number) then
--sleep
session:sleep(500);
--get the user pin number
min_digits = 2;
max_digits = 20;
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
--validate the user pin number
pin_number_table = explode(",",pin_number);
for index,pin_number in pairs(pin_number_table) do
if (digits == pin_number) then
--set the variable to true
auth = true;
--set the authorized pin number that was used
session:setVariable("pin_number", pin_number);
--end the loop
break;
end
end
--if not authorized play a message and then hangup
if (not auth) then
session:streamFile("phrase:voicemail_fail_auth:#");
session:hangup("NORMAL_CLEARING");
return;
end
check_pin_number();
end
end
end