Changed from recieving strings to JSON
This commit is contained in:
		
							parent
							
								
									ddac236778
								
							
						
					
					
						commit
						dc63fcdc3e
					
				
					 3 changed files with 7 additions and 24 deletions
				
			
		
							
								
								
									
										29
									
								
								login.js
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								login.js
									
									
									
									
									
								
							|  | @ -9,31 +9,16 @@ form.addEventListener("submit", async function(event) { | ||||||
|     uname = formData.get('uname'); |     uname = formData.get('uname'); | ||||||
|     pin = formData.get('pin'); |     pin = formData.get('pin'); | ||||||
| 
 | 
 | ||||||
|     try { |     const response = await fetch(`/users/${uname}/${pin}`); | ||||||
|     const loginInfo = await loginFetch(); |     const loginInfo = await response.json(); | ||||||
| 
 |      | ||||||
|     if (loginInfo === "pin matches") { |     if (loginInfo.status === "ok") { | ||||||
|         login() |       login() | ||||||
|     } else if (loginInfo === "Incorrect pin" || loginInfo === `User ${uname} does not exist.`) { |     } else { | ||||||
|         incorrectLogin() |       incorrectLogin() | ||||||
|     } |  | ||||||
|     } catch { |  | ||||||
|         document.querySelector("#incorrect").innerHTML = 'An Error has Occurred. Try again later.' |  | ||||||
|     } |     } | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| async function loginFetch() { |  | ||||||
|     const rawResponse = await fetch(`/api/users/${uname}/${pin}`, { |  | ||||||
|         // credentials: "include",
 |  | ||||||
|         method: 'GET', |  | ||||||
|         headers: { |  | ||||||
|             'Accept': 'text/plain' |  | ||||||
|           }, |  | ||||||
| }); |  | ||||||
| const content = await rawResponse.text(); |  | ||||||
| return content |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function login() { | function login() { | ||||||
|     console.log('You have logged in!') |     console.log('You have logged in!') | ||||||
|     document.querySelector("#username").innerHTML = `${uname}` |     document.querySelector("#username").innerHTML = `${uname}` | ||||||
|  |  | ||||||
|  | @ -55,7 +55,6 @@ async function loginChange() { | ||||||
| const rawResponse = await fetch(`/api/users/change/${uname}/${pin}/${newUname}/${newPin}`, { | const rawResponse = await fetch(`/api/users/change/${uname}/${pin}/${newUname}/${newPin}`, { | ||||||
|     method: 'POST', |     method: 'POST', | ||||||
|     headers: { |     headers: { | ||||||
|       'Accept': 'text/plain' |  | ||||||
|     }, |     }, | ||||||
|     body: "" |     body: "" | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -45,7 +45,6 @@ async function register() { | ||||||
| const rawResponse = await fetch(`/api/register/${uname.toString().toLowerCase()}/${pin.toString()}/${pronouns.toString().toLowerCase().replace("/", ".")}`, { | const rawResponse = await fetch(`/api/register/${uname.toString().toLowerCase()}/${pin.toString()}/${pronouns.toString().toLowerCase().replace("/", ".")}`, { | ||||||
|     method: 'POST', |     method: 'POST', | ||||||
|     headers: { |     headers: { | ||||||
|       'Accept': 'text/plain' |  | ||||||
|     }, |     }, | ||||||
|     body: "" |     body: "" | ||||||
| }); | }); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue