// ---- BEGIN -- json lib function JSONRequest(obj) { this.obj = obj; var jsonreqcnt = 0; var jsonparent; var jsononreq = function() {}; var jsononclear = function() {}; var jsonreqpendding = 0; var jsonreqnode = []; var jsontimeoutcounter = 0; var json_check_timeout = function() { var ctime = new Date(); var i; var s; for(i in jsonreqnode) { if (ctime - jsonreqnode[i].reqtime > 10000) { if (jsonreqnode[i].parentNode != null) { s = document.createElement('script'); s.setAttribute('src', jsonreqnode[i].src); s.setAttribute('type', "text/javascript"); s.reqtime = new Date(); jsonparent.removeChild(jsonreqnode[i]); delete jsonreqnode[i]; jsonparent.appendChild(s); jsonreqnode[i] = s; jsontimeoutcounter++; } } } setTimeout("json_check_timeout()",10000); } this.json_init = function(obj){ jsonparent = obj; //json_check_timeout(); } this.json_request = function(url, param, rvar, callback, norand){ if (!jsonparent) { this.json_init(document.getElementsByTagName("head")[0]); } jsonreqpendding++; jsononreq(); jsonreqcnt++; s = document.createElement('script'); var attr = url + "?" + param + "&var=" + rvar + "&callback=document.longdoaccount.jsonp.json_clear(" + jsonreqcnt + ");" + callback; if (! norand) { attr += "&rand="+Math.random(); } s.setAttribute('src', attr); s.setAttribute('type', "text/javascript"); s.reqtime = new Date(); jsonreqnode[jsonreqcnt] = s; jsonparent.appendChild(s); } this.json_clear = function(nid) { // if (jsonreqnode[nid]) { jsonreqpendding--; jsononclear(); jsonparent.removeChild(jsonreqnode[nid]); delete jsonreqnode[nid]; //jsonreqnode[nid] = false; // } } var json_attach = function(onreq, onclear){ jsononreq = onreq; jsononclear = onclear; } } function LongdoAccount() { var obj = this; this.debug = false; this.client = false; this.uuid = false; this.device_name = false; this.model = false; this.os_version = false; this.fb_connected = false; this.current_facebook_app_id = 246718802847685; var error_msg_div = 'pp-longdocom-error-txt'; var info_msg_div = 'pp-longdocom-info-txt'; this.setMsgDiv = function(ele_id) { this.setInfoMsgDiv(ele_id); this.setErrorMsgDiv(ele_id); } this.setErrorMsgDiv = function(ele_id) { error_msg_div = ele_id; } this.setInfoMsgDiv = function(ele_id) { info_msg_div = ele_id; } this.mylang = 'th'; this.jsonp = false; this.getScript = function(url, success) { var script = document.createElement('script'); script.src = url; var head = document.getElementsByTagName('head')[0], done = false; // Attach handlers for all browsers script.onload = script.onreadystatechange = function() { if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { done = true; // callback function provided as param success(); script.onload = script.onreadystatechange = null; head.removeChild(script); }; }; head.appendChild(script); } var filesadded = ""; //list of files already added var loadjscssfile = function(filename, filetype) { var lastupdated = '?20140717'; if (filetype=="js") { //if filename is a external JavaScript file var fileref=document.createElement('script') fileref.setAttribute("type","text/javascript") fileref.setAttribute("src", filename+lastupdated) } else if (filetype=="css") { //if filename is an external CSS file var fileref=document.createElement("link") fileref.setAttribute("rel", "stylesheet") fileref.setAttribute("type", "text/css") fileref.setAttribute("href", filename+lastupdated) } if (typeof fileref!="undefined") document.getElementsByTagName("head")[0].appendChild(fileref); } var checkloadjscssfile = function(filename, filetype){ if (filesadded.indexOf("["+filename+"]") == -1) { loadjscssfile(filename, filetype) filesadded += "["+filename+"]"; // List of files added in the form "[filename1],[filename2],etc" } } this.jq = false; var jq_initialed = false; var jq_prettyphoto_initialed = false; var jq_prettyphoto_function_initialed = false; this.thisPageUsingOtherJSLibrary = false; this.consoleLog = function(msg) { if(this.debug && window.console && window.console.log) { console.log(msg); } } //var longdoLoginElement = false; this.closePrettyPhoto = function() { if (this.jq && this.jq.prettyPhotoLongdoHook && this.jq.prettyPhotoLongdoHook.close) { this.jq.prettyPhotoLongdoHook.close(); } } this.showLongdoLoginForm = function(msg, des, callback) { //if (longdoLoginElement && longdoLoginElement.length > 0) { // longdoLoginElement.click(); //} else { if(typeof(msg) == 'undefined') msg = false; if(typeof(des) == 'undefined') des = false; if(typeof(callback) != 'function') callback = false; this.initLongdoLogin(); if (!document.longdoaccount.jq.prettyPhotoLongdoHook) { setTimeout(function(){ document.longdoaccount.showLongdoLoginForm(msg, des, callback); }, 200); return; } var href = '/login'; if (des) { href = des; } else { var longdoLoginElement = document.longdoaccount.jq("a[href$='/login'], a[href*='/login?destination']"); if(longdoLoginElement.length > 0) { var login_href = longdoLoginElement.attr('href').replace(longdoLoginElement.attr('baseURI'), ''); if(login_href) href = '/' + login_href; } } document.longdoaccount.jq.prettyPhotoLongdoHook.openLink(href, { changepicturecallback: function() { document.longdoaccount.setFBLoginButtonID('longdo-login-fb-btn'); document.longdoaccount.setGGLoginButtonID('longdo-login-gg-btn'); document.longdoaccount.initSocialAccountButton({fb: 'longdocards-login-fb-btn', try_longdocards_fb: msg ? msg.try_longdocards_fb : false}); if (msg && msg.txt) { if (msg.type == 'error') { document.longdoaccount.showErrorMsgLongdoLogin(msg.txt) } else if (msg.type == 'info') { document.longdoaccount.showInfoMsgLongdoLogin(msg.txt) } } }, login_callback: callback, callback: function() { document.longdoaccount.initFBAppID(facebook_app_id); } }); void(0); } this.initFBAppID = function(fb_app_id) { FB.init({ appId : fb_app_id, status : true, // check login status cookie : true, // enable cookies to allow the server to access the session xfbml : true, // parse XFBML version : 'v2.12' }); this.current_facebook_app_id = fb_app_id; } this.showLongdoRequestPwdForm = function(email) { if(!document.longdoaccount.jq) { window.open('//login-test.loga.app/user/password/force', '_blank'); return; } this.initLongdoLogin(); if (!document.longdoaccount.jq.prettyPhotoLongdoHook) { setTimeout(function(){ document.longdoaccount.showLongdoRequestPwdForm(); }, 200); return; } //document.longdoaccount.closePrettyPhoto(); if(!email) { email = ''; } document.longdoaccount.jq.prettyPhotoLongdoHook.openLink('/forgotpwd', {forgotpwd_email: email}); //setTimeout(function(){ document.longdoaccount.jq.prettyPhotoLongdoHook.changePage('', function(){ document.longdoaccount.jq.prettyPhotoLongdoHook.openLink('/forgotpwd'); }) }, 1000); void(0); } this.showPrettyPhotoPopup = function(op, param) { this.initLongdoLogin(); if (!document.longdoaccount.jq.prettyPhotoLongdoHook) { setTimeout(function(){ document.longdoaccount.showPrettyPhotoPopup(op, param); }, 200); return; } if (typeof(param) == 'object') { document.longdoaccount.jq.prettyPhotoLongdoHook.openLink(op, param); } else { document.longdoaccount.jq.prettyPhotoLongdoHook.openLink(op); } } var timeoutLoadjQuery = false; this.initPrettyPhotoAPI = function() { if (!this.jq && !jq_initialed) { this.initJQuery(); jq_initialed = true; } if (!this.jq) { // jQuery is loading .. setTimeout(function(){ document.longdoaccount.initPrettyPhotoAPI(); }, 200); return; } if (!this.jq.prettyPhotoLongdoHook && !jq_prettyphoto_initialed) { document.longdoaccount.loadPrettyPhoto(); jq_prettyphoto_initialed = true; } if(!this.jq.prettyPhotoLongdoHook) { setTimeout(function(){ document.longdoaccount.initPrettyPhotoAPI(); }, 200); return; } if (this.jq.prettyPhotoLongdoHook && !jq_prettyphoto_function_initialed) { jq_prettyphoto_function_initialed = true; this.jq("longdo").prettyPhotoLongdoHook({}); } } this.appendSocialAccountButton = function(eles) { if (typeof(eles) != 'object' || !eles.length || eles.length < 1) { return; } var fb_loginbar_button_id = 'longdocom-loginbar-fb-button'; var gg_loginbar_button_id = 'longdocom-loginbar-gg-button'; var content = document.createElement("span"); content.id = fb_loginbar_button_id; content.className = 'longdocom-loginbar-social-button'; //var ele; //var num_ele = eles.length; //for(var i=0; i 0) { longdoLoginElement.unbind('click').bind('click',function(){ document.longdoaccount.showLongdoLoginForm(); return false; }); document.longdoaccount.appendSocialAccountButton(document.longdoaccount.jq(".longdo-loginbar-button")); } jq_longdologin_initialed = true; } else if(!jq_longdologin_initialed) { setTimeout(function(){ document.longdoaccount.initLongdoLogin(jq_ele); }, 200); return; } } this.login_ajax_callback = function(rs, destination, target) { if(typeof(rs) == 'object' && rs.uid) { if (this.jq.prettyPhotoLongdoHook.login_callback) { try { this.jq.prettyPhotoLongdoHook.login_callback(parseInt(rs.uid, 10)); this.jq.prettyPhotoLongdoHook.close(); } catch (ex) { this.consoleLog(ex); } } else { if(destination) destination = decodeURIComponent(decodeURIComponent(String(destination).replace(/\+/g, '%20'))); if(destination && destination != window.location.pathname) { if (!/^\//.test(destination)) { destination = '/'+destination; } if(target == '_blank') { window.location.reload(true); window.open(destination); } else window.location = destination; } else { window.location.reload(true); } } } else if (typeof(rs) == 'object' && (rs.errormsg || rs.errorcode)) { this.enableButtonOnLoginForm(); var msg; if(rs.errorcode) { msg = this.getMessageByMsgCode(rs.errorcode, rs.errormail || rs.erroruid); if(msg == rs.errorcode && rs.errormsg) { msg = rs.errormsg; } } else { msg = rs.errormsg; } this.showErrorMsgLongdoLogin(msg); } else if (rs == 0) { this.enableButtonOnLoginForm(); this.showErrorMsgLongdoLogin(this.getMessageByMsgCode('userpwd_incorrect')); } else { this.enableButtonOnLoginForm(); this.showErrorMsgLongdoComFailed(); } } this.showErrorMsgLongdoComFailed = function() { this.showErrorMsgLongdoLogin(this.getMessageByMsgCode('longdocom_failed')); } this.hideMsgLongdoLogin = function(ele_id) { if (!this.jq) { var msg_div = getEleByID(ele_id); if(msg_div) { msg_div.innerHTML = ''; msg_div.style.display = 'none'; } return; } var err_txt = this.jq('#'+ele_id); if(err_txt && err_txt.length > 0) { err_txt.html(''); this.hideElementByJq(err_txt); } } this.showMsgLongdoLogin = function(ele_id, errortxt) { if (!this.jq) { var msg_div = getEleByID(ele_id); if(msg_div) { msg_div.innerHTML = errortxt; msg_div.style.display = 'block'; } return; } var err_txt = this.jq('#'+ele_id); if(err_txt && err_txt.length > 0) { err_txt.html(errortxt); this.showElementByJq(err_txt); } else if(ele_id == error_msg_div) { document.longdoaccount.showPrettyPhotoPopup('/showmsg?msg='+errortxt, { default_width: '400', default_height: '100' }); return; } } this.hideErrorMsgLongdoLogin = function() { this.hideMsgLongdoLogin(error_msg_div); } this.showErrorMsgLongdoLogin = function(txt) { this.hideInfoMsgLongdoLogin(); this.showMsgLongdoLogin(error_msg_div, txt); } this.hideInfoMsgLongdoLogin = function() { this.hideMsgLongdoLogin(info_msg_div); } this.showInfoMsgLongdoLogin = function(txt) { this.hideErrorMsgLongdoLogin(); this.showMsgLongdoLogin(info_msg_div, txt); } this.hideElementByJq = function(ele) { if (!this.jq) { return; } if (typeof(ele) == 'string') { ele = this.jq(ele); } if(typeof(ele) == 'object' && ele.length > 0) { ele.addClass('pp-longdocom-hide'); } } this.showElementByJq = function(ele) { if (!this.jq) { return; } if (typeof(ele) == 'string') { ele = this.jq(ele); } if(typeof(ele) == 'object' && ele.length > 0) { ele.removeClass('pp-longdocom-hide'); } } this.enableButtonOnLoginForm = function() { if (this.jq && this.jq != 'failed' && this.jq('#longdologin-form-ajax').length > 0) { // login form on prettyphoto popup var pp_login_form = this.jq('#longdologin-form-ajax'); pp_login_form.find('.button-submit-ajax').removeAttr("disabled").removeClass('pp-longdocom-btn-waiting'); pp_login_form.find('.longdo-login-social-button').removeClass('longdo-login-social-button-waiting'); } else { // on longdo.com page var login_button = getEleByID('login-button'); var loading = getEleByID('loading-login'); var fb_button = getEleByID(fb_login_button_div_id); var gg_button = getEleByID(gg_login_button_div_id); if (login_button && loading) { login_button.style.display = 'block'; loading.style.display = 'none'; } if (fb_button) { removeClass(fb_button, 'longdo-login-social-button-waiting'); } if (gg_button) { removeClass(gg_button, 'longdo-login-social-button-waiting'); } } } this.disableButtonOnLoginForm = function() { if (this.jq && this.jq != 'failed' && this.jq('#longdologin-form-ajax').length > 0) { // login form on prettyphoto popup var pp_login_form = this.jq('#longdologin-form-ajax'); pp_login_form.find('.button-submit-ajax').attr("disabled", "disabled").addClass('pp-longdocom-btn-waiting'); pp_login_form.find('.longdo-login-social-button').addClass('longdo-login-social-button-waiting'); } else { // on longdo.com page var login_button = getEleByID('login-button'); var loading = getEleByID('loading-login'); var fb_button = getEleByID(fb_login_button_div_id); var gg_button = getEleByID(gg_login_button_div_id); if (login_button && loading) { login_button.style.display = 'none'; loading.style.display = 'block'; } if (fb_button) { addClass(fb_button, 'longdo-login-social-button-waiting'); } if (gg_button) { addClass(gg_button, 'longdo-login-social-button-waiting'); } } } this.login_ajax = function(destination, target) { var username_val = ''; var password_val = ''; if(this.jq('#username-ajax')) username_val = this.jq('#username-ajax').val(); if(this.jq('#pass-ajax')) password_val = this.jq('#pass-ajax').val(); var msgcode = username_val != '' ? (password_val != '' ? "" : "pwd_required") : (password_val != '' ? "user_required" : "userpwd_required") ; if(msgcode != '') { this.showErrorMsgLongdoLogin(this.getMessageByMsgCode(msgcode)); return;} //this.hideElementByJq('#longdologin-form-ajax'); this.disableButtonOnLoginForm(); this.hideErrorMsgLongdoLogin() if (!target) { target = false; } if (!destination) { destination = false; } else { destination = encodeURIComponent(destination); } this.jq.ajax({ url: '//login-test.loga.app/action/login/', dataType: "json", type: "POST", data: {'username': username_val, 'pass': password_val, 'getuser': 1}, success: function( response ) { document.longdoaccount.login_ajax_callback(response, destination, target) }, beforeSend: function(xhr){ xhr.withCredentials = true; }, xhrFields: { withCredentials: true }, crossDomain: true }); //document.longdoaccount.jsonp.json_request('//login-test.loga.app/action/login', 'username='+encodeURIComponent(username_val)+'&pass='+encodeURIComponent(password_val)+'&getuser=1', 'rs', 'document.longdoaccount.login_ajax_callback(rs)'); } this.forgotpwd_ajax = function() { var username_val = ''; if(this.jq('.pp-longdocom #username-ajax')) username_val = this.jq('.pp-longdocom #username-ajax').val(); var msgcode = username_val != '' ? '' : "user_required"; if(msgcode != '') { this.showErrorMsgLongdoLogin(this.getMessageByMsgCode(msgcode)); return;} //this.hideElementByJq('#longdologin-form-ajax'); this.disableButtonOnLoginForm(); this.hideErrorMsgLongdoLogin() document.longdoaccount.jsonp.json_request('//login-test.loga.app/action/forgotpwd', 'username='+encodeURIComponent(username_val), 'rs', 'document.longdoaccount.forgotpwd_ajax_callback(rs)'); } this.getMessageByMsgCode = function(code, arg) { var en = (this.mylang == 'en'); if (typeof(arg) == 'undefined') { arg = ''; } switch (code) { case "forgotpwd_completed": if(arg && arg != '') { arg = '
('+arg+')
'; } return (en ? "Further instructions have been sent to your e-mail address{email}" : "ระบบได้ส่งขั้นตอนการเข้าสู่ระบบให้ท่านทางอีเมลเรียบร้อยแล้ว{email}").replace('{email}', arg);; case "forgotpwd_notfound": return en ? "Sorry, invalid a username or an e-mail address" : "ไม่พบชื่อผู้ใช้ หรือ อีเมลนี้ในระบบ"; case "socialmail_found": return en ? "You already have a Loga account,
please enter your Loga password" : "ระบบพบว่าท่านเคยมีบัญชีผู้ใช้ Loga อยู่แล้ว
โปรดใส่รหัสผ่าน Loga"; case "socialmail_regist": return en ? "Please enter new password for create new Loga account" : "กรุณากรอกรหัสผ่านใหม่ เพื่อสร้างบัญชีผู้ใช้กับ Loga"; case "fbmail_invalid": return en ? "Invalid Facebook e-mail address" : "อีเมลของ Facebook ไม่ถูกต้อง"; case "userpwd_incorrect": return en ? "The username or password is incorrect" : "ชื่อผู้ใช้ หรือ รหัสผ่านไม่ถูกต้อง"; case "regist_fail": return en ? "Failed to register, Please try again" : "ลงทะเบียนไม่สำเร็จ โปรดลองใหม่อีกครั้ง"; case "connecting_fb": return en ? "Connecting with Facebook .." : "กำลังเชื่อมต่อ Facebook .."; case "pwd_required": return en ? "Password is required" : "โปรดระบุรหัสผ่าน"; case "user_required": return en ? "Username/E-mail address is required" : "โปรดระบุชื่อผู้ใช้/อีเมลผู้ใช้"; case "userpwd_required": return en ? "Username/E-mail address and Password are required" : "โปรดระบุชื่อผู้ใช้/อีเมลผู้ใช้ และ รหัสผ่าน"; case "longdocom_failed": return en ? "Loga is not available right now. Please try again later" : "Loga อยู่ในระหว่างการพัฒนาระบบ/เกิดข้อผิดหลาด กรุณาลองใหม่ภายหลัง"; case "signin": return en ? "Sign In" : "เข้าสู่ระบบ"; case "forgotpwd": return en ? "Forgot Password" : "ลืมรหัสผ่าน"; case "register": return en ? "Register" : "ลงทะเบียน"; case "signup": return en ? "Sign Up" : "สมัครบัญชีผู้ใช้"; case "userormail": return en ? "Username / E-mail Address" : "ชื่อผู้ใช้ / อีเมลผู้ใช้"; case "userormailortel": return en ? "Username / E-mail / Mobile phone no." : "ชื่อผู้ใช้ / อีเมล / เบอร์มือถือ"; case "pwd": return en ? "Password" : "รหัสผ่าน"; case "signin_via": return en ? "Or sign in using" : "หรือเข้าสู่ระบบโดย"; case "mail_newpwd": return en ? "E-mail New Password" : "ขอรหัสผ่านใหม่ทางอีเมล"; case "user_not_activated": if(arg && arg != '') { arg = '
('+arg+')
'; } return (en ? "Your account is not activated.
Please check your e-mail to activate your account.{email}Resend Activation Email" : "บัญชีของท่านยังไม่ได้ทำการยืนยันอีเมล
กรุณาตรวจสอบอีเมล และยืนยันบัญชีผู้ใช้{email}ให้ระบบส่งอีเมลยืนยันอีกครั้ง").replace("{email}", arg).replace("{plainemail}", arg.replace(/<[^>]*>/g, "").replace(/^\s*\(/, '').replace(/\)$/, '')); //case "": // return en ? "" : // ""; default: return code; } } //this.resend_activation_mail = function(ele) { // if (!ele.uid) { // this.consoleLog('Unknown UID.'); // return; // } // // document.longdoaccount.jsonp.json_request('//login-test.loga.app/action/resendactivationmail', 'uid='+ele.uid, 'rs', 'document.longdoaccount.resend_activation_mail_callback(rs)'); //} this.forgotpwd_ajax_callback = function(rs) { this.enableButtonOnLoginForm(); if (validateEmail(rs)) { // success, return e-mail this.showInfoMsgLongdoLogin(this.getMessageByMsgCode("forgotpwd_completed", rs)); this.enableButtonOnLoginForm(); } else if (rs == "forgotpwd_notfound") { // user not found this.showErrorMsgLongdoLogin(this.getMessageByMsgCode(rs)); this.enableButtonOnLoginForm(); } else { this.showErrorMsgLongdoComFailed(); this.enableButtonOnLoginForm(); } } this.socialregist_ajax = function() { var username_val = ''; if(this.jq('.pp-longdocom #username-ajax')) username_val = this.jq('.pp-longdocom #username-ajax').val(); else if(this.jq('#username-ajax')) username_val = this.jq('#username-ajax').val(); var pwd_val = ''; if(this.jq('.pp-longdocom #pass-ajax')) pwd_val = this.jq('.pp-longdocom #pass-ajax').val(); else if(this.jq('#pass-ajax')) pwd_val = this.jq('#pass-ajax').val(); var msgcode = username_val != '' ? '' : "user_required"; if (!pwd_val) { if (msgcode != '') { msgcode = "userpwd_required"; } else { msgcode = "pwd_required"; } } if(msgcode != '') { this.showErrorMsgLongdoLogin(this.getMessageByMsgCode(msgcode)); return;} //this.hideElementByJq('#longdologin-form-ajax'); this.disableButtonOnLoginForm(); this.hideErrorMsgLongdoLogin() var params = document.longdoaccount.getSocialParam('obj'); params['email'] = username_val; params['pwd'] = pwd_val; this.jq.ajax({ url: '//login-test.loga.app/action/socialregist/', dataType: "json", type: "POST", data: params, success: function( response ) { document.longdoaccount.socialregist_ajax_callback(response); }, beforeSend: function(xhr){ xhr.withCredentials = true; }, xhrFields: { withCredentials: true }, crossDomain: true }); //document.longdoaccount.jsonp.json_request('//login-test.loga.app/action/socialregist', 'email='+username_val+'&pwd='+pwd_val+document.longdoaccount.getSocialParam(), 'rs', 'document.longdoaccount.socialregist_ajax_callback(rs)'); } this.login_callback_customize = function(uid) { uid = parseInt(uid, 10); if (this.jq && this.jq.prettyPhotoLongdoHook && typeof(this.jq.prettyPhotoLongdoHook.login_callback) == 'function') { try { this.jq.prettyPhotoLongdoHook.login_callback(uid); } catch (ex) { this.consoleLog(ex); window.location.reload(true); } finally { this.jq.prettyPhotoLongdoHook.close(); } } else { window.location.reload(true); } } this.socialregist_ajax_callback = function(rs) { rs = parseInt(rs, 10); if (rs > 0) { this.login_callback_customize(rs); } else if (rs == 0) { this.enableButtonOnLoginForm(); this.showErrorMsgLongdoLogin(this.getMessageByMsgCode('regist_fail')); } else { this.enableButtonOnLoginForm(); this.showErrorMsgLongdoComFailed(); } } this.socialconnect_ajax = function() { var username_val = ''; if(this.jq('#username-ajax')) username_val = this.jq('#username-ajax').val(); var pwd_val = ''; if(this.jq('#pass-ajax')) pwd_val = this.jq('#pass-ajax').val(); var msgcode = username_val != '' ? '' : "user_required"; if (!pwd_val) { if (msgcode != '') { msgcode = "userpwd_required"; } else { msgcode = "pwd_required"; } } if(msgcode != '') { this.showErrorMsgLongdoLogin(this.getMessageByMsgCode(msgcode)); return;} this.disableButtonOnLoginForm(); //this.hideElementByJq('#longdologin-form-ajax'); this.hideErrorMsgLongdoLogin() var params = document.longdoaccount.getSocialParam('obj'); params['username'] = username_val; params['pass'] = pwd_val; params['getuser'] = 1; this.jq.ajax({ url: '//login-test.loga.app/action/login/', dataType: "json", type: "POST", data: params, success: function( response ) { document.longdoaccount.login_ajax_callback(response) }, beforeSend: function(xhr){ xhr.withCredentials = true; }, xhrFields: { withCredentials: true }, crossDomain: true }); //document.longdoaccount.jsonp.json_request('//login-test.loga.app/action/login', 'username='+encodeURIComponent(username_val)+'&pass='+encodeURIComponent(pwd_val)+document.longdoaccount.getSocialParam()+'&getuser=1', 'rs', 'document.longdoaccount.login_ajax_callback(rs)'); } this.checksocialmail_ajax_callback = function(rs) { if (rs && rs.username) { if (rs.connected && rs.uid > 0) { this.login_callback_customize(rs.uid); } else { // request pwd for connect social account (Should not be in this case) document.longdoaccount.enableButtonOnLoginForm(); document.longdoaccount.showPrettyPhotoPopup('/socialconnect?username='+rs.username, { changepicturecallback: function() { document.longdoaccount.showInfoMsgLongdoLogin(document.longdoaccount.getMessageByMsgCode('socialmail_found')); }, login_callback: document.longdoaccount.login_callback_customize }); } } else { document.longdoaccount.enableButtonOnLoginForm(); document.longdoaccount.showPrettyPhotoPopup('/socialregist?username='+rs.email, { changepicturecallback: function() { document.longdoaccount.showInfoMsgLongdoLogin(document.longdoaccount.getMessageByMsgCode('socialmail_regist')); }, login_callback: document.longdoaccount.login_callback_customize }); } } this.loadPrettyPhoto = function() { loadjscssfile('//login-test.loga.app//api/prettyPhoto/js/jquery.prettyPhoto.js', 'js'); loadjscssfile('//login-test.loga.app//api/css/prettyPhoto.css', 'css'); } this.initJQuery = function(callback) { if (typeof jQuery == 'undefined') { if (typeof $ == 'function') { document.longdoaccount.thisPageUsingOtherJSLibrary = true; } this.getScript('//login-test.loga.app//api/prettyPhoto/js/jquery-1.6.1.min.js', function() { if (typeof jQuery=='undefined') { document.longdoaccount.jq = 'failed'; document.longdoaccount.consoleLog('Error: Load jQuery Failed.'); } else { if (document.longdoaccount.thisPageUsingOtherJSLibrary) { document.longdoaccount.jq = jQuery; } else { document.longdoaccount.jq = jQuery.noConflict(); } } }); } else { document.longdoaccount.jq = jQuery; }; } this.initJSONP = function() { if (this.jsonp) { return; } this.jsonp = new JSONRequest(); //document.longdoaccount.jsonp.json_init(document.getElementsByTagName("head")[0]); } var fb_login_button_div_id = 'fb-login-button'; var gg_login_button_div_id = 'gg-login-button'; this.setFBLoginButtonID = function(id) { fb_login_button_div_id = id; } this.setGGLoginButtonID = function(id) { gg_login_button_div_id = id; } var facebook_app_id = '246718802847685'; var facebook_app_longdocards_id = '148173948530677'; var facebook_scopes = 'email,public_profile'; var facebook_required_fields_when_login = 'id,name,email'; var google_client_id = '143997539175-5304ci1cdrqmei1qrqhf11drg5q7s4us.apps.googleusercontent.com'; var google_client_secret = '4sadCoAab1eO30KYpPAfZwrQ'; var google_api_key = 'AIzaSyBB1gbmtus0vyI6ENA4HYtYA-acrrw8QVg'; var google_scopes = 'https://www.googleapis.com/auth/plus.me'; var googleHandleClientLoad = function() { // Step 2: Reference the API key gapi.client.setApiKey(google_api_key); window.setTimeout(checkAuth,1); } var checkAuth = function() { gapi.auth.authorize({client_id: google_client_id, scope: google_scopes, immediate: true}, handleAuthResult); } var handleAuthResult = function(authResult) { //var authorizeButton = document.getElementById('authorize-button'); if (authResult && !authResult.error) { //authorizeButton.style.visibility = 'hidden'; makeApiCall(); } else { //authorizeButton.style.visibility = ''; //authorizeButton.onclick = handleAuthClick; } } var handleAuthClick = function(event) { // Step 3: get authorization to use private data gapi.auth.authorize({client_id: google_client_id, scope: google_scopes, immediate: false}, handleAuthResult); return false; } // Load the API and make an API call. Display the results on the screen. var makeApiCall = function() { // Step 4: Load the Google+ API gapi.client.load('plus', 'v1', function() { // Step 5: Assemble the API request var request = gapi.client.plus.people.get({ 'userId': 'me' }); // Step 6: Execute the API request request.execute(function(resp) { var heading = document.createElement('h4'); var image = document.createElement('img'); image.src = resp.image.url; heading.appendChild(image); heading.appendChild(document.createTextNode(resp.displayName)); document.getElementById('content').appendChild(heading); }); }); } var username = ''; var passwd = ''; var getEleByID = function(id) { var ele = document.getElementById(id); return (ele ? ele : false); } var getEleByClass = function(className) { var ele = document.getElementsByClassName(className); return (ele ? ele : false); } this.ggLongdoRegis = function() { handleAuthClick(); } this.redirectPage = function(url) { window.location.replace(url); } var validateEmail = function(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } this.getSocialParam = function(mode) { // obj / str if(!mode) { mode = 'str'; } var social_param = mode == 'obj' ? {} : ''; if (this.socialtoken) { if(mode == 'obj') { social_param['socialtoken'] = this.socialtoken; } else { social_param += '&socialtoken='+this.socialtoken; } } if (this.socialtoken_longdocards) { if(mode == 'obj') { social_param['socialtokenldcards'] = this.socialtoken_longdocards; } else { social_param += '&socialtokenldcards='+this.socialtoken_longdocards; } } return social_param; } this.processConnectedFacebookUser = function(user_rs) { var client_param = this.client ? '&client='+this.client : ''; var device_param = this.device_name ? '&device_name='+this.device_name : ''; device_param += this.model ? '&model='+this.model : ''; device_param += this.os_version ? '&os_version='+this.os_version : ''; device_param += this.uuid ? '&uuid='+this.uuid : ''; var social_param = this.getSocialParam(); //this.consoleLog(user_rs); if (!user_rs) { FB.api('/me?fields='+facebook_required_fields_when_login, function(response) { var email = response.email; if (email && validateEmail(email)) { if (/secure.longdo.com/.test(window.location.hostname)) { document.longdoaccount.redirectPage('https://secure.longdo.com/iregister/social.php?email='+email+client_param+device_param+social_param); } else { document.longdoaccount.jsonp.json_request('//login-test.loga.app/action/checksocialmail', 'email='+email+social_param, 'rs', 'document.longdoaccount.checksocialmail_ajax_callback(rs)'); } } else { if (/secure.longdo.com/.test(window.location.hostname)) { if(!email) { email = ''; } document.longdoaccount.redirectPage('https://secure.longdo.com/iregister/social.php?email='+email+client_param+device_param+social_param); } else { document.longdoaccount.enableButtonOnLoginForm(); document.longdoaccount.showLongdoLoginForm({txt: document.longdoaccount.getMessageByMsgCode('fbmail_invalid')+(email ? '
('+email+')' : ''), type: 'error', try_longdocards_fb: true}); } } }); } else if (typeof(user_rs) == 'object' && (user_rs.errormsg || user_rs.errorcode)) { this.enableButtonOnLoginForm(); var msg; if(user_rs.errorcode) { msg = this.getMessageByMsgCode(user_rs.errorcode, user_rs.errormail); if(msg == user_rs.errorcode && user_rs.errormsg) { msg = user_rs.errormsg; } } else { msg = user_rs.errormsg; } this.showErrorMsgLongdoLogin(msg); } else { var redirect_url = this.getRedirectLoggedinPathByClient(device_param, social_param); if (redirect_url != '') { redirect_url = redirect_url.replace('{uid}', user_rs.uid); redirect_url = redirect_url.replace('{username}', user_rs.name); redirect_url = redirect_url.replace('{ldtoken}', user_rs.longdousertoken); document.longdoaccount.redirectPage(redirect_url); } else { document.longdoaccount.login_callback_customize(user_rs.uid); } } } this.getRedirectLoggedinPathByClient = function(device_param, social_param) { var redirect_path = ''; switch(this.client) { case 'longdocardappios': case 'appandroid': case 'longdocardappandroid': case 'logaappios': case 'logaappandroid': redirect_path = 'https://www-test.loga.app/privateapi/longdo/getusertoken?uid={uid}'+device_param+social_param; break; case 'longdomapappios': redirect_path = 'ldmap://map/login/{username}/{ldtoken}'; break; case 'longdotrafficappandroid': case 'longdotrafficappios': redirect_path = 'ldtraffic://login/{username}/{ldtoken}'; break; default: redirect_path = ''; break; } return redirect_path; } this.checkConnectedFacebookUser = function(social_param, variable, callback) { if (!callback) { callback = 'document.longdoaccount.processConnectedFacebookUser(rs)'; } if (!variable) { variable = 'rs'; } document.longdoaccount.jsonp.json_request('//login-test.loga.app/action/login', 'getuser=1'+social_param, variable, callback); } var hasClass = function(ele, clsname) { return ( (" " + ele.className + " ").replace(/[\n\t]/g, " ").indexOf(" "+clsname+" ") > -1 ); } var addClass = function(ele, name) { if (!hasClass(ele, name)) { ele.className += (ele.className ? ' ' : '') +name; } } var removeClass = function(ele, name) { if (hasClass(ele, name)) { ele.className=ele.className.replace(new RegExp('(\\s|^)'+name+'(\\s|$)'),' ').replace(/^\s+|\s+$/g, ''); } } this.fbLongdoLogin = function(evt) { if (typeof evt != 'undefined') { var ele = evt.target || evt.srcElement || evt.toElement; if (ele && hasClass(ele, 'longdo-login-social-button-waiting')) { return; } } if (!FB) { setTimeout(function() { document.longdoaccount.fbLongdoLogin(evt); }, 200); } document.longdoaccount.showInfoMsgLongdoLogin(document.longdoaccount.getMessageByMsgCode('connecting_fb')); document.longdoaccount.disableButtonOnLoginForm(); document.longdoaccount.initialFacebook(); FB.login(function(response) { if (response.authResponse) { var fb_uid = response.authResponse.userID; var fb_accesstoken = response.authResponse.accessToken; if(document.longdoaccount.current_facebook_app_id == facebook_app_longdocards_id) { document.longdoaccount.socialtoken_longdocards = 'fb:'+fb_uid+':'+fb_accesstoken+':'+document.longdoaccount.current_facebook_app_id; } else { document.longdoaccount.socialtoken = 'fb:'+fb_uid+':'+fb_accesstoken+':'+document.longdoaccount.current_facebook_app_id; } var user = document.longdoaccount.checkConnectedFacebookUser(document.longdoaccount.getSocialParam()); } else { document.longdoaccount.enableButtonOnLoginForm(); document.longdoaccount.hideInfoMsgLongdoLogin(); } }, { scope: facebook_scopes}); } var initButtonStyle = function(type, ele) { ele.style.cursor = 'pointer'; ele.style.WebkitBorderRadius = '3px'; ele.style.borderRadius = '3px'; ele.style.MozBorderRadius = '3px'; ele.style.WebkitAppearance = 'none'; ele.style.height = '32px'; ele.style.lineHeight = '32px'; ele.style.color = '#FFF'; ele.style.margin = '0px auto 15px'; if (!ele.style.width) { ele.style.width = '220px'; } if(type == 'fb') { ele.style.background = '#4c69ba'; ele.style.background = '-webkit-gradient(linear, center top, center bottom, from(#4c69ba), to(#3b55a0))'; ele.style.background = '-webkit-linear-gradient(#4c69ba, #3b55a0)'; ele.style.background = '-moz-linear-gradient(top, #3b55a0, #4c69ba)'; ele.style.background = '-ms-linear-gradient(top, #3b55a0, #4c69ba)'; ele.style.background = '-o-linear-gradient(top, #3b55a0, #4c69ba)'; ele.style.border = '1px solid #4c69ba'; ele.style.fontFamily = 'Helvetica Neue, Helvetica, Arial, lucida grande,tahoma,verdana,arial,sans-serif'; ele.style.fontSize = '17px'; } else { ele.style.background = '#357FFF'; ele.style.fontFamily = 'Helvetica,Tahoma'; ele.style.border = '1px solid #245bc2'; ele.style.fontSize = '16px'; } } this.setEventSubscribeFacebookUser = function() { if (typeof(FB) != 'undefined') { FB.getLoginStatus(function(response) { var auth = response.authResponse; if(response.status == 'connected'){ var fb_uid = auth.userID; var fb_accesstoken = auth.accessToken; if(document.longdoaccount.current_facebook_app_id == facebook_app_longdocards_id) { document.longdoaccount.socialtoken_longdocards = 'fb:'+fb_uid+':'+fb_accesstoken+':'+document.longdoaccount.current_facebook_app_id; } else { document.longdoaccount.socialtoken = 'fb:'+fb_uid+':'+fb_accesstoken+':'+document.longdoaccount.current_facebook_app_id; } var user = document.longdoaccount.checkConnectedFacebookUser(document.longdoaccount.getSocialParam()); } }); } } var fb_initialed = false; this.initialFacebook = function() { if (typeof(FB) != 'undefined' && !fb_initialed) { this.initFBAppID(facebook_app_id); fb_initialed = true; if(this.fb_connected == 1) { this.setEventSubscribeFacebookUser(); } } else if (typeof(FB) == 'undefined') { setTimeout(function(){ document.longdoaccount.initialFacebook(); }, 200); } if(this.fb_connected == 1 && !document.getElementById('ld-fb-loading')) { var ld = document.createElement("div"); ld.id = "ld-fb-loading"; ld.style.fontFamily = "Helvetica"; ld.style.fontSize = "13px"; ld.style.color = "#537041"; ld.style.margin = "30px auto 50px"; ld.style.border = "1px solid #537041"; ld.style.width = "80%"; ld.style.padding = "5px 3px"; ld.style.textAlign = "center"; ld.style.backgroundColor = "#e0ffb7"; ld.style.lineHeight = "24px"; ld.innerHTML = "Please wait, connecting with Facebook .."; if(document.getElementById('signup-form')) { document.getElementById('signup-form').parentNode.insertBefore(ld, document.getElementById('signup-form').nextSibling); //document.getElementById('signup-form').parentNode.insertBefore(ld, document.getElementById('signup-form').parentNode.firstChild); document.getElementById('signup-form').style.display = 'none'; } else { document.body.insertBefore(ld, document.body.firstChild); } } } this.initFacebookButton = function(fb_login_button) { if (fb_login_button) { fb_login_button.onclick = this.fbLongdoLogin; //if (fb_login_button.offsetHeight == 0 || fb_login_button.offsetWidth == 0) { if (fb_login_button_div_id == 'fb-login-button') { // for secure.longdo page fb_login_button.innerHTML = ' Log in with Facebook'; initButtonStyle('fb', fb_login_button); } } } this.initSocialAccountButton = function(obj) { var fb_login_button = getEleByID(fb_login_button_div_id); var gg_login_button = getEleByID(gg_login_button_div_id); if (fb_login_button || (obj && obj.fb)) { if(obj && obj.try_longdocards_fb) { this.initFBAppID(facebook_app_longdocards_id); this.showElementByJq('#longdocards-login-fb-btn'); this.hideElementByJq('#longdo-login-fb-btn'); this.jq(".pp-longdocom .longdo-login-social-btn").css('minWidth', '200px'); } else if(typeof FB != 'undefined') { this.initFBAppID(facebook_app_id); this.hideElementByJq('#longdocards-login-fb-btn'); this.showElementByJq('#longdo-login-fb-btn'); this.jq(".longdo-login-social-btn").css('minWidth', ''); } (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); document.longdoaccount.initialFacebook(); }(document, 'script', 'facebook-jssdk')); if (fb_login_button) { this.initFacebookButton(fb_login_button); //if (fb_login_button.offsetHeight == 0 || fb_login_button.offsetWidth == 0) { if (fb_login_button_div_id == 'fb-login-button') { // for secure.longdo page fb_login_button.innerHTML = ' Log in with Facebook'; initButtonStyle('fb', fb_login_button); } } if(obj && obj.fb) { var fb_login_button = getEleByID(obj.fb); this.initFacebookButton(fb_login_button); } } if (gg_login_button) { (function(d) { var js, id = 'google-jssdk', ref = d.getElementsByTagName('script')[0]; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//apis.google.com/js/client.js?onload=googleHandleClientLoad"; js.async = true; ref.parentNode.insertBefore(js, ref); }(document)); if (gg_login_button) { gg_login_button.onclick = this.ggLongdoLogin; //if (gg_login_button.offsetHeight == 0 || gg_login_button.offsetWidth == 0) { if (gg_login_button == 'gg-login-button') { // for secure.longdo page gg_login_button.innerHTML = 'Log in with Google'; initButtonStyle('gg', gg_login_button); } } } } document.longdoaccount = this; document.longdoaccount.initJSONP(); }