@@ -7,6 +7,7 @@ import 'package:nextcloud/nextcloud.dart';
7
7
import 'package:nextcloud_cookbook_flutter/src/blocs/authentication/authentication_bloc.dart' ;
8
8
import 'package:nextcloud_cookbook_flutter/src/models/app_authentication.dart' ;
9
9
import 'package:nextcloud_cookbook_flutter/src/services/services.dart' ;
10
+ import 'package:nextcloud_cookbook_flutter/src/util/nextcloud_login_qr_util.dart' ;
10
11
import 'package:nextcloud_cookbook_flutter/src/util/url_validator.dart' ;
11
12
12
13
part 'login_event.dart' ;
@@ -17,6 +18,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
17
18
required this .authenticationBloc,
18
19
}) : super (const LoginState ()) {
19
20
on < LoginFlowStart > (_mapLoginFlowStartEventToState);
21
+ on < LoginQRScenned > (_mapLoginQRScannedEventToState);
20
22
}
21
23
final UserRepository userRepository = UserRepository ();
22
24
final AuthenticationBloc authenticationBloc;
@@ -54,4 +56,27 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
54
56
emit (LoginState (status: LoginStatus .failure, error: e.toString ()));
55
57
}
56
58
}
59
+
60
+ Future <void > _mapLoginQRScannedEventToState (
61
+ LoginQRScenned event,
62
+ Emitter <LoginState > emit,
63
+ ) async {
64
+ assert (event.uri.isScheme ('nc' ));
65
+ try {
66
+ final auth = parseNCLoginQR (event.uri);
67
+
68
+ authenticationBloc.add (
69
+ LoggedIn (
70
+ appAuthentication: AppAuthentication (
71
+ server: auth['server' ]! ,
72
+ loginName: auth['user' ]! ,
73
+ appPassword: auth['password' ]! ,
74
+ isSelfSignedCertificate: false ,
75
+ ),
76
+ ),
77
+ );
78
+ } catch (e) {
79
+ emit (LoginState (status: LoginStatus .failure, error: e.toString ()));
80
+ }
81
+ }
57
82
}
0 commit comments