Added account permissions and ui for recipient

This commit is contained in:
Arseni
2025-11-26 13:03:52 +03:00
parent fcb5ab4f2c
commit 357af99564
23 changed files with 507 additions and 70 deletions

View File

@@ -1,15 +1,13 @@
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:pshared/models/auth/pending_login.dart';
import 'package:pshared/provider/account.dart';
import 'package:pshared/service/account.dart';
import 'package:pweb/services/auth.dart';
class TwoFactorProvider extends ChangeNotifier {
static final _logger = Logger('provider.two_factor');
final AccountProvider _accountProvider;
final AuthenticationService _authService;
TwoFactorProvider({required AccountProvider accountProvider}) : _accountProvider = accountProvider;
TwoFactorProvider({AuthenticationService? authService}) : _authService = authService ?? AuthenticationService();
bool _isSubmitting = false;
bool _hasError = false;
@@ -20,7 +18,6 @@ class TwoFactorProvider extends ChangeNotifier {
bool get hasError => _hasError;
bool get verificationSuccess => _verificationSuccess;
String? get errorMessage => _errorMessage;
PendingLogin? get pendingLogin => _accountProvider.pendingLogin;
Future<void> submitCode(String code) async {
@@ -31,16 +28,8 @@ class TwoFactorProvider extends ChangeNotifier {
notifyListeners();
try {
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;
final isValid = await _authService.verifyTwoFactorCode(code);
_verificationSuccess = isValid;
} catch (e) {
_hasError = true;
_errorMessage = e.toString();
@@ -52,18 +41,9 @@ class TwoFactorProvider extends ChangeNotifier {
}
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();
}
_logger.fine('Resending mock two-factor code');
_hasError = false;
_errorMessage = null;
notifyListeners();
}
}