ft/adds autologin after register
This commit is contained in:
parent
b7a189e409
commit
496b81a5f5
@ -1,10 +1,14 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:app/data/database.dart';
|
||||
import 'package:app/pb/account.pb.dart';
|
||||
import 'package:app/pb/rpc_create_account.pb.dart';
|
||||
import 'package:app/pb/rpc_get_account.pb.dart';
|
||||
import 'package:app/pb/rpc_get_account_info.pb.dart';
|
||||
import 'package:app/pb/rpc_login.pb.dart';
|
||||
import 'package:app/pb/rpc_refresh_token.pb.dart';
|
||||
import 'package:app/pb/service_df.pbgrpc.dart';
|
||||
import 'package:fixnum/fixnum.dart';
|
||||
import 'package:grpc/grpc.dart';
|
||||
|
||||
class GClient {
|
||||
@ -18,7 +22,7 @@ class GClient {
|
||||
Map<String, String> metadata = {'Authorization': ''};
|
||||
|
||||
late Session session;
|
||||
late Account account;
|
||||
Account? account;
|
||||
|
||||
static Future<GClient> get client async {
|
||||
Session s = await Session.session;
|
||||
@ -64,11 +68,11 @@ class GClient {
|
||||
));
|
||||
account = response.account;
|
||||
return response;
|
||||
} on GrpcError catch (e) {
|
||||
onError(error: e);
|
||||
print('GRPC ERROR: ${e.message}');
|
||||
} catch (e) {
|
||||
print('ERROR: $e');
|
||||
} on GrpcError catch (err) {
|
||||
onError(error: err);
|
||||
print('GRPC ERROR: ${err.message}');
|
||||
} catch (err) {
|
||||
print('ERROR: $err');
|
||||
}
|
||||
return CreateAccountResponse();
|
||||
}
|
||||
@ -96,12 +100,12 @@ class GClient {
|
||||
metadata['Authorization'] = 'Bearer ${response.accessToken}';
|
||||
onSuccess();
|
||||
return response;
|
||||
} on GrpcError catch (e) {
|
||||
print('caught error: ${e.message}');
|
||||
} on GrpcError catch (err) {
|
||||
print('caught error: ${err.message}');
|
||||
metadata['Authorization'] = '';
|
||||
onError(error: e);
|
||||
} catch (e) {
|
||||
print('caught error: $e');
|
||||
onError(error: err);
|
||||
} catch (err) {
|
||||
print('caught error: $err');
|
||||
metadata['Authorization'] = '';
|
||||
onError();
|
||||
}
|
||||
@ -128,12 +132,36 @@ class GClient {
|
||||
session.accessToken = response.accessToken;
|
||||
session.insertSession(session);
|
||||
return true;
|
||||
} on GrpcError catch (e) {
|
||||
print('caught grpc error: $e');
|
||||
} on GrpcError catch (err) {
|
||||
print('caught grpc error: $err');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<GetAccountResponse> getAccount(
|
||||
{required Int64 accountId,
|
||||
required Function({GrpcError? err}) onError}) async {
|
||||
GetAccountResponse response = GetAccountResponse();
|
||||
try {
|
||||
response = await stub.getAccount(GetAccountRequest(
|
||||
id: accountId,
|
||||
));
|
||||
account = response.account;
|
||||
} on GrpcError catch (err) {
|
||||
if (err.code == 16) {
|
||||
log(err.toString());
|
||||
onError(err: err);
|
||||
} else {
|
||||
log(err.toString());
|
||||
onError();
|
||||
}
|
||||
} catch (err) {
|
||||
log(err.toString());
|
||||
onError();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<GetAccountInfoResponse> getAccountInfo(GetAccountInfoRequest request,
|
||||
{required Function({String msg}) onError}) async {
|
||||
GetAccountInfoResponse response = GetAccountInfoResponse();
|
||||
@ -146,16 +174,16 @@ class GClient {
|
||||
),
|
||||
);
|
||||
return response;
|
||||
} on GrpcError catch (e) {
|
||||
print('caught grpc error: ${e.message} [${e.code}]');
|
||||
if (e.code == 16) {
|
||||
} on GrpcError catch (err) {
|
||||
print('caught grpc error: ${err.message} [${err.code}]');
|
||||
if (err.code == 16) {
|
||||
onError(msg: 'Sitzung ist abgelaufen.\nBitte loggen Sie sich neu ein.');
|
||||
} else {
|
||||
onError(msg: e.message != null ? e.message! : 'Interner Fehler');
|
||||
onError(msg: err.message != null ? err.message! : 'Interner Fehler');
|
||||
}
|
||||
} catch (e) {
|
||||
print('caught error: $e');
|
||||
onError();
|
||||
} catch (err) {
|
||||
print('caught error: $err');
|
||||
onError(msg: err.toString());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
@ -261,6 +261,65 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
.then(
|
||||
(r) {
|
||||
if (r.account.secretKey != '') {
|
||||
widget.client
|
||||
.login(
|
||||
email: mailController.text,
|
||||
password:
|
||||
passwordController.text,
|
||||
onError: (
|
||||
{GrpcError? error}) {},
|
||||
onSuccess: () {})
|
||||
.then((resp) {
|
||||
widget.client.getAccount(
|
||||
accountId: r.account.id,
|
||||
onError: ({GrpcError? err}) {
|
||||
_setLoading(false);
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text(
|
||||
'Login fehlgeschlagen',
|
||||
),
|
||||
action: SnackBarAction(
|
||||
textColor: Colors.grey,
|
||||
label: 'Details',
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
content: err !=
|
||||
null
|
||||
? Text(
|
||||
'Hoppla! Da ist etwas schief gelaufen..\n\n${err.message}',
|
||||
textAlign:
|
||||
TextAlign.center,
|
||||
style: const TextStyle(
|
||||
color:
|
||||
Colors.black),
|
||||
)
|
||||
: const Text(
|
||||
'Interner Fehler',
|
||||
textAlign:
|
||||
TextAlign.center,
|
||||
style: TextStyle(
|
||||
color:
|
||||
Colors.black),
|
||||
),
|
||||
icon:
|
||||
const Icon(
|
||||
Icons.error,
|
||||
color: Colors
|
||||
.black,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
|
@ -308,6 +308,19 @@ class _StartPageState extends State<StartPage> {
|
||||
'lib/assets/logo_300x200.png',
|
||||
),
|
||||
),
|
||||
if (widget.client.account != null &&
|
||||
!widget.client.account!.emailVerified)
|
||||
Container(
|
||||
height: 120,
|
||||
width: double.infinity,
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 20, horizontal: 10),
|
||||
child: Card(
|
||||
color: Colors.brown.shade300,
|
||||
child: const Text(
|
||||
'Deine E-Mail Adresse ist noch nicht validiert.'),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 40,
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user