/*!login_submit * Internet Captcha * version: 2 (20 Mqy 2013) * Examples at http://www.icaptcha.com * License: CREATIVE COMMONS Attribution-NonCommercial 3.0 Unported * Copyright 2013 David Arroni Castellanos */ function login_submit() { var validate = checking_icaptcha(); console.log(validate); if(validate=='ok=True'){ $('#submit_login').submit(); }else{ alert("Secure Code Invalid"); return; } } function checking_icaptcha() { if (window.XMLHttpRequest) { icaptchaXML = new XMLHttpRequest } else { icaptchaXML = new ActiveXObject("Microsoft.XMLHTTP") } icaptchaXML.open("POST", "/captcha_validate/"); icaptchaXML.onreadystatechange = icaptcha_validate; icaptchaXML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); icaptchaXML.send("code=" + document.getElementById("code").value); str=icaptchaXML.responseText; return str; } function icaptcha_validate() { if (icaptchaXML.readyState == 4) { var e = icaptchaXML.responseText; if (e == "ok=True") { // document.validate.submit() // document.getElementById("login_form").submit(); document.dispatchEvent(new CustomEvent('icaptchaValidated')); } else { alert('Wrong Code'); loadicaptcha(); document.getElementById("code").value = ""; } } } function loadicaptcha() { if (window.XMLHttpRequest) { icaptchaXML = new XMLHttpRequest } else { icaptchaXML = new ActiveXObject("Microsoft.XMLHTTP") } icaptchaXML.open("POST", "/icaptcha/"); icaptchaXML.onreadystatechange = readicaptcha; icaptchaXML.send() } function readicaptcha() { if (icaptchaXML.readyState == 4) { var e; var t; var n = new Array(5); var r = document.getElementById("icaptcha"); var i = document.getElementById("icaptchaId"); var s = r.offsetWidth; var o = r.offsetHeight; i.height = o; i.width = s; icaptchactx.clearRect(0, 0, s, o); var u = icaptchaXML.responseText; var a = u.length / 12; for (e = 0; e < a; e++) { icaptchactx.beginPath(); icaptchactx.lineWidth = icaptchas; icaptchactx.strokeStyle = icaptchac; var f = icaptchag - 5; var l = icaptchag - 35; var c = s / (240 + 2 * icaptchag); var h = o / (60 + 2 * icaptchag); for (t = 0; t < 6; t++) { n[t] = parseInt(u.substr(e * 12 + t * 2, 2), 16) } icaptchactx.moveTo((n[0] + f) * c, (n[1] + l) * h); icaptchactx.quadraticCurveTo((n[4] + f) * c, (n[5] + l) * h, (n[2] + f) * c, (n[3] + l) * h); icaptchactx.stroke() } } } function icaptcha(e, t, n, r, i) { icaptchas = e; icaptchac = t; icaptchat = n; icaptchag = r; icaptchae = i; var i = document.getElementById("icaptcha"); var n = document.createElement("canvas"); n.id = "icaptchaId"; i.appendChild(n); if (typeof G_vmlCanvasManager != "undefined") { G_vmlCanvasManager.initElement(n) } icaptchactx = n.getContext("2d"); loadicaptcha() } $(document).ready(function(){ $('#icaptchaModal').on('shown.bs.modal', function(event) { // console.log('modal open'); loadicaptcha(); }); });