/* login.js * */ $(function () { var sData = new Object(); sData = getAppInfo(); // Set dictionary jQuery.i18n.properties({ name: 'Messages', path: '../include/lang/', mode: 'both', language: sData.lang, callback: function () {} }); $("#login-button").click(function () { var user = $('#username').val() var pass = $('#username').val() if (user == "") { alert("Username void not allowed") $("#username").focus() return false } if (pass.length < 4) { alert("Password too short!") $("#password").focus() return false } // passo i dati (via POST) al file PHP che effettua le verifiche $("#messageBar").html("Connecting..") $.post("../php/login.php", { username: $('#username').val(), password: $('#password').val(), rand: Math.random()}, function (res) { // se i dati sono corretti... console.log("LOGIN: ", res) if (res == 1) { // applico l'effetto allo span con id "messaggio" $("#messageBar").fadeTo(200, 0.1, function () { // per prima cosa mostro, con effetto fade, un messaggio di attesa $(this).removeClass().addClass('corretto').text('Login in...').fadeTo(900, 1, function () { // al termine effettuo il redirect alla pagina privata document.location = '../home/home.php'; }); }); } else { // stampo un messaggio di errore $("#messageBar").fadeTo(200, 0.1, function () { $(this).removeClass().addClass('errore').text("Invalid username or password").fadeTo(900, 1); }); console.log("res", res) } }); // evito il submit del form (che deve essere gestito solo dalla funzione Javascript) return false; }); var theme = getDemoTheme(); //$("#username, #password").addClass('jqx-input'); //if (theme != '') { $("#username, #password").addClass('jqx-input-' + theme); //} $("#loginButton").jqxButton({theme: 'classic'}); // add validation rules. $('#form').jqxValidator({ rules: [ //{ input: '#username', message: 'Username is required!', action: 'keyup, blur', rule: 'required' }, //{ input: '#username', message: 'Your username must start with a letter!', action: 'keyup, blur', rule: 'startWithLetter' }, //{ input: '#username', message: 'Your username must be between 3 and 12 characters!', action: 'keyup, blur', rule: 'length=3,12' }, {input: '#password', message: "Password is required!", action: 'keyup, blur', rule: 'required'}, {input: '#password', message: "Your password must be between 4 and 12 characters!", action: 'keyup, blur', rule: 'length=4,12'} ], theme: 'classic' }); $("#pageTitle").text(jQuery.i18n.prop('page_title_login')); $("#lblVersion").text(jQuery.i18n.prop('lbl_version')); $("#lblUsername").text(jQuery.i18n.prop('txt_username')); $("#lblPassword").text(jQuery.i18n.prop('txt_password')); $("#password-recovery-btn").data("click", 0).click(function () { $("#password-recovery-collapse").slideToggle() $("#login-form").slideToggle() }) $("#password").keydown(function (e) { if (e.which == 13) { $("#login-button").click() } }) $("[name=email]").keydown(function (e) { if (e.which == 13) { $("#email-recovery").click() return false } }) $("#email-recovery").click(function () { var email = $("[name=email]").val() if (!isEmail(email)) { alert("Insert a valid email") $("[name=email]").focus() return false } console.log("ajax ", "../login/emailRecoveryPwdJs.php") $.ajax({ url: "../login/emailRecoveryPwdJs.php", method: "post", datatype: "text", data: {"email": email}, success: function (r, s, x) { console.log("SUCCESS: ", r, s, x) eval(r) }, error: function (x, s, t) { console("ERR:", x, s, t) } }) }) }); function noEmailUserFound() { $("#messageBar").fadeTo(200, 1, function () { // per prima cosa mostro, con effetto fade, un messaggio di attesa $(this).removeClass().addClass('errore').text('User email not found').fadeTo(900, 1, function () { // al termine effettuo il redirect alla pagina privata //document.location = '../login/login.php'; }); }); } function userEmailFound() { $("#messageBar").fadeTo(200, 1, function () { // per prima cosa mostro, con effetto fade, un messaggio di attesa $(this).removeClass().addClass('corretto').text('Email sent').fadeTo(900, 1, function () { // al termine effettuo il redirect alla pagina privata document.location = '../login/login.php'; }); }); }