Advertisement
Guest User

Untitled

a guest
Sep 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var responseStatus;
  2.             var postBody = {
  3.                 UserName: travelNexusRegisterUsernameInput.value,
  4.                 Email: travelNexusRegisterEmailInput.value,
  5.                 Password: travelNexusRegisterPasswordInput.value,
  6.                 ConfirmPassword: travelNexusRegisterConfirmPasswordInput.value,
  7.                 PlayerId: travelNexusRegisterPlayerIdInput.value,
  8.                 ApiKey: travelNexusRegisterApiKeyInput.value
  9.             }
  10.             fetch("https://torn.plus/api/auth/register", {
  11.                 method: "POST",
  12.                 mode: "cors",
  13.                 headers: { "Content-Type": "application/json; charset=utf-8" },
  14.                 body: JSON.stringify(postBody)
  15.             }).then(response => {
  16.                 responseStatus = response.status;
  17.                 return response.json();
  18.             }).then(jsonResponse => {
  19.                     switch (responseStatus) {
  20.                         case 400:
  21.                             if (jsonResponse.UserName) {
  22.                                 for (var i in jsonResponse.UserName) {
  23.                                     console.log(jsonResponse.UserName[i]);
  24.                                 }
  25.  
  26.                             }
  27.                             if (jsonResponse.Email) {
  28.                                 for (var i in jsonResponse.Email) {
  29.                                     console.log(jsonResponse.Email[i]);
  30.                                 }
  31.  
  32.                             }
  33.                             if (jsonResponse.Password) {
  34.                                 for (var i in jsonResponse.Password) {
  35.                                     console.log(jsonResponse.Password[i]);
  36.                                 }
  37.                             }
  38.                             if (jsonResponse.ConfirmPassword) {
  39.                                 for (var i in jsonResponse.ConfirmPassword) {
  40.                                     console.log(jsonResponse.ConfirmPassword[i]);
  41.                                 }
  42.                             }
  43.                             if (jsonResponse.PlayerId) {
  44.                                 for (var i in jsonResponse.PlayerId) {
  45.                                     console.log(jsonResponse.PlayerId[i]);
  46.                                 }
  47.                             }
  48.                             if (jsonResponse.ApiKey) {
  49.                                 for (var i in jsonResponse.PlayerId) {
  50.                                     console.log(jsonResponse.ApiKey[i]);
  51.                                 }
  52.                             }
  53.                             break;
  54.                         case 200:
  55.                             if (jsonResponse.succeeded == true) {
  56.                                 //travelNexusRegisterErrorSpan.innerHTML = "Registration successful";
  57.                                 //travelNexusRegisterErrorSpan.classList.add("tornplus-error--success");
  58.                                 //travelNexusRegisterErrorSpan.classList.remove("tornplus-error--fail");
  59.                             }
  60.                             else {
  61.                                 //travelNexusRegisterErrorSpan.innerHTML = "Unknown error! Check the console log.";
  62.                                 //travelNexusRegisterErrorSpan.classList.remove("tornplus-error--success");
  63.                                 //travelNexusRegisterErrorSpan.classList.add("tornplus-error--fail");
  64.                                 console.log(jsonResponse.errors);
  65.                             }  
  66.                             break;
  67.                         default:
  68.                             //travelNexusRegisterErrorSpan.innerHTML = "Unknown error! Check the console log.";
  69.                             //travelNexusRegisterErrorSpan.classList.remove("tornplus-error--success");
  70.                             //travelNexusRegisterErrorSpan.classList.add("tornplus-error--fail");
  71.                             console.log(jsonResponse);
  72.                     }
  73.             }).catch(error => {
  74.                 console.log(error)
  75.             })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement