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

This commit is contained in:
Stephan D
2025-11-21 16:41:41 +01:00
parent ef5b3dc1a7
commit e1e4c580e8
72 changed files with 1660 additions and 454 deletions

View File

@@ -24,7 +24,6 @@ import 'package:pweb/providers/two_factor.dart';
import 'package:pweb/providers/upload_history.dart';
import 'package:pweb/providers/wallets.dart';
import 'package:pweb/services/amplitude.dart';
import 'package:pweb/services/auth.dart';
import 'package:pweb/services/balance.dart';
import 'package:pweb/services/payments/payment_methods.dart';
import 'package:pweb/services/payments/upload_history.dart';
@@ -53,17 +52,16 @@ void main() async {
runApp(
MultiProvider(
providers: [
Provider<AuthenticationService>(
create: (_) => AuthenticationService(),
),
ChangeNotifierProxyProvider<AuthenticationService, TwoFactorProvider>(
create: (context) => TwoFactorProvider(
context.read<AuthenticationService>(),
),
update: (context, authService, previous) => TwoFactorProvider(authService),
),
ChangeNotifierProvider(create: (_) => LocaleProvider(null)),
ChangeNotifierProvider(create: (_) => AccountProvider()),
ChangeNotifierProxyProvider<AccountProvider, TwoFactorProvider>(
create: (context) => TwoFactorProvider(
accountProvider: context.read<AccountProvider>(),
),
update: (context, accountProvider, previous) => TwoFactorProvider(
accountProvider: accountProvider,
),
),
ChangeNotifierProvider(create: (_) => OrganizationsProvider()),
ChangeNotifierProvider(create: (_) => AccountProvider()),
ChangeNotifierProvider(create: (_) => CarouselIndexProvider()),

View File

@@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:pweb/generated/i18n/app_localizations.dart';
import 'package:pweb/providers/two_factor.dart';
class ResendCodeButton extends StatelessWidget {
@@ -12,9 +15,7 @@ class ResendCodeButton extends StatelessWidget {
final localizations = AppLocalizations.of(context)!;
return TextButton(
onPressed: () {
// TODO: Add resend logic
},
onPressed: () => context.read<TwoFactorProvider>().resendCode(),
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
minimumSize: const Size(0, 0),
@@ -28,4 +29,4 @@ class ResendCodeButton extends StatelessWidget {
child: Text(localizations.twoFactorResend),
);
}
}
}

View File

@@ -38,13 +38,16 @@ class _LoginFormState extends State<LoginForm> {
final provider = Provider.of<AccountProvider>(context, listen: false);
try {
//final account =
await provider.login(
final outcome = await provider.login(
email: _usernameController.text,
password: _passwordController.text,
locale: context.read<LocaleProvider>().locale.languageCode,
);
onLogin();
if (outcome.isPending) {
navigateAndReplace(context, Pages.sfactor);
} else {
onLogin();
}
return 'ok';
} catch (e) {
onError(provider.error ?? e);
@@ -92,7 +95,7 @@ class _LoginFormState extends State<LoginForm> {
onSignUp: () => navigate(context, Pages.signup),
login: () => _login(
context,
() => navigateAndReplace(context, Pages.sfactor),
() => navigateAndReplace(context, Pages.dashboard),
(e) => postNotifyUserOfErrorX(
context: context,
errorSituation: AppLocalizations.of(context)!.errorLogin,

View File

@@ -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();
}
}
}

View File

@@ -1,12 +0,0 @@
class AuthenticationService {
Future<bool> verifyTwoFactorCode(String code) async {
await Future.delayed(const Duration(seconds: 2));
if (code == '000000') {
return true;
} else {
throw Exception('Wrong Code'); //TODO Localize
}
}
}

View File

@@ -8,7 +8,6 @@ import Foundation
import amplitude_flutter
import file_selector_macos
import flutter_timezone
import path_provider_foundation
import share_plus
import shared_preferences_foundation
import sqflite_darwin
@@ -18,7 +17,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AmplitudeFlutterPlugin.register(with: registry.registrar(forPlugin: "AmplitudeFlutterPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))