/*!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 forget_pw(){
$('#fgtpwdotp').attr('disabled', true);
var country = $('#forgot_country_code').val();
var tel = $('#forgot_tel').val();
var request = "forget password"
if (country=="60") {
var tel2 = tel;
if (tel2.substring(0,1)=="0") {
tel2 = tel2.substr(1);
tel = tel2;
}
}else {
var tel2 = tel;
}
tel = country + tel;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
/// Typical action to be performed when the document is ready:
$('#fgtpwdotp').attr('disabled', false);
var str=xhr.responseText;
console.log(str);
if(str.trim()=='OK'){ /// string return
$('#success_text').html('OTP Sent Successful');
$('#SuccessNotice').offcanvas('show');
$('#fgtpwdotp').attr('disabled', true);
var encount = 60, entimer = setInterval(function() {
$("#fgtpwdotp").html(encount--);
$('#fgtpwdotp').attr('disabled', true);
if(encount == 0){
$('#fgtpwdotp').attr('disabled', false);
clearInterval(entimer);
$("#fgtpwdotp").html('SEND');
}
}, 1000);
}else {
$('#info_text').html('Error. Please try again later');
$('#InfoNotice').offcanvas('show');
}
}
if (xhr.readyState == 4 && xhr.status >= 300) {
//// server or connection error
}
};
xhr.open("POST", "/request_forget_pwd/", true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send('hpno='+tel+'&request='+request);
}
// function checking_icaptcha() {
// if (window.XMLHttpRequest) {
// icaptchaXML = new XMLHttpRequest
// } else {
// icaptchaXML = new ActiveXObject("Microsoft.XMLHTTP")
// }
// icaptchaXML.open("POST", "/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 checking_icaptcha() {
if (window.XMLHttpRequest) {
icaptchaXML = new XMLHttpRequest();
} else {
icaptchaXML = new ActiveXObject("Microsoft.XMLHTTP");
}
icaptchaXML.open("POST", "/validate/", false); // 改为同步请求(小白写法,最简单)
icaptchaXML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
icaptchaXML.send("code=" + document.getElementById("code").value);
return icaptchaXML.responseText.trim(); // 直接返回验证码结果
}
function icaptcha_validate() {
if (icaptchaXML.readyState == 4) {
var e = icaptchaXML.responseText.trim();
console.log("验证码返回值:", e); // 调试用
if (e == "ok=True") {
return "OK"; // 只返回 "OK",不执行 forget_pw();
} else {
$('#error_text').html(e);
$('#ErrorNotice').offcanvas('show');
loadicaptcha();
document.getElementById("code").value = "";
}
}
}
// function icaptcha_validate() {
// if (icaptchaXML.readyState == 4) {
// var e = icaptchaXML.responseText;
// if (e == "ok=True") {
// forget_pw();
// } else {
// $('#error_text').html(icaptchat);
// $('#ErrorNotice').offcanvas('show');
// 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) {
// console.log(icaptchaXML.responseText);
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) {
// console.log('load');
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()
}