Advertisement
Guest User

Untitled

a guest
Apr 12th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function(){
  2.  
  3.     console.log("sanity check");
  4.  
  5.     function logincheck(username, password){
  6.         var url = 'http://localhost:3000/login/';
  7.  
  8.         console.log('username', username);
  9.         console.log('password', password);
  10.  
  11.         var data = {
  12.                 username: username,
  13.                 password: password
  14.             };
  15.  
  16.         var pushlogin = $.ajax({
  17.                             type:"POST",
  18.                             url:url,
  19.                             data
  20.                          });
  21.  
  22.         pushlogin.done(function(response){
  23.             console.log("loginYATA", response.goto);
  24.  
  25.  
  26.             if (response.goto==="passwordsdontmatch"){
  27.                 alert("password or username is not correct");
  28.             }else{
  29.                 //the following localstorage set is to identify users in chat
  30.                 localStorage.setItem('username', username);
  31.  
  32.                 if (response.goto==='charityportal'){
  33.                     window.location.href = 'charityProfile.html';
  34.                 }else if (response.goto==='donatorportal'){
  35.                     window.location.href = 'donorProfile.html';
  36.                 }
  37.             }
  38.         });
  39.  
  40.     }
  41.  
  42.  
  43.  
  44.     function pushdonatorinfo(){
  45.         console.log('got to pushdonatorinfo');
  46.         var url = 'http://localhost:3000/login/signup/donatorpost';
  47.  
  48.         var name = $('.donorname').val();
  49.         var username = $('.donoremail').val();
  50.         var email = $('.donoremail').val();
  51.  
  52.         var data3 = {
  53.             name: name,
  54.             username: username,
  55.             email: email
  56.         }
  57.  
  58.         var pushdonator = $.ajax({
  59.             type:"POST",
  60.             url:url,
  61.             data: data3
  62.         },
  63.         console.log(data3));
  64.  
  65.         pushdonator.done(function(response){
  66.             //console.log('donatorpushYATA ', response);
  67.             window.location.href='donorProfile.html';
  68.         });
  69.  
  70.     }
  71.  
  72.  
  73.  
  74.  
  75.     function pushcharityinfo(){
  76.         var url = 'http://localhost:3000/login/signup/charitypost';
  77.  
  78.         var name = $(".charityorginizationname").val();
  79.         var address = $(".charityaddress").val();
  80.         var organizationname = $(".charityorginizationname").val();
  81.             var email = $('.charityemail').val();
  82.  
  83.         console.log(" name ", name, " address ", address);
  84.  
  85.         var data2 = {
  86.             //bio: name,
  87.             profileManager: me,
  88.                 email: email,
  89.             streetAddress: address,
  90.             charityName: organizationname
  91.         };
  92.  
  93.         var pushcharity = $.ajax({
  94.             type:"POST",
  95.             url:url,
  96.             data: data2
  97.         },
  98.         console.log(data2));
  99.  
  100.         pushcharity.done(function(response){
  101.             console.log("charitypushYATA ", response);
  102.             window.location.href = 'charityProfile.html'
  103.         });
  104.     }
  105.  
  106.  
  107.  
  108.     function signup(username, password, type){
  109.         var url = 'http://localhost:3000/login/signup';
  110.  
  111.         var data = {
  112.                 username: username,
  113.                 password: password,
  114.                 type: type
  115.             };
  116.  
  117.         var pushsignup = $.ajax({
  118.                             type:"POST",
  119.                             url:url,
  120.                             data:data
  121.                          });
  122.  
  123.         pushsignup.done(function(response){
  124.             console.log("signupYATA", response);
  125.             if (response.status==='ok'){
  126.  
  127.                 localStorage.setItem('username', username);
  128.  
  129.                 alert('user succesfully added to the db');
  130.                 if (type === "charity"){
  131.                     pushcharityinfo(); 
  132.                 }else if (type === "donator"){
  133.                     pushdonatorinfo();
  134.                 }                  
  135.  
  136.             }
  137.             if (response.status==='reject'){
  138.                 alert('username already taken, please choose another');
  139.             }
  140.  
  141.         });
  142.     }
  143.  
  144.     $("#USERlogin").submit(function(){
  145.  
  146.             //NOTE: can't add passwords to database manually and check - the passwords need to be hashed to be properly searched!
  147.  
  148.             if (($(".USERusernamesignin").val() != "") && ($(".USERpasswordsignin").val() != "")){
  149.                 console.log("USERusernamesignin ", $(".USERusernamesignin").val());
  150.                 console.log("USERpasswordsignin ", $(".USERpasswordsignin").val());
  151.                 logincheck($(".USERusernamesignin").val(), $(".USERpasswordsignin").val());
  152.             }
  153.         return false;
  154.     });
  155.  
  156.  
  157.     $("#charitysignup").on("submit", function(e){
  158.         e.preventDefault();
  159.             if($(".charitypassword").val()===$(".charityconfirmpassword").val() && $(".charityemail").val()!="" && $(".charitypassword").val()!=""){
  160.                 signup($(".charityemail").val(), $(".charitypassword").val(), "charity");
  161.             }
  162.     });
  163.  
  164.     $('#donorsubmitform').on("submit", function(e){
  165.         e.preventDefault();
  166.             if($('.donorpassword').val()===$('.donorconfirmpassword').val() && $('.donoremail').val()!="" && $('.donorconfirmpassword').val()!=""){
  167.                 signup($(".donoremail").val(), $(".donorpassword").val(), "donator");
  168.             }
  169.     });
  170. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement