Compare commits
	
		
			2 commits
		
	
	
		
			5543b1e8c5
			...
			c826b6b5db
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | c826b6b5db | ||
|  | d875ce398f | 
					 2 changed files with 32 additions and 21 deletions
				
			
		
							
								
								
									
										31
									
								
								chat.js
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								chat.js
									
									
									
									
									
								
							|  | @ -12,17 +12,21 @@ form.addEventListener("submit", async function (event) { | |||
| 
 | ||||
|     formMessage = formData.get('message').toString(); | ||||
| 
 | ||||
|         //KINDA UNNECESSARY
 | ||||
|         //CHECKS TO SEE IF THE PERSON IS LOGGED IN IN ORDER TO SEND A MESSAGE.
 | ||||
|         const response = await fetch(`api/token/${username}/`); | ||||
|         const matches = await response.json(); | ||||
|     //KINDA UNNECESSARY
 | ||||
|     //CHECKS TO SEE IF THE PERSON IS LOGGED IN IN ORDER TO SEND A MESSAGE.
 | ||||
|     const response = await fetch(`api/token/${username}/`); | ||||
|     const matches = await response.json(); | ||||
| 
 | ||||
|     //YES THIS IS CONFUSING I KNOW.
 | ||||
|     if (matches.status === "ok") { | ||||
|         sendMessage() | ||||
|     } else { | ||||
|         const mismatch = 'Username and token mismatch. Try logging in again.' | ||||
|         printText(mismatch.bold()) | ||||
|         logout() | ||||
|         localStorage.removeItem('username') | ||||
|     } | ||||
| 
 | ||||
|         //YES THIS IS CONFUSING I KNOW.
 | ||||
|         if (matches.status === "ok") { | ||||
|           sendMessage() | ||||
|         } else { | ||||
|             document.querySelector("#errormessage").innerHTML = 'Username and token mismatch. Try logging in again.' | ||||
|         } | ||||
| }) | ||||
| 
 | ||||
| //SEND MESSAGE FETCH FUNCTION
 | ||||
|  | @ -87,3 +91,10 @@ loggedIn() | |||
| 
 | ||||
| 
 | ||||
| //REVIECE USERS PRONOUNS
 | ||||
| 
 | ||||
| async function getPronouns() { | ||||
| const response = await fetch(`api/users/${username}/`); | ||||
| const data = await response.json(); | ||||
| pronouns = data.pronouns | ||||
| return pronouns; | ||||
| } | ||||
							
								
								
									
										18
									
								
								logout.js
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								logout.js
									
									
									
									
									
								
							|  | @ -20,13 +20,13 @@ async function logout() { | |||
|   loggedIn() | ||||
| } | ||||
| 
 | ||||
| // // IF THERE IS A TOKEN BUT NO USERNAME LOGOUT
 | ||||
| // if (allCookies !== '' && myStorage.length === 0) {
 | ||||
| //   logout()
 | ||||
| // }
 | ||||
| // IF THERE IS A TOKEN BUT NO USERNAME LOGOUT
 | ||||
| if (allCookies !== '' && myStorage.length === 0) { | ||||
|   logout() | ||||
| } | ||||
| 
 | ||||
| // // IF THERE IS NO COOKIE BUT A USERNAME GET RID OF USERNAME LOCALLY.
 | ||||
| // if (allCookies === '' && myStorage.length !== 0) {
 | ||||
| //   localStorage.removeItem('username')
 | ||||
| //   document.querySelector("#loggeduser").innerHTML = 'You are not logged in'
 | ||||
| // }
 | ||||
| // IF THERE IS NO COOKIE BUT A USERNAME GET RID OF USERNAME LOCALLY.
 | ||||
| if (allCookies === '' && myStorage.length !== 0) { | ||||
|   localStorage.removeItem('username') | ||||
|   document.querySelector("#loggeduser").innerHTML = 'You are not logged in' | ||||
| } | ||||
		Loading…
	
		Reference in a new issue