Created
March 28, 2012 17:27
-
-
Save jonmarkgo/2228441 to your computer and use it in GitHub Desktop.
Twilio Phone Verification Blog Post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="enter_number"> | |
<p>Enter your phone number:</p> | |
<p><input type="text" name="phone_number" id="phone_number" /></p> | |
<p><input type="submit" name="submit" value="Verify" /></p> | |
</form> | |
<div id="verify_code" style="display: none;"> | |
<p>Calling you now.</p> | |
<p>When prompted, enter the verification code:</p> | |
<h1 id="verification_code"></h1> | |
<p><strong id="status">Waiting...</strong></p> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkStatus() { | |
$.post("status.php", { phone_number : $("#phone_number").val() }, | |
function(data) { updateStatus(data.status); }, "json"); | |
} | |
function updateStatus(current) { | |
if (current === "unverified") { | |
$("#status").append("."); | |
setTimeout(checkStatus, 3000); | |
} | |
else { | |
success(); | |
} | |
} | |
function success() { | |
$("#status").text("Verified!"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
$("#enter_number").submit(function(e) { | |
e.preventDefault(); | |
initiateCall(); | |
}); | |
}); | |
function initiateCall() { | |
$.post("call.php", { phone_number : $("#phone_number").val() }, | |
function(data) { showCodeForm(data.verification_code); }, "json"); | |
checkStatus(); | |
} | |
function showCodeForm(code) { | |
$("#verification_code").text(code); | |
$("#verify_code").fadeIn(); | |
$("#enter_number").fadeOut(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment