Merge pull request 'Password field checks for match with old password from db and check so that new password feild matches with the confirm password field' (#143) from SEND013 into main
Some checks failed
ci/woodpecker/push/billing_fees Pipeline failed
ci/woodpecker/push/frontend Pipeline is pending
ci/woodpecker/push/chain_gateway Pipeline is pending
ci/woodpecker/push/db Pipeline is pending
ci/woodpecker/push/fx_ingestor Pipeline is pending
ci/woodpecker/push/fx_oracle Pipeline is pending
ci/woodpecker/push/ledger Pipeline is pending
ci/woodpecker/push/mntx_gateway Pipeline is pending
ci/woodpecker/push/nats Pipeline is pending
ci/woodpecker/push/notification Pipeline is pending
ci/woodpecker/push/payments_orchestrator Pipeline is pending
ci/woodpecker/push/bff Pipeline failed
Some checks failed
ci/woodpecker/push/billing_fees Pipeline failed
ci/woodpecker/push/frontend Pipeline is pending
ci/woodpecker/push/chain_gateway Pipeline is pending
ci/woodpecker/push/db Pipeline is pending
ci/woodpecker/push/fx_ingestor Pipeline is pending
ci/woodpecker/push/fx_oracle Pipeline is pending
ci/woodpecker/push/ledger Pipeline is pending
ci/woodpecker/push/mntx_gateway Pipeline is pending
ci/woodpecker/push/nats Pipeline is pending
ci/woodpecker/push/notification Pipeline is pending
ci/woodpecker/push/payments_orchestrator Pipeline is pending
ci/woodpecker/push/bff Pipeline failed
Reviewed-on: #143
This commit was merged in pull request #143.
This commit is contained in:
@@ -3,6 +3,9 @@ import 'package:flutter/material.dart';
|
||||
import 'package:pshared/provider/account.dart';
|
||||
|
||||
import 'package:pweb/models/edit_state.dart';
|
||||
import 'package:pshared/api/responses/error/server.dart';
|
||||
import 'package:pweb/models/password_field_type.dart';
|
||||
import 'package:pweb/models/visibility.dart';
|
||||
|
||||
|
||||
class PasswordFormProvider extends ChangeNotifier {
|
||||
@@ -11,6 +14,11 @@ class PasswordFormProvider extends ChangeNotifier {
|
||||
final newPasswordController = TextEditingController();
|
||||
final confirmPasswordController = TextEditingController();
|
||||
|
||||
final Map<PasswordFieldType, VisibilityState> _visibility = {
|
||||
PasswordFieldType.old: VisibilityState.hidden,
|
||||
PasswordFieldType.newPassword: VisibilityState.hidden,
|
||||
PasswordFieldType.confirmPassword: VisibilityState.hidden,
|
||||
};
|
||||
EditState _state = EditState.view;
|
||||
String _errorText = '';
|
||||
bool _disposed = false;
|
||||
@@ -19,6 +27,8 @@ class PasswordFormProvider extends ChangeNotifier {
|
||||
bool get isSaving => _state == EditState.saving;
|
||||
String get errorText => _errorText;
|
||||
EditState get state => _state;
|
||||
bool isPasswordVisible(PasswordFieldType type) =>
|
||||
_visibility[type] == VisibilityState.visible;
|
||||
|
||||
void toggleExpanded() {
|
||||
if (_state == EditState.saving) return;
|
||||
@@ -26,12 +36,21 @@ class PasswordFormProvider extends ChangeNotifier {
|
||||
_setError('');
|
||||
}
|
||||
|
||||
Future<void> submit({
|
||||
void togglePasswordVisibility(PasswordFieldType type) {
|
||||
final current = _visibility[type];
|
||||
if (current == null) return;
|
||||
_visibility[type] = current == VisibilityState.hidden
|
||||
? VisibilityState.visible
|
||||
: VisibilityState.hidden;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<bool> submit({
|
||||
required AccountProvider accountProvider,
|
||||
required String errorText,
|
||||
}) async {
|
||||
final currentForm = formKey.currentState;
|
||||
if (currentForm == null || !currentForm.validate()) return;
|
||||
if (currentForm == null || !currentForm.validate()) return false;
|
||||
|
||||
_setState(EditState.saving);
|
||||
_setError('');
|
||||
@@ -45,14 +64,22 @@ class PasswordFormProvider extends ChangeNotifier {
|
||||
oldPasswordController.clear();
|
||||
newPasswordController.clear();
|
||||
confirmPasswordController.clear();
|
||||
_setState(EditState.view);
|
||||
return true;
|
||||
} catch (e) {
|
||||
_setError(errorText);
|
||||
rethrow;
|
||||
} finally {
|
||||
_setError(_errorMessageForException(e, errorText));
|
||||
_setState(EditState.edit);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
String _errorMessageForException(Object exception, String fallback) {
|
||||
if (exception is ErrorResponse && exception.details.isNotEmpty) {
|
||||
return exception.details;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
void _setState(EditState value) {
|
||||
if (_state == value || _disposed) return;
|
||||
_state = value;
|
||||
|
||||
Reference in New Issue
Block a user