-
Notifications
You must be signed in to change notification settings - Fork 259
chore(core): updated asyncConfig to use AmplifyOutputs #4995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 20 commits
8fb9e66
b9b3515
76ae8e0
e7d77ea
4e7f792
f6cc0a4
bbf6e72
aa7140a
1113935
7bb4159
9e57209
272f211
cacc5ca
e2b068a
dcf5056
a391ecc
20ca76c
b565963
5ff3478
6e71be3
a66e07f
0599648
0b545ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import 'package:amplify_authenticator/amplify_authenticator.dart'; | ||
import 'package:amplify_core/amplify_core.dart'; | ||
import 'package:amplify_flutter/amplify_flutter.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
|
@@ -73,11 +74,10 @@ extension PasswordPolicyCharactersX on PasswordPolicyCharacters { | |
} | ||
|
||
FormFieldValidator<String> Function(BuildContext) validateNewPassword({ | ||
required AmplifyConfig? amplifyConfig, | ||
required AmplifyOutputs? amplifyConfig, | ||
tyllark marked this conversation as resolved.
Show resolved
Hide resolved
|
||
required InputResolver inputResolver, | ||
}) { | ||
final passwordProtectionSettings = amplifyConfig | ||
?.auth?.awsPlugin?.auth?.default$?.passwordProtectionSettings; | ||
final passwordPolicies = amplifyConfig?.auth?.passwordPolicy; | ||
return (BuildContext context) => (String? password) { | ||
if (password == null || password.isEmpty) { | ||
return inputResolver.resolve( | ||
|
@@ -86,23 +86,15 @@ FormFieldValidator<String> Function(BuildContext) validateNewPassword({ | |
); | ||
} | ||
password = password.trim(); | ||
if (passwordProtectionSettings == null) { | ||
if (passwordPolicies == null) { | ||
return null; | ||
} | ||
|
||
final unmetReqs = <PasswordPolicyCharacters>[]; | ||
|
||
final minLength = passwordProtectionSettings.passwordPolicyMinLength; | ||
final minLength = passwordPolicies.minLength; | ||
final meetsMinLengthRequirement = | ||
minLength == null || password.length >= minLength; | ||
|
||
final passwordPolicies = | ||
passwordProtectionSettings.passwordPolicyCharacters; | ||
for (final policy in passwordPolicies) { | ||
if (!policy.meetsRequirement(password)) { | ||
unmetReqs.add(policy); | ||
} | ||
} | ||
final unmetReqs = _getUnmetPasswordPolicies(password, passwordPolicies); | ||
|
||
final error = inputResolver.resolve( | ||
context, | ||
|
@@ -118,6 +110,26 @@ FormFieldValidator<String> Function(BuildContext) validateNewPassword({ | |
}; | ||
} | ||
|
||
List<PasswordPolicyCharacters> _getUnmetPasswordPolicies( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Remove use of
|
||
String password, | ||
PasswordPolicy? policy, | ||
) { | ||
final unmetReqs = <PasswordPolicyCharacters>[]; | ||
if ((policy?.requireLowercase ?? false) && !password.contains(_lowercase)) { | ||
unmetReqs.add(PasswordPolicyCharacters.requiresLowercase); | ||
} | ||
if ((policy?.requireUppercase ?? false) && !password.contains(_uppercase)) { | ||
unmetReqs.add(PasswordPolicyCharacters.requiresUppercase); | ||
} | ||
if ((policy?.requireNumbers ?? false) && !password.contains(_numeric)) { | ||
unmetReqs.add(PasswordPolicyCharacters.requiresNumbers); | ||
} | ||
if ((policy?.requireSymbols ?? false) && !password.contains(_symbols)) { | ||
unmetReqs.add(PasswordPolicyCharacters.requiresSymbols); | ||
} | ||
return unmetReqs; | ||
} | ||
|
||
FormFieldValidator<String> validatePasswordConfirmation( | ||
String Function() getPassword, { | ||
required BuildContext context, | ||
|
Uh oh!
There was an error while loading. Please reload this page.