CINXE.COM
<!DOCTYPE html> <form action="" class="form modal-form" method="post" id="formLogin"> <h2>Collegati</h2> <label for="error" style="color:Red; line-height:12px; visibility:hidden">Sessione scaduta. Effettua di nuovo il login.</label> <label for="login-mail">E-MAILE</label> <input id="login-user" name="login-user" placeholder="Inserisci la tua e-mail" type="text"> <label for="login-pass">PASSWORD</label> <input id="login-pass" name="login-pass" placeholder="Inserisci la password" type="password"> <div class="login-actions"> <span class="login-register">Non ti sei ancora registrato? <a class="modalwindow fancybox.ajax" href="/shopv3/it/users/registro.html" title="">Fallo ora</a></span> <a class="modalwindow fancybox.ajax" href="/shopv3/it/users/password.html">Hai dimenticato la password?</a> </div> <div class="buttons"> <a href="javascript:enviaFormLogin()" class="button button-primary" id="submit">Entra</a> </div> </form> <script type="text/javascript"> $( document ).ready(function() { (function(d,s,id) { var js, fjs = d.getElementsByTagName(s)[0]; if(d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "http://connect.facebook.net/es_ES/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); window.fbAsyncInit = function() { FB.init({ appId : '967253789953504', cookie : true, xfbml : true, version : 'v2.0' }); } $("#submit").click(function() { //ga("send", "event", "Login", "Entrar", "", 1); }); }); function enviaFormLogin(){ mostrarCargador(); $.ajax({ type: "POST", url: '/shopv3/it/users/login.html', data: {user:$("#login-user").val(),pass:$("#login-pass").val()}, dataType:'json' }).done(function(res){ console.info("Login hecho"); tratarLogin(res); }); } function loginFacebook(){ FB.login(function(response){ validarUsuario(); }, {scope: 'public_profile, email'}); }; function validarUsuario() { FB.getLoginStatus(function(response) { if(response.status == 'connected') { FB.api('/me', function(response) { mostrarCargador(); $.ajax({ type: "POST", url: '/shopv3/it/users/facebook.json', data: {email:response.email,name:response.name,id:response.id}, dataType:'json' }).done(function(res){ tratarLogin(res); }); alert('Hola ' + response.name); }); } else if(response.status == 'not_authorized') { alert('Debes autorizar la app!'); } else { alert('Debes ingresar a tu cuenta de Facebook!'); } }); } function statusChangeCallback(response) { // The response object is returned with a status field that lets the // app know the current login status of the person. // Full docs on the response object can be found in the documentation // for FB.getLoginStatus(). if (response.status === 'connected') { // Logged into your app and Facebook. testAPI(); } else if (response.status === 'not_authorized') { // The person is logged into Facebook, but not your app. FB.api('/me', function(response) { console.log(response); }); //document.getElementById('status').innerHTML = 'Please log ' + // 'into this app.'; } else { // The person is not logged into Facebook, so we're not sure if // they are logged into this app or not. document.getElementById('status').innerHTML = 'Please log ' + 'into Facebook.'; } } function tratarLogin(res){ //var nombre = res.username; //if(res.nom!==""){ // nombre= res.nom+' '+res.cognom; //} //console.info(res); if(res.response.auth==="ok"){ console.info("Response ok. Escondemos cargador."); ocultarCargador(); window.location.reload(true); $.fancybox.close(); // $("#prelogin").before('<ul id="postlogin" class="header-user user-drop" ><li><a class="header-user-logged" href="#">'+nombre+'</a><ul><li><a href="/shopv3/it/users/view.html">Ver Perf铆l</a></li><li><a id="logout" href="#" onclick="logout();">Logout</a></li></ul></li></ul>'); // $("#prelogin").remove(); // $("#countFavoritos").html(res.numfav.toString()); } if(res.response.auth==="nok"){ ocultarCargador(); $('label[for="error"]').css('visibility', 'visible'); if(res.response.iderror===1){ //console.info("Paso por iderror 1"); $('label[for="error"]').html("La combinazione nome utente e password 猫 errata"); } else if(res.response.iderror===6){ //console.info("Paso por iderror 6"); $('label[for="error"]').html("Hai superato il numero massimo di tentativi. Prova pi霉 tardi"); } else{ $('label[for="error"]').html("Non 猫 stato possibile effettuare il login"); } } } </script>