Пример #1
0
        /// <summary>
        /// Implements a simple navigation and message stateless state machine. The prior parameter is the ViewModel of the
        /// page that caused the transition. It may be null, so test before using. This is included in case there may be information
        /// relevant to actions or messages. This method may not be called on the UI thread.
        /// </summary>
        /// <param name="ce">The event to respond to</param>
        /// <param name="prior">The ViewModel of the screen that caused the transition. May be null.</param>
        /// <returns></returns>
        public virtual async Task OnResult(CognitoEvent ce, CognitoFormsViewModel prior)
        {
            PageModelPair pair = null;

            switch (ce)
            {
            case CognitoEvent.DoSignup:
                pair = CreatePageModelPair(PageId.SignUp, AuthApi, SessionStore);
                pair.Page.BindingContext = pair.ViewModel;

                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PushAsync(pair.Page, true);
                });
                break;

            case CognitoEvent.Authenticated:
                await Authenticated?.Invoke();

                break;

            case CognitoEvent.BadPassword:
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Page.DisplayAlert(Strings.SignInTitle, Strings.BadPassMessage, Strings.OkButton);
                });
                break;

            case CognitoEvent.UserNotFound:
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Page.DisplayAlert(Strings.UserNotFoundTitle, Strings.UserNotFoundMessage, Strings.OkButton);
                });
                break;

            case CognitoEvent.PasswordChangedRequired:
                pair = CreatePageModelPair(PageId.UpdatePassword, AuthApi, SessionStore);
                pair.Page.BindingContext = pair.ViewModel;

                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PushAsync(pair.Page, true);
                });
                break;

            case CognitoEvent.RegistrationComplete:
                Device.BeginInvokeOnMainThread(async() =>
                {
                    pair = CreatePageModelPair(PageId.ValidateCode, AuthApi, SessionStore);
                    pair.Page.BindingContext = pair.ViewModel;

                    await Navigation.PushAsync(pair.Page, true);
                });
                break;

            case CognitoEvent.AccountVerified:
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopToRootAsync();
                });
                break;

            case CognitoEvent.PasswordUpdated:
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopAsync(true);
                });
                break;

            case CognitoEvent.BadCode:
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Page.DisplayAlert(Strings.BadCodeTitle, Strings.BadCodeMessage, Strings.OkButton);
                });
                break;

            case CognitoEvent.PasswordUpdateFailed:
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Page.DisplayAlert(Strings.PassUpdateFailedTitle, Strings.PassUpdateFailedMessage, Strings.OkButton);
                });
                break;

            case CognitoEvent.UserNameAlreadyUsed:
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Page.DisplayAlert(Strings.SignupFailedTitle, Strings.UserNameUsed, Strings.OkButton);
                });
                break;

            case CognitoEvent.PasswordRequirementsFailed:
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Page.DisplayAlert(Strings.SignupFailedTitle, Strings.MinimalPasswordRequirements, Strings.OkButton);
                });
                break;

            case CognitoEvent.AccountConfirmationRequired:
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Page.DisplayAlert(Strings.SignInTitle, Strings.RequiresValidation, Strings.OkButton);

                    pair = CreatePageModelPair(PageId.ValidateCode, AuthApi, SessionStore);
                    pair.Page.BindingContext = pair.ViewModel;

                    await Navigation.PushAsync(pair.Page, true);
                });
                break;

            default:
                break;
            }
        }
Пример #2
0
 public PageModelPair(ContentPage page, CognitoFormsViewModel viewModel)
 {
     Page      = page;
     ViewModel = viewModel;
 }