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:
1
frontend/pweb/lib/models/password_field_type.dart
Normal file
1
frontend/pweb/lib/models/password_field_type.dart
Normal file
@@ -0,0 +1 @@
|
||||
enum PasswordFieldType { old, newPassword, confirmPassword }
|
||||
1
frontend/pweb/lib/models/visibility.dart
Normal file
1
frontend/pweb/lib/models/visibility.dart
Normal file
@@ -0,0 +1 @@
|
||||
enum VisibilityState { hidden, visible }
|
||||
@@ -4,6 +4,7 @@ import 'package:pshared/provider/account.dart';
|
||||
import 'package:pshared/widgets/password/fields.dart';
|
||||
import 'package:pshared/utils/snackbar.dart';
|
||||
|
||||
import 'package:pweb/models/password_field_type.dart';
|
||||
import 'package:pweb/providers/password_form.dart';
|
||||
import 'package:pweb/pages/settings/profile/account/password/form/error_text.dart';
|
||||
import 'package:pweb/pages/settings/profile/account/password/form/submit_button.dart';
|
||||
@@ -65,6 +66,18 @@ class PasswordForm extends StatelessWidget {
|
||||
fieldWidth: _fieldWidth,
|
||||
gapSmall: _gapSmall,
|
||||
isEnabled: !isFormBusy,
|
||||
showOldPassword:
|
||||
formProvider.isPasswordVisible(PasswordFieldType.old),
|
||||
showNewPassword:
|
||||
formProvider.isPasswordVisible(PasswordFieldType.newPassword),
|
||||
showConfirmPassword: formProvider
|
||||
.isPasswordVisible(PasswordFieldType.confirmPassword),
|
||||
onToggleOldPassword: () =>
|
||||
formProvider.togglePasswordVisibility(PasswordFieldType.old),
|
||||
onToggleNewPassword: () => formProvider
|
||||
.togglePasswordVisibility(PasswordFieldType.newPassword),
|
||||
onToggleConfirmPassword: () => formProvider
|
||||
.togglePasswordVisibility(PasswordFieldType.confirmPassword),
|
||||
),
|
||||
const SizedBox(height: _gapMedium),
|
||||
PasswordSubmitButton(
|
||||
@@ -72,10 +85,11 @@ class PasswordForm extends StatelessWidget {
|
||||
label: savePassword,
|
||||
onSubmit: () async {
|
||||
try {
|
||||
await formProvider.submit(
|
||||
final success = await formProvider.submit(
|
||||
accountProvider: accountProvider,
|
||||
errorText: errorText,
|
||||
);
|
||||
if (!success) return;
|
||||
if (!context.mounted) return;
|
||||
notifyUser(context, successText);
|
||||
} catch (e) {
|
||||
|
||||
@@ -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