This commit is contained in:
zoe 2022-07-02 00:26:58 +02:00
parent 48e4f8eea4
commit d0f02d1ad6
3 changed files with 10 additions and 14 deletions

View File

@ -38,9 +38,10 @@ Response readAuthcode(Request request) {
String code = params["code"].toString();
settings.saveAuthCode(code);
}
return Response(200,
return Response(308,
headers: {"Content-Type": "text/html; charset=UTF-8"},
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
@ -54,7 +55,6 @@ Future<int> handleFullOauth() async {
await settings.saveAuthCode("");
var handler = const Pipeline().addHandler(readAuthcode);
var server = await shelf_io.serve(handler, 'localhost', 1312);
server.idleTimeout = const Duration(minutes: 5);
await pollCode();
server.close();
return 200;
@ -66,10 +66,9 @@ Future<int> handleFullOauth() async {
Future<String> pollCode() async {
String code = "";
while (code == "") {
await Future.delayed(const Duration(seconds: 1));
await Future.delayed(const Duration(seconds: 3));
code = await settings.loadAuthCode();
}
print(code);
return code;
}
@ -77,7 +76,6 @@ Future<http.Response> doOauthFlow() async {
String url = await settings.loadInstanceUrl();
try {
http.Response response = await registerApp(url);
print(response.body);
openBrowserForAuthCode(url, App.fromJson(jsonDecode(response.body)));
return response;
} catch (e) {

View File

@ -1,15 +1,10 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:slothmu/business_logic/auth/oauth.dart';
enum Settings {
instanceUrl,
username,
}
void saveSetting(Settings setting, dynamic value) async {
final prefs = await SharedPreferences.getInstance();
}
Future<bool> saveInstanceUrl(String url) async {
final prefs = await SharedPreferences.getInstance();
return await prefs.setString("instance-url", url);

View File

@ -62,6 +62,7 @@ class _LoginFormState extends State<LoginForm> {
if (value!.isEmpty || !isValidUsername(name: value)) {
return "user-id-not-valid".i18n();
}
return null;
},
),
TextButton.icon(
@ -128,9 +129,11 @@ class _AuthPageState extends State<AuthPage> {
}
}
return TextButton.icon(
onPressed: null,
icon: const Icon(Icons.check),
label: Text("confirm-button".i18n()));
onPressed: () {
Navigator.pushReplacementNamed(context, "/");
},
icon: const Icon(Icons.arrow_forward),
label: Text("confirm".i18n()));
} else {
return const CircularProgressIndicator();
}