コード例 #1
0
        private async Task SignIn(string email = "", string password = "")
        {
            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
            {
                SignInError.Text      = "Please enter an email address and password.";
                SignInError.IsVisible = true;
                return;
            }
            else if (!RegexHelper.IsValidEmail(email))
            {
                SignInError.Text      = "Please enter a valid email address.";
                SignInError.IsVisible = true;
                return;
            }
            SignInError.IsVisible = false;
            Loading.IsVisible     = true;
            SignInContext context = await _cognitoHelper.SignIn(email.ToLower(), password);

            switch (context.Result)
            {
            case CognitoResult.NotConfirmed:
                SignInError.Text      = "You have not confirmed your email address. Please check your email and click on the provided link to confirm your email address and then try again.";
                SignInError.IsVisible = true;
                Loading.IsVisible     = false;
                break;

            case CognitoResult.UserNotFound:
                SignInError.Text      = "No user with that email address was found.";
                SignInError.IsVisible = true;
                Loading.IsVisible     = false;
                break;

            case CognitoResult.Error:
                SignInError.Text      = "Something went wrong. Please try again later.";
                SignInError.IsVisible = true;
                Loading.IsVisible     = false;
                break;

            case CognitoResult.Ok:
                await Application.Current.SavePropertiesAsync();

                var cred = AmazonUtils.Credentials;
                cred.AddLogin(Constants.PROVIDER_NAME, context.IdToken);
                await GetUser(context.User.Username, context.User.UserID);

                Loading.IsVisible            = false;
                Application.Current.MainPage = new NavigationPage(new MyHome());

                break;

            case CognitoResult.NotAuthorized:
                SignInError.Text      = "Incorrect password.";
                SignInError.IsVisible = true;
                Loading.IsVisible     = false;
                break;

            default:
                SignInError.Text      = "Something went wrong. Please try again later.";
                SignInError.IsVisible = true;
                Loading.IsVisible     = false;
                break;
            }
        }