Confirm email

This commit is contained in:
Hillel Coren 2021-02-21 14:04:23 +02:00
parent bb7e05e9a4
commit dff671a999
5 changed files with 39 additions and 2 deletions

View File

@ -161,6 +161,14 @@ class AuthRepository {
password: password); password: password);
} }
Future<dynamic> resendConfirmation(
{@required Credentials credentials, @required String userId}) async {
return webClient.post(
'${credentials.url}/user/$userId/reconfirm',
credentials.token,
);
}
Future<LoginResponse> sendRequest({ Future<LoginResponse> sendRequest({
String url, String url,
dynamic data, dynamic data,

View File

@ -151,6 +151,15 @@ class LoadAccountSuccess implements StopLoading {
final LoginResponse loginResponse; final LoginResponse loginResponse;
} }
class ResendConfirmation implements StartLoading {}
class ResendConfirmationFailure implements StopLoading {
ResendConfirmationFailure(this.error);
final dynamic error;
}
class ResendConfirmationSuccess implements StopLoading {}
class RefreshData implements StartLoading { class RefreshData implements StartLoading {
RefreshData({ RefreshData({
this.completer, this.completer,

View File

@ -28,6 +28,7 @@ List<Middleware<AppState>> createStoreAuthMiddleware([
final addCompany = _createCompany(repository); final addCompany = _createCompany(repository);
final deleteCompany = _deleteCompany(repository); final deleteCompany = _deleteCompany(repository);
final purgeData = _purgeData(repository); final purgeData = _purgeData(repository);
final resendConfirmation = _resendConfirmation(repository);
return [ return [
TypedMiddleware<AppState, UserLogout>(userLogout), TypedMiddleware<AppState, UserLogout>(userLogout),
@ -40,6 +41,7 @@ List<Middleware<AppState>> createStoreAuthMiddleware([
TypedMiddleware<AppState, AddCompany>(addCompany), TypedMiddleware<AppState, AddCompany>(addCompany),
TypedMiddleware<AppState, DeleteCompanyRequest>(deleteCompany), TypedMiddleware<AppState, DeleteCompanyRequest>(deleteCompany),
TypedMiddleware<AppState, PurgeDataRequest>(purgeData), TypedMiddleware<AppState, PurgeDataRequest>(purgeData),
TypedMiddleware<AppState, ResendConfirmation>(resendConfirmation),
]; ];
} }
@ -371,6 +373,25 @@ Middleware<AppState> _purgeData(AuthRepository repository) {
}; };
} }
Middleware<AppState> _resendConfirmation(AuthRepository repository) {
return (Store<AppState> store, dynamic dynamicAction,
NextDispatcher next) async {
final action = dynamicAction as ResendConfirmation;
final state = store.state;
repository
.resendConfirmation(
credentials: state.credentials, userId: state.user.id)
.then((dynamic value) {
store.dispatch(ResendConfirmationSuccess());
}).catchError((Object error) {
store.dispatch(ResendConfirmationFailure(error));
});
next(action);
};
}
String _parseError(String error) { String _parseError(String error) {
const errorPattern = 'failed due to: Deserializing'; const errorPattern = 'failed due to: Deserializing';
if (error.contains(errorPattern)) { if (error.contains(errorPattern)) {

View File

@ -1,7 +1,6 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/constants.dart';
import 'package:invoiceninja_flutter/ui/app/buttons/elevated_button.dart';
import 'package:invoiceninja_flutter/ui/app/confirm_email_vm.dart'; import 'package:invoiceninja_flutter/ui/app/confirm_email_vm.dart';
import 'package:invoiceninja_flutter/ui/app/loading_indicator.dart'; import 'package:invoiceninja_flutter/ui/app/loading_indicator.dart';
import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/utils/localization.dart';

View File

@ -40,7 +40,7 @@ class ConfirmEmailVM {
store.dispatch(RefreshData()); store.dispatch(RefreshData());
}, },
onResendPressed: () { onResendPressed: () {
// store.dispatch(ResendConfirmation());
}, },
); );
} }