New code verification service
Some checks failed
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
ci/woodpecker/push/bump_version Pipeline failed
Some checks failed
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
ci/woodpecker/push/bump_version Pipeline failed
This commit is contained in:
@@ -1,38 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
import 'package:pweb/services/auth.dart';
|
||||
|
||||
import 'package:pshared/models/auth/pending_login.dart';
|
||||
import 'package:pshared/provider/account.dart';
|
||||
import 'package:pshared/service/account.dart';
|
||||
|
||||
class TwoFactorProvider extends ChangeNotifier {
|
||||
final AuthenticationService _authService;
|
||||
static final _logger = Logger('provider.two_factor');
|
||||
final AccountProvider _accountProvider;
|
||||
|
||||
TwoFactorProvider(this._authService);
|
||||
TwoFactorProvider({required AccountProvider accountProvider}) : _accountProvider = accountProvider;
|
||||
|
||||
bool _isSubmitting = false;
|
||||
bool _hasError = false;
|
||||
bool _verificationSuccess = false;
|
||||
String? _errorMessage;
|
||||
|
||||
bool get isSubmitting => _isSubmitting;
|
||||
bool get hasError => _hasError;
|
||||
bool get verificationSuccess => _verificationSuccess;
|
||||
String? get errorMessage => _errorMessage;
|
||||
PendingLogin? get pendingLogin => _accountProvider.pendingLogin;
|
||||
|
||||
|
||||
Future<void> submitCode(String code) async {
|
||||
_isSubmitting = true;
|
||||
_hasError = false;
|
||||
_errorMessage = null;
|
||||
_verificationSuccess = false;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final success = await _authService.verifyTwoFactorCode(code);
|
||||
if (success) {
|
||||
_verificationSuccess = true;
|
||||
final pending = _accountProvider.pendingLogin;
|
||||
if (pending == null) {
|
||||
throw Exception('No pending login available');
|
||||
}
|
||||
final account = await AccountService.confirmLoginCode(
|
||||
pending: pending,
|
||||
code: code,
|
||||
);
|
||||
_accountProvider.completePendingLogin(account);
|
||||
_verificationSuccess = true;
|
||||
} catch (e) {
|
||||
_hasError = true;
|
||||
_errorMessage = e.toString();
|
||||
_logger.warning('Failed to verify code', e);
|
||||
} finally {
|
||||
_isSubmitting = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> resendCode() async {
|
||||
final pending = _accountProvider.pendingLogin;
|
||||
if (pending == null) {
|
||||
_logger.warning('No pending login to resend code for');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await AccountService.resendLoginCode(pending);
|
||||
} catch (e) {
|
||||
_logger.warning('Failed to resend login code', e);
|
||||
_hasError = true;
|
||||
_errorMessage = e.toString();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user