Kate
1 year ago
committed by
GitHub
20 changed files with 894 additions and 131 deletions
@ -1,3 +1,3 @@
|
||||
export 'package:neon/src/models/account.dart'; |
||||
export 'package:neon/src/models/account.dart' hide Credentials, LoginQrcode; |
||||
export 'package:neon/src/models/app_implementation.dart'; |
||||
export 'package:neon/src/models/notifications_interface.dart'; |
||||
|
@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart'; |
||||
import 'package:flutter_zxing/flutter_zxing.dart'; |
||||
import 'package:neon/src/models/account.dart'; |
||||
import 'package:neon/src/router.dart'; |
||||
import 'package:neon/src/utils/exceptions.dart'; |
||||
import 'package:neon/src/widgets/exception.dart'; |
||||
|
||||
class LoginQrcodePage extends StatefulWidget { |
||||
const LoginQrcodePage({ |
||||
super.key, |
||||
}); |
||||
|
||||
@override |
||||
State<LoginQrcodePage> createState() => _LoginQrcodePageState(); |
||||
} |
||||
|
||||
class _LoginQrcodePageState extends State<LoginQrcodePage> { |
||||
String? _lastErrorURL; |
||||
|
||||
@override |
||||
Widget build(final BuildContext context) => Scaffold( |
||||
appBar: AppBar(), |
||||
body: ReaderWidget( |
||||
codeFormat: Format.qrCode, |
||||
showGallery: false, |
||||
showToggleCamera: false, |
||||
showScannerOverlay: false, |
||||
tryHarder: true, |
||||
cropPercent: 0, |
||||
scanDelaySuccess: const Duration(seconds: 3), |
||||
onScan: (final code) async { |
||||
String? url; |
||||
try { |
||||
url = code.text; |
||||
if (url == null) { |
||||
throw InvalidQrcodeException(); |
||||
} |
||||
final match = LoginQrcode.tryParse(url); |
||||
if (match == null) { |
||||
throw InvalidQrcodeException(); |
||||
} |
||||
|
||||
LoginCheckServerStatusRoute.withCredentials( |
||||
serverUrl: match.serverURL, |
||||
loginName: match.username, |
||||
password: match.password, |
||||
).pushReplacement(context); |
||||
} catch (e, s) { |
||||
if (_lastErrorURL != url) { |
||||
debugPrint(e.toString()); |
||||
debugPrint(s.toString()); |
||||
|
||||
_lastErrorURL = url; |
||||
NeonException.showSnackbar(context, e); |
||||
} |
||||
} |
||||
}, |
||||
), |
||||
); |
||||
} |
@ -0,0 +1,25 @@
|
||||
import 'package:neon/src/models/account.dart'; |
||||
import 'package:test/test.dart'; |
||||
|
||||
void main() { |
||||
const qrCodePath = '/user:JohnDoe&password:super_secret&server:example.com'; |
||||
const qrCode = 'nc://login$qrCodePath'; |
||||
const invalidUrl = '::Not valid LoginQrcode::'; |
||||
const credentials = LoginQrcode( |
||||
serverURL: 'example.com', |
||||
username: 'JohnDoe', |
||||
password: 'super_secret', |
||||
); |
||||
|
||||
group('LoginQrcode', () { |
||||
test('parse', () { |
||||
expect(LoginQrcode.tryParse(qrCode), equals(credentials)); |
||||
expect(LoginQrcode.tryParse(qrCodePath), equals(credentials)); |
||||
expect(LoginQrcode.tryParse(invalidUrl), null); |
||||
}); |
||||
|
||||
test('equality', () { |
||||
expect(credentials, equals(credentials)); |
||||
}); |
||||
}); |
||||
} |
Loading…
Reference in new issue