Integrate users with api.js.
This commit is contained in:
		
							parent
							
								
									8cfa88e45d
								
							
						
					
					
						commit
						d436b32df8
					
				
					 2 changed files with 31 additions and 19 deletions
				
			
		|  | @ -243,3 +243,31 @@ function remove_synonym(tag_name, syn_name, callback) | ||||||
| 
 | 
 | ||||||
| /**************************************************************************************************/ | /**************************************************************************************************/ | ||||||
| api.users = {}; | api.users = {}; | ||||||
|  | 
 | ||||||
|  | api.users.login = | ||||||
|  | function login(username, password, callback) | ||||||
|  | { | ||||||
|  |     var url = "/login"; | ||||||
|  |     data = new FormData(); | ||||||
|  |     data.append("username", username); | ||||||
|  |     data.append("password", password); | ||||||
|  |     common.post(url, data, callback); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | api.users.logout = | ||||||
|  | function logout(callback) | ||||||
|  | { | ||||||
|  |     var url = "/logout"; | ||||||
|  |     common.post(url, null, callback); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | api.users.register = | ||||||
|  | function register(username, password_1, password_2, callback) | ||||||
|  | { | ||||||
|  |     var url = "/register"; | ||||||
|  |     data = new FormData(); | ||||||
|  |     data.append("username", username); | ||||||
|  |     data.append("password_1", password_1); | ||||||
|  |     data.append("password_2", password_2); | ||||||
|  |     common.post(url, data, callback); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -7,6 +7,7 @@ | ||||||
|     <meta name="viewport" content="width=device-width, initial-scale=1.0"/> |     <meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||||||
|     <link rel="stylesheet" href="/static/css/common.css"> |     <link rel="stylesheet" href="/static/css/common.css"> | ||||||
|     <script src="/static/js/common.js"></script> |     <script src="/static/js/common.js"></script> | ||||||
|  |     <script src="/static/js/api.js"></script> | ||||||
| 
 | 
 | ||||||
| <style> | <style> | ||||||
| input | input | ||||||
|  | @ -114,14 +115,6 @@ common.bind_box_to_button(register_input_password_2, register_input_button); | ||||||
| 
 | 
 | ||||||
| var message_area = document.getElementById("message_area"); | var message_area = document.getElementById("message_area"); | ||||||
| 
 | 
 | ||||||
| function login(username, password, callback) |  | ||||||
| { |  | ||||||
|     var url = "/login"; |  | ||||||
|     data = new FormData(); |  | ||||||
|     data.append("username", username); |  | ||||||
|     data.append("password", password); |  | ||||||
|     return common.post(url, data, callback); |  | ||||||
| } |  | ||||||
| function login_form() | function login_form() | ||||||
| { | { | ||||||
|     var username = document.getElementById("login_input_username").value; |     var username = document.getElementById("login_input_username").value; | ||||||
|  | @ -131,18 +124,9 @@ function login_form() | ||||||
|         common.create_message_bubble(message_area, "message_negative", "Fill out the form, yo."); |         common.create_message_bubble(message_area, "message_negative", "Fill out the form, yo."); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     return login(username, password, receive_callback) |     api.users.login(username, password, receive_callback) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function register(username, password_1, password_2, callback) |  | ||||||
| { |  | ||||||
|     var url = "/register"; |  | ||||||
|     data = new FormData(); |  | ||||||
|     data.append("username", username); |  | ||||||
|     data.append("password_1", password_1); |  | ||||||
|     data.append("password_2", password_2); |  | ||||||
|     return common.post(url, data, callback); |  | ||||||
| } |  | ||||||
| function register_form() | function register_form() | ||||||
| { | { | ||||||
|     var username = document.getElementById("register_input_username").value; |     var username = document.getElementById("register_input_username").value; | ||||||
|  | @ -153,7 +137,7 @@ function register_form() | ||||||
|         common.create_message_bubble(message_area, "message_negative", "Fill out the form, yo."); |         common.create_message_bubble(message_area, "message_negative", "Fill out the form, yo."); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     return register(username, password_1, password_2, receive_callback); |     api.users.register(username, password_1, password_2, receive_callback); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function receive_callback(response) | function receive_callback(response) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue