Guest User

Untitled

a guest
Sep 26th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1. // about on line 37, there is a ajaxRequest.responseText that has no value
  2. var store_reguser;
  3. var ajaxRequest;
  4. /* in ajax() I am trying to assign a value to ajaxRequest
  5. to make it possible to do ajax requests */
  6. function ajax()
  7. {
  8. if (window.XMLHttpRequest)
  9. {//Code for IE7+, Firefox, Chrome, Opera, Safari
  10. ajaxRequest=new XMLHttpRequest();
  11. console.log('making ajaxRequest worked');
  12. }
  13. else
  14. {//code for IE6, IE5
  15. ajaxRequest=new ActiveXObject("Microsoft.XMLHTTP");
  16. }
  17. }
  18.  
  19.  
  20. /* What this function does is that it checks if the username and password correspond.
  21. It is a simple login function.*/
  22. if(ajaxRequeast=aslkdj){}
  23. function loginFunction()
  24. {
  25. console.log('thefuncisexecuted');
  26. ajaxRequest.onreadystatechange = function(){
  27. if(ajaxRequest.readyState == 4)
  28. {
  29. if(ajaxRequest.responseText == "ok")
  30. {
  31. console.log('passwords match');
  32. logintosite();
  33. }
  34. else
  35. {
  36.  
  37. //***The error is here //Here
  38. console.log ('expecting not ok ' +ajaxRequest);
  39. document.getElementById('mySpan2').innerHTML = ajaxRequest.responseText;
  40. }
  41. }
  42. }
  43. //sending the username and password to the sever
  44. var usernameID = document.getElementById('usernameID').value;
  45. var password = document.getElementById('password').value;
  46. var queryString2 = "?username=" +usernameID +"&pass=" +password;
  47. ajaxRequest.open("GET", "checkLogin.php" +queryString2, true);
  48. ajaxRequest.send(null);
  49. console.log('you reached it');
  50. }
  51.  
  52. /* Here, I am trying to see if the input is okay. I use in_ and out because there are two
  53. different inputs ( register and login ) which use this function. I did this just because
  54. of a recommendation on an IRC chat.
  55.  
  56. What the function does is that it sends the input
  57. to ServerUsers to check if this username exists in the database.*/
  58. function usernameVer(in_, out)
  59. {
  60. //function which will get data from server.
  61. ajaxRequest.onreadystatechange = function()
  62. {
  63. if(ajaxRequest.readyState == 4)
  64. {
  65. var input = document.getElementById(in_).value;
  66. if(input != "")
  67. {
  68. console.log('yeah: ' +ajaxRequest);
  69. if(in_ == 'user1') // <-- If the input is the registration input
  70. {
  71. if(ajaxRequest.responseText == "cross")
  72. // ^-- If the server response is a redcross, it means that the username does not exist in the database
  73. {
  74. console.log('response:' +ajaxRequest.responseText);
  75. document.getElementById(out).innerHTML = "<img src='greencheck.png' height='20' width='20' />"
  76. // ^-- So it is okay for the user to use that username for registration
  77.  
  78.  
  79. //Ignore this, it is related to disabling/enabling the registration button
  80. store_reguser = "nodisable";
  81. if(store_regpass == "ok")
  82. {
  83. document.getElementById('regbutton').disabled = false;
  84. }
  85. }
  86. if(ajaxRequest.responseText == "check")
  87. // Same as above, but inverted. So if the username exists on the db, the person cannot register with that username...
  88. {
  89. console.log('expecting a username' +document.getElementById('user1').value);
  90. document.getElementById(out).innerHTML = "<img src='redcross.png' height='20' width='20' />";
  91.  
  92.  
  93. //Ignore this --v
  94. store_reguser = "disable";
  95. document.getElementById('regbutton').disabled = true;
  96. }
  97. }else{
  98. if(ajaxRequest.responseText == "check"){
  99. document.getElementById(out).innerHTML = "<img src='greencheck.png' height='20' width='20' />";
  100. }else{
  101. document.getElementById(out).innerHTML = "<img src='redcross.png' height='20' width='20' />";
  102. }
  103. }
  104. }
  105. else
  106. {// If the input is empty, it disables the registration button...
  107. document.getElementById('regbutton').disabled = true;
  108. document.getElementById(out).innerHTML = "";
  109. }
  110. }
  111. }
  112. // Here, it sends the username to the server
  113. var usernameID = document.getElementById(in_).value;
  114. var queryString = "?usernameID=" +usernameID;
  115. ajaxRequest.open("GET", "ServerUsers.php" +queryString, true);
  116. ajaxRequest.send(null);
  117.  
  118.  
  119. }
  120.  
  121.  
  122.  
  123. /* Here I check if the first password in the registration form is equal to the second one,
  124. If they are not the same, there is a redcross appearing next to the input and the
  125. registration button is disabled*/
  126. var store_regpass;
  127. function confirmPass(){
  128. var pass1 = document.getElementById('pass1').value;
  129. var pass2 = document.getElementById('pass2').value;
  130. if(pass1 == pass2) // Pretty simple
  131. {
  132. var greencheck = "<img src='greencheck.png' height='20' width='20' />";
  133. document.getElementById('confpass').innerHTML = greencheck;
  134. document.getElementById('regbutton').disabled = false;
  135.  
  136.  
  137. //Ignore this --v Trying to make the registration more user friendly
  138. store_regpass = "ok";
  139. console.log ('expecting a username ' +document.getElementById('user1').value);
  140. if (store_reguser == "disable" || !store_reguser || store_reguser == "" || document.getElementById('user1').value == ""){
  141. console.log ('store_reguser');
  142. document.getElementById('regbutton').disabled = true;
  143. }
  144. }
  145. else
  146. {
  147. //Ignore this
  148. store_regpass = "not ok";
  149. var redcross = "<img src='redcross.png' height='20' width='20' />";
  150.  
  151. //If the passwords do not match, there is a red cross...
  152. document.getElementById('confpass').innerHTML = redcross;
  153. document.getElementById('regbutton').disabled = true;
  154. }
  155. }
  156.  
  157.  
  158. /* This function simply checks if the inputs in the login for are filled or not,
  159. If they are filled, the user can try to log in. If they are not, the login
  160. button is disabled. */
  161. function checkIfLog(){
  162. var user = document.getElementById('usernameID').value;
  163. var pass = document.getElementById('password').value;
  164. if(pass == "" || user == "")
  165. {
  166. document.getElementById('submitLog').disabled = true;
  167. }
  168. else
  169. {
  170. document.getElementById('submitLog').disabled = false;
  171. }
  172. }
  173.  
  174.  
  175. /* This function is used to register a username and a password to a database. */
  176. function registerR(){
  177. ajaxRequest.onreadystatechange = function(){
  178. if(ajaxRequest.readyState == 4){
  179. if(ajaxRequest.responseText == "ok"){ //If the server return "ok", then the registration WORKED.
  180. document.getElementById('regspan').innerHTML = "Registration was a success! You can now Log in.";
  181. }
  182. else{ //If it returns "not ok", the registration FAILED
  183. document.getElementById('regspan').innerHTML = "Registration Failed.";
  184. console.log('expecting a response other than "ok": ' +ajaxRequest.responseText);
  185. }
  186. }
  187. }
  188.  
  189. //Sends the values username, password1, and password2 to the server.
  190. var username = document.getElementById('user1').value;
  191. var password1 = document.getElementById('pass1').value;
  192. var password2 = document.getElementById('pass2').value;
  193. var query = "?usernameR=" +username +"&passwordR1=" +password1 +"&passwordR2=" +password2;
  194. ajaxRequest.open("GET", "register.php" +query, true);
  195. ajaxRequest.send(null);
  196. //console.log ('expecting a query' +"register.php" +query);
  197. }
  198.  
  199. function logintosite(){
  200. window.location = "loggedIn.php";
  201. }
Add Comment
Please, Sign In to add comment