Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. // CHECK IF USER HAS AUTHENTICATED
  2. var username = document.cookie.replace(/(?:(?:^|.*;\s*)username\s*\=\s*([^;]*).*$)|^.*$/, "$1");
  3. var password = document.cookie.replace(/(?:(?:^|.*;\s*)password\s*\=\s*([^;]*).*$)|^.*$/, "$1");
  4.  
  5. if (username == "" || password == ""){
  6. window.location.replace("http://www.returnit.com:8080/returnitRest/login.html")
  7. }else{
  8.  
  9. $.ajax( {
  10. method: "POST",
  11. url: "http://www.returnit.com:8080/returnitRest/rest/user/authentication",
  12. beforeSend: function (xhr) {
  13. xhr.setRequestHeader ("Authorization", "Basic " + window.btoa(username + ":" + password));
  14. },
  15. // data: $.param(userFilter, true),
  16. contentType: "application/json",
  17. async: false
  18. } )
  19. .done( function(response){
  20. alert("authentication successful")
  21. })
  22. .fail( function(jqXHR){
  23. alert(jqXHR.statusText);
  24. window.location.replace("http://www.returnit.com:8080/returnitRest/login.html")
  25. });
  26. }
  27. // END OF AUTHENTICATION
  28.  
  29. var clients;
  30. var oldProduct;
  31. var curProductList = {};
  32. var curProductIndex;
  33.  
  34. var userFilter = {
  35. "inputEmail" : "",
  36. "inputFirstName" : "",
  37. "inputLastName" : "",
  38. "inputType" : "client"
  39. };
  40.  
  41. $.ajax( {
  42. // method: "POST",
  43. url: "http://www.returnit.com:8080/returnitRest/rest/user",
  44. data: $.param(userFilter, true),
  45. contentType: "application/json"
  46. } )
  47. .done( function(response){
  48. clients = response;
  49.  
  50. var options = $("#inputClient");
  51. options.append($("<option />").val("").text("All clients"));
  52.  
  53. $.each(clients, function() {
  54. options.append($("<option />").val(this.id).text(this.firstName + " " + this.lastName)); // TODO using email as key atm, should we use ID instead?
  55. });
  56. })
  57. .fail( function(jqXHR){
  58. alert(jqXHR.statusText);
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement