cleanup
This commit is contained in:
		
							parent
							
								
									48e4f8eea4
								
							
						
					
					
						commit
						d0f02d1ad6
					
				
					 3 changed files with 10 additions and 14 deletions
				
			
		|  | @ -38,9 +38,10 @@ Response readAuthcode(Request request) { | ||||||
|     String code = params["code"].toString(); |     String code = params["code"].toString(); | ||||||
|     settings.saveAuthCode(code); |     settings.saveAuthCode(code); | ||||||
|   } |   } | ||||||
|   return Response(200, |   return Response(308, | ||||||
|  |       headers: {"Content-Type": "text/html; charset=UTF-8"}, | ||||||
|       body: |       body: | ||||||
|           "<html><head><meta http-equiv='Refresh' content='0; URL=https://example.com/'></head></html>"); |           "<html><head><meta http-equiv='Refresh' content='0; URL=https://git.kittycat.homes/zoe/slothmu'></head></html>"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // returns status code | // returns status code | ||||||
|  | @ -54,7 +55,6 @@ Future<int> handleFullOauth() async { | ||||||
|     await settings.saveAuthCode(""); |     await settings.saveAuthCode(""); | ||||||
|     var handler = const Pipeline().addHandler(readAuthcode); |     var handler = const Pipeline().addHandler(readAuthcode); | ||||||
|     var server = await shelf_io.serve(handler, 'localhost', 1312); |     var server = await shelf_io.serve(handler, 'localhost', 1312); | ||||||
|     server.idleTimeout = const Duration(minutes: 5); |  | ||||||
|     await pollCode(); |     await pollCode(); | ||||||
|     server.close(); |     server.close(); | ||||||
|     return 200; |     return 200; | ||||||
|  | @ -66,10 +66,9 @@ Future<int> handleFullOauth() async { | ||||||
| Future<String> pollCode() async { | Future<String> pollCode() async { | ||||||
|   String code = ""; |   String code = ""; | ||||||
|   while (code == "") { |   while (code == "") { | ||||||
|     await Future.delayed(const Duration(seconds: 1)); |     await Future.delayed(const Duration(seconds: 3)); | ||||||
|     code = await settings.loadAuthCode(); |     code = await settings.loadAuthCode(); | ||||||
|   } |   } | ||||||
|   print(code); |  | ||||||
|   return code; |   return code; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -77,7 +76,6 @@ Future<http.Response> doOauthFlow() async { | ||||||
|   String url = await settings.loadInstanceUrl(); |   String url = await settings.loadInstanceUrl(); | ||||||
|   try { |   try { | ||||||
|     http.Response response = await registerApp(url); |     http.Response response = await registerApp(url); | ||||||
|     print(response.body); |  | ||||||
|     openBrowserForAuthCode(url, App.fromJson(jsonDecode(response.body))); |     openBrowserForAuthCode(url, App.fromJson(jsonDecode(response.body))); | ||||||
|     return response; |     return response; | ||||||
|   } catch (e) { |   } catch (e) { | ||||||
|  |  | ||||||
|  | @ -1,15 +1,10 @@ | ||||||
| import 'package:shared_preferences/shared_preferences.dart'; | import 'package:shared_preferences/shared_preferences.dart'; | ||||||
| import 'package:slothmu/business_logic/auth/oauth.dart'; |  | ||||||
| 
 | 
 | ||||||
| enum Settings { | enum Settings { | ||||||
|   instanceUrl, |   instanceUrl, | ||||||
|   username, |   username, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void saveSetting(Settings setting, dynamic value) async { |  | ||||||
|   final prefs = await SharedPreferences.getInstance(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| Future<bool> saveInstanceUrl(String url) async { | Future<bool> saveInstanceUrl(String url) async { | ||||||
|   final prefs = await SharedPreferences.getInstance(); |   final prefs = await SharedPreferences.getInstance(); | ||||||
|   return await prefs.setString("instance-url", url); |   return await prefs.setString("instance-url", url); | ||||||
|  |  | ||||||
|  | @ -62,6 +62,7 @@ class _LoginFormState extends State<LoginForm> { | ||||||
|               if (value!.isEmpty || !isValidUsername(name: value)) { |               if (value!.isEmpty || !isValidUsername(name: value)) { | ||||||
|                 return "user-id-not-valid".i18n(); |                 return "user-id-not-valid".i18n(); | ||||||
|               } |               } | ||||||
|  |               return null; | ||||||
|             }, |             }, | ||||||
|           ), |           ), | ||||||
|           TextButton.icon( |           TextButton.icon( | ||||||
|  | @ -128,9 +129,11 @@ class _AuthPageState extends State<AuthPage> { | ||||||
|                     } |                     } | ||||||
|                   } |                   } | ||||||
|                   return TextButton.icon( |                   return TextButton.icon( | ||||||
|                       onPressed: null, |                       onPressed: () { | ||||||
|                       icon: const Icon(Icons.check), |                         Navigator.pushReplacementNamed(context, "/"); | ||||||
|                       label: Text("confirm-button".i18n())); |                       }, | ||||||
|  |                       icon: const Icon(Icons.arrow_forward), | ||||||
|  |                       label: Text("confirm".i18n())); | ||||||
|                 } else { |                 } else { | ||||||
|                   return const CircularProgressIndicator(); |                   return const CircularProgressIndicator(); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue