save auth code
This commit is contained in:
parent
bb8680e3f6
commit
21e130b6f6
3 changed files with 41 additions and 4 deletions
|
@ -36,7 +36,7 @@ Response readAuthcode(Request request) {
|
|||
Map<String, String> params = request.url.queryParameters;
|
||||
if (params.containsKey("code") && params["code"] != null) {
|
||||
String code = params["code"].toString();
|
||||
print(code);
|
||||
settings.saveAuthCode(code);
|
||||
}
|
||||
return Response(200,
|
||||
body:
|
||||
|
@ -51,16 +51,28 @@ Future<int> handleFullOauth() async {
|
|||
return response.statusCode;
|
||||
}
|
||||
|
||||
await settings.saveAuthCode("");
|
||||
var handler = const Pipeline().addHandler(readAuthcode);
|
||||
var server = await shelf_io.serve(handler, 'localhost', 1312);
|
||||
server.idleTimeout = const Duration(minutes: 5);
|
||||
server.autoCompress = true;
|
||||
await pollCode();
|
||||
server.close();
|
||||
return 200;
|
||||
} catch (e) {
|
||||
return 400;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> pollCode() async {
|
||||
String code = "";
|
||||
while (code == "") {
|
||||
await Future.delayed(const Duration(seconds: 3));
|
||||
code = await settings.loadAuthCode();
|
||||
}
|
||||
print(code);
|
||||
return code;
|
||||
}
|
||||
|
||||
Future<http.Response> doOauthFlow() async {
|
||||
String url = await settings.loadInstanceUrl();
|
||||
try {
|
||||
|
|
|
@ -12,7 +12,7 @@ void saveSetting(Settings setting, dynamic value) async {
|
|||
|
||||
Future<bool> saveInstanceUrl(String url) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.setString("instance-url", url);
|
||||
return await prefs.setString("instance-url", url);
|
||||
}
|
||||
|
||||
Future<String> loadInstanceUrl() async {
|
||||
|
@ -27,5 +27,19 @@ Future<String> loadInstanceUrl() async {
|
|||
|
||||
Future<bool> saveUsername(String username) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.setString("username", username);
|
||||
return await prefs.setString("username", username);
|
||||
}
|
||||
|
||||
Future<bool> saveAuthCode(String code) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return await prefs.setString("authcode", code);
|
||||
}
|
||||
|
||||
Future<String> loadAuthCode() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
String? code = prefs.getString("authcode");
|
||||
if (code == null) {
|
||||
return "";
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
11
test/user/regex_test.dart
Normal file
11
test/user/regex_test.dart
Normal file
|
@ -0,0 +1,11 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
matchWords();
|
||||
}
|
||||
|
||||
void matchWords() {
|
||||
test("try matching some words", () {
|
||||
expect(RegExp(r"tiger").hasMatch("tigerfucker"), true);
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue