Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function(){
  2.     var url="http://localhost/phonegap/login/auth.php?callback=?";
  3.         //var url="http://localhost:3000/login/auth.php?callback=?";
  4.  
  5.     //Login Function
  6.     $("#login").click(function(){
  7.        
  8.         var email=$("#email").val();
  9.         var password=$("#password").val();
  10.         var dataString="email="+email+"&password="+password+"&login=";
  11.         if($.trim(email).length>0 & $.trim(password).length>0)
  12.         {
  13.             $.ajax({
  14.                 type: "POST",
  15.                 url: url,
  16.                 data: dataString,
  17.                 crossDomain: true,
  18.                 cache: false,
  19.                 beforeSend: function(){ $("#login").html('Connecting...');},
  20.                 success: function(data){
  21.                     if(data=="success")
  22.                     {
  23.                         localStorage.login="true";
  24.                         localStorage.email=email;
  25.                         window.location.href = "index.html";
  26.                     }
  27.                     else if(data="failed")
  28.                     {
  29.                         alert("Login error");
  30.                         $("#login").html('Login');
  31.                     }
  32.                 }
  33.             });
  34.         }return false;
  35.  
  36.     });
  37.  
  38.     //signup function
  39.     $("#signup").click(function(){
  40.         var fullname=$("#fullname").val();
  41.         var email=$("#email").val();
  42.         var password=$("#password").val();
  43.         var dataString="fullname="+fullname+"&email="+email+"&password="+password+"&signup=";
  44.  
  45.         if($.trim(fullname).length>0 & $.trim(email).length>0 & $.trim(password).length>0)
  46.         {
  47.             $.ajax({
  48.                 type: "POST",
  49.                 url: url,
  50.                 data: dataString,
  51.                 crossDomain: true,
  52.                 cache: false,
  53.                 beforeSend: function(){ $("#signup").val('Connecting...');},
  54.                 success: function(data){
  55.                     if(data=="success")
  56.                     {
  57.                         alert("Thank you for Registering with us! you can login now");
  58.                     }
  59.                     else if(data="exist")
  60.                     {
  61.                         alert("Hey! You alreay has account! you can login with us");
  62.                     }
  63.                     else if(data="failed")
  64.                     {
  65.                         alert("Something Went wrong");
  66.                     }
  67.                 }
  68.             });
  69.         }return false;
  70.  
  71.     });
  72.  
  73.     //Change Password
  74.     $("#change_password").click(function(){
  75.         var email=localStorage.email;
  76.         var old_password=$("#old_password").val();
  77.         var new_password=$("#new_password").val();
  78.         var dataString="old_password="+old_password+"&new_password="+new_password+"&email="+email+"&change_password=";
  79.         if($.trim(old_password).length>0 & $.trim(old_password).length>0)
  80.         {
  81.             $.ajax({
  82.                 type: "POST",
  83.                 url: url,
  84.                 data: dataString,
  85.                 crossDomain: true,
  86.                 cache: false,
  87.                 beforeSend: function(){ $("#change_password").val('Connecting...');},
  88.                 success: function(data){
  89.                     if(data=="incorrect")
  90.                     {
  91.                         alert("Your old password is incorrect");
  92.                     }
  93.                     else if(data="success")
  94.                     {
  95.                         alert("Password Changed successfully");
  96.                     }
  97.                     else if(data="failed")
  98.                     {
  99.                         alert("Something Went wrong");
  100.                     }
  101.                 }
  102.             });
  103.         }return false;
  104.  
  105.     });
  106.  
  107.     //Forget Password
  108.     $("#forget_password").click(function(){
  109.         var email=$("#email").val();
  110.         var dataString="email="+email+"&forget_password=";
  111.         if($.trim(email).length>0)
  112.         {
  113.             $.ajax({
  114.                 type: "POST",
  115.                 url: url,
  116.                 data: dataString,
  117.                 crossDomain: true,
  118.                 cache: false,
  119.                 beforeSend: function(){ $("#forget_password").val('Connecting...');},
  120.                 success: function(data){
  121.                     if(data=="invalid")
  122.                     {
  123.                         alert("Your have not registered with us");
  124.                     }
  125.                     else if(data="success")
  126.                     {
  127.                         alert("we have sent password to your email address, please check");
  128.                     }
  129.                 }
  130.             });
  131.         }return false;
  132.  
  133.     });
  134.  
  135.  
  136.     //logout function
  137.     $("#logout").click(function(){
  138.         localStorage.login="false";
  139.         window.location.href = "login.html";
  140.     });
  141.  
  142.     //Displaying user email on home page
  143.     $("#email1").html(localStorage.email);
  144.     var imageHash="http://www.gravatar.com/avatar/"+md5(localStorage.email);
  145.     $("#profilepic").attr('src',imageHash);
  146. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement