Skip to content

Commit

Permalink
feat(amplify_authenticator): configured signup fields and password va…
Browse files Browse the repository at this point in the history
…lidation (aws-amplify#899)
  • Loading branch information
haverchuck authored and Dillon Nys committed Nov 9, 2021
1 parent 180d115 commit 257ab56
Show file tree
Hide file tree
Showing 38 changed files with 1,223 additions and 167 deletions.
148 changes: 79 additions & 69 deletions packages/amplify_authenticator/lib/amplify_authenticator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

library amplify_authenticator;

import 'package:amplify_authenticator/src/state/inherited_config.dart';
import 'package:amplify_authenticator/src/widgets/default_forms/default_confirm_signin_mfa.dart';
import 'package:amplify_authenticator/src/widgets/default_forms/default_confirm_signin_new_password.dart';
import 'package:amplify_authenticator/src/widgets/default_forms/default_confirm_signup.dart';
Expand Down Expand Up @@ -239,6 +240,9 @@ class _AuthenticatorState extends State<Authenticator> {
cognitoPlugin ?? missingValues.add('auth.plugins.Auth.Default');
cognitoPlugin?.signupAttributes?.length ??
missingValues.add('auth.plugins.Auth.Default.signUpAttributes');
cognitoPlugin?.passwordProtectionSettings ??
missingValues
.add('auth.plugins.Auth.Default.passwordProtectionSettings');
return missingValues;
}

Expand Down Expand Up @@ -268,77 +272,83 @@ class _AuthenticatorState extends State<Authenticator> {
return InheritedAuthBloc(
key: const Key(keyInheritedAuthBloc),
authBloc: _stateMachineBloc,
child: InheritedAuthViewModel(
key: const Key(keyInheritedAuthViewModel),
signInViewModel: SignInViewModel(_stateMachineBloc),
signUpViewModel: SignUpViewModel(_stateMachineBloc),
confirmSignUpViewModel: ConfirmSignUpViewModel(_stateMachineBloc),
confirmSignInViewModel: ConfirmSignInViewModel(_stateMachineBloc),
child: InheritedStrings(
resolver: resolver,
child: InheritedForms(
confirmSignInNewPasswordForm: confirmSignInNewPasswordForm,
resetPasswordForm: resetPasswordForm,
sendCodeForm: sendCodeForm,
signInForm: signInForm,
signUpForm: signUpForm,
confirmSignUpForm: confirmSignUpForm,
confirmSignInMFAForm: confirmSignInMFAForm,
child: Scaffold(
body: StreamBuilder(
stream: _stateMachineBloc.stream,
builder: (context, snapshot) {
final state = (snapshot.data != null &&
_configInitialized &&
_config?.auth != null)
? snapshot.data
: const AuthLoading();
late Widget screen;
if (state is AuthLoading) {
screen = LoadingScreen();
} else if (state is Authenticated) {
return widget.child;
} else if (state is AuthFlow &&
state.screen == AuthScreen.signin) {
screen = SignInScreen();
} else if (state is AuthFlow &&
state.screen == AuthScreen.signup) {
screen = SignUpScreen();
} else if (state is AuthFlow &&
state.screen == AuthScreen.confirmSignUp) {
screen = ConfirmSignUpScreen();
} else if (state is AuthFlow &&
state.screen == AuthScreen.confirmSignInMfa) {
screen = const ConfirmSignInMFAScreen();
} else if (state is AuthFlow &&
state.screen == AuthScreen.confirmSignInNewPassword) {
screen = ConfirmSignInNewPasswordScreen();
} else if (state is AuthFlow &&
state.screen == AuthScreen.sendCode) {
screen = const SendCodeScreen();
} else if (state is AuthFlow &&
state.screen == AuthScreen.resetPassword) {
screen = const ResetPasswordScreen();
} else {
screen = SignInScreen();
}
child: InheritedConfig(
config: _config,
child: InheritedAuthViewModel(
key: const Key(keyInheritedAuthViewModel),
signInViewModel: SignInViewModel(_stateMachineBloc),
signUpViewModel: SignUpViewModel(_stateMachineBloc),
confirmSignUpViewModel:
ConfirmSignUpViewModel(_stateMachineBloc),
confirmSignInViewModel:
ConfirmSignInViewModel(_stateMachineBloc),
child: InheritedStrings(
resolver: resolver,
child: InheritedForms(
confirmSignInNewPasswordForm:
confirmSignInNewPasswordForm,
resetPasswordForm: resetPasswordForm,
sendCodeForm: sendCodeForm,
signInForm: signInForm,
signUpForm: signUpForm,
confirmSignUpForm: confirmSignUpForm,
confirmSignInMFAForm: confirmSignInMFAForm,
child: Scaffold(
body: StreamBuilder(
stream: _stateMachineBloc.stream,
builder: (context, snapshot) {
final state = (snapshot.data != null &&
_configInitialized &&
_config?.auth != null)
? snapshot.data
: const AuthLoading();
late Widget screen;
if (state is AuthLoading) {
screen = LoadingScreen();
} else if (state is Authenticated) {
return widget.child;
} else if (state is AuthFlow &&
state.screen == AuthScreen.signin) {
screen = SignInScreen();
} else if (state is AuthFlow &&
state.screen == AuthScreen.signup) {
screen = SignUpScreen();
} else if (state is AuthFlow &&
state.screen == AuthScreen.confirmSignUp) {
screen = ConfirmSignUpScreen();
} else if (state is AuthFlow &&
state.screen == AuthScreen.confirmSignInMfa) {
screen = const ConfirmSignInMFAScreen();
} else if (state is AuthFlow &&
state.screen ==
AuthScreen.confirmSignInNewPassword) {
screen = ConfirmSignInNewPasswordScreen();
} else if (state is AuthFlow &&
state.screen == AuthScreen.sendCode) {
screen = const SendCodeScreen();
} else if (state is AuthFlow &&
state.screen == AuthScreen.resetPassword) {
screen = const ResetPasswordScreen();
} else {
screen = SignInScreen();
}

return Container(
padding: const EdgeInsets.symmetric(vertical: 40),
child: Center(
child: SingleChildScrollView(
child: Column(
children: [
const AuthExceptionsWidget(),
screen,
],
return Container(
padding: const EdgeInsets.symmetric(vertical: 40),
child: Center(
child: SingleChildScrollView(
child: Column(
children: [
const AuthExceptionsWidget(),
screen,
],
),
),
),
),
),
);
},
)),
))));
);
},
)),
)))));
}

@override
Expand Down
15 changes: 15 additions & 0 deletions packages/amplify_authenticator/lib/src/blocs/auth/auth_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import 'dart:async';

import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
Expand Down
15 changes: 15 additions & 0 deletions packages/amplify_authenticator/lib/src/blocs/auth/auth_data.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// ignore: public_member_api_docs
enum AuthScreen {
signup,
Expand Down
15 changes: 15 additions & 0 deletions packages/amplify_authenticator/lib/src/blocs/auth/auth_event.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

part of 'auth_bloc.dart';

abstract class AuthEvent {
Expand Down
15 changes: 15 additions & 0 deletions packages/amplify_authenticator/lib/src/blocs/auth/auth_state.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

part of 'auth_bloc.dart';

abstract class AuthState {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import 'package:flutter/material.dart';

abstract class AuthenticatorConstants {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import 'package:flutter/material.dart';

abstract class ThemeConstants {}
Expand Down
15 changes: 15 additions & 0 deletions packages/amplify_authenticator/lib/src/enums/alias.dart
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

enum Alias { username, email, phone_number, email_phone_number }
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

enum ConfirmSignInType {
code,
password,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import 'package:collection/collection.dart';

enum ConfirmSignUpType { username, password, email, phone_number, code }
Expand Down
15 changes: 15 additions & 0 deletions packages/amplify_authenticator/lib/src/enums/signin_types.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import 'package:collection/collection.dart';

enum SignInType {
Expand Down
15 changes: 15 additions & 0 deletions packages/amplify_authenticator/lib/src/enums/signup_types.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import 'package:collection/collection.dart';

enum SignUpType {
Expand Down
15 changes: 15 additions & 0 deletions packages/amplify_authenticator/lib/src/keys.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Sign in form fields keys

const String keyUsernameSignInFormField = 'usernameSignInFormField';
Expand Down
Loading

0 comments on commit 257ab56

Please sign in to comment.