v1.1.27 deactivate customer

This commit is contained in:
Tibor Bossanyi (Freelancer)
2022-11-26 16:46:06 +01:00
parent dbdcf2f239
commit 98901f2770
10 changed files with 116 additions and 9 deletions
+21
View File
@@ -6,6 +6,8 @@ import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:meta/meta.dart';
import '../../service/customer_service.dart';
part 'account_event.dart';
part 'account_state.dart';
@@ -21,6 +23,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
on<AccountLogout>(_onLogout);
on<AccountGetTrainees>(_onGetTrainees);
on<AccountSelectTrainee>(_onSelectTrainees);
on<DeleteAccount>(_onDeleteAccount);
}
void _load() {
@@ -56,6 +59,24 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
emit(AccountReady());
}
void _onDeleteAccount(DeleteAccount event, Emitter<AccountState> emit) async {
emit(AccountLoading());
await Cache().logout();
customerRepository.customer = event.customer;
customerRepository.emptyTrainees();
loggedIn = false;
//delete local store
int customerId = customerRepository.customer!.customerId!;
await Cache().deleteCustomerId(customerId);
customerRepository.customer = null;
// deactivate user
await CustomerApi().deactivateCustomer(customerId);
emit(AccountReady());
}
void _onGetTrainees(AccountGetTrainees event, Emitter<AccountState> emit) async {
emit(AccountLoading());
await customerRepository.getTrainees();
+8
View File
@@ -20,6 +20,14 @@ class AccountLogin extends AccountEvent {
const AccountLogin();
}
class DeleteAccount extends AccountEvent {
final Customer customer;
const DeleteAccount ({required this.customer});
@override
List<Object> get props => [customer];
}
class AccountLogInFinished extends AccountEvent {
final Customer customer;
+1
View File
@@ -95,6 +95,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
Cache().setLoginType(LoginType.email);
emit(LoginSuccess());
} on Exception catch (e) {
print("Login error: $e" );
emit(LoginError(message: e.toString()));
}
}