Frontend first draft
This commit is contained in:
38
frontend/pweb/lib/providers/two_factor.dart
Normal file
38
frontend/pweb/lib/providers/two_factor.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/services/auth.dart';
|
||||
|
||||
|
||||
class TwoFactorProvider extends ChangeNotifier {
|
||||
final AuthenticationService _authService;
|
||||
|
||||
TwoFactorProvider(this._authService);
|
||||
|
||||
bool _isSubmitting = false;
|
||||
bool _hasError = false;
|
||||
bool _verificationSuccess = false;
|
||||
|
||||
bool get isSubmitting => _isSubmitting;
|
||||
bool get hasError => _hasError;
|
||||
bool get verificationSuccess => _verificationSuccess;
|
||||
|
||||
|
||||
Future<void> submitCode(String code) async {
|
||||
_isSubmitting = true;
|
||||
_hasError = false;
|
||||
_verificationSuccess = false;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final success = await _authService.verifyTwoFactorCode(code);
|
||||
if (success) {
|
||||
_verificationSuccess = true;
|
||||
}
|
||||
} catch (e) {
|
||||
_hasError = true;
|
||||
} finally {
|
||||
_isSubmitting = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user