Advertisement
Guest User

Untitled

a guest
Sep 4th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $("#repeatPassword, #passwordInput").on("keyup", function () {
  2.         if($password.value != "" && $repeatPassword.value != ""){
  3.             if($password.value != $repeatPassword.value){
  4.                 $("#repeatPassword").removeClass("is-valid").addClass("is-invalid");
  5.                 $("#repeat-password").removeClass("d-none valid-feedback").addClass("d-block invalid-feedback").text("Incorrect Password");
  6.                 matching = false;
  7.             } else{
  8.                 $("#repeatPassword").removeClass("is-invalid").addClass("is-valid");
  9.                 $("#repeat-password").removeClass("invalid-feedback").addClass("valid-feedback").text("Correct Password");
  10.                 matching = true;
  11.             }
  12.         }
  13.     });
  14.  
  15.     $("#username").on("keyup", function () {
  16.         $.post("/username", {input: $("#username").val()}, function (data) {
  17.             if(data.message == "EXIST"){
  18.                 $("#username").removeClass("is-valid").addClass("is-invalid");
  19.                 $("#choose-username").removeClass("d-none valid-feedback").addClass("d-block invalid-feedback").text("This username already exists");
  20.                 matchingUsername = false;
  21.             } else{
  22.                 $("#username").removeClass("is-invalid").addClass("is-valid");
  23.                 $("#choose-username").removeClass("invalid-feedback").addClass("valid-feedback").text("Valid Username");
  24.                 matchingUsername = true;
  25.             }
  26.         });
  27.     });
  28.  
  29.     $("#passwordInput").on("keyup", function () {
  30.         if(!checkPassword($password.value)){
  31.             $("#passwordInput").addClass("is-invalid");
  32.             $("#choose-password").removeClass("d-none valid-feedback").addClass("d-block invalid-feedback").text("Your password must be 8-20 character long, contain letters and numbers," +
  33.                 " and must not contain spaces or special characters.");
  34.             $("#passwordHelpBlock").addClass("d-none");
  35.         } else{
  36.             $("#passwordInput").removeClass("is-invalid").addClass("is-valid");
  37.             $("#choose-password").removeClass("d-none invalid-feedback").addClass("d-block valid-feedback").text("Safe Password");
  38.             $("#passwordHelpBlock").addClass("d-none");
  39.         }
  40.     });
  41.  
  42.     $("#registration-btn").on("click", function () {
  43.         if(checkingData() && matching && !toobig && matchingUsername){
  44.             var img = "";
  45.             if(imageloaded != "") img = imageloaded;
  46.             $.post("/register", { username: $username.value, password: $password.value,
  47.                 profileImg: img} , function(data){
  48.                 if(data.message == "BAD"){
  49.                     $("#alert-register").removeClass("d-none alert-success").addClass("d-block alert-danger").text("Something went wrong!");
  50.                 } else{
  51.                     var url = window.location.href;
  52.                     var pos = url.indexOf("register.html");
  53.                     window.location.href = url.substring(0, pos);
  54.                 }
  55.             });
  56.         }
  57.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement