Esempio n. 1
0
        public void onEvent(MegaSDK api, MEvent ev)
        {
            if (ev.getType() != MEventType.EVENT_ACCOUNT_BLOCKED)
            {
                return;
            }

            AccountService.IsAccountBlocked = true;

            LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Blocked account: " + ev.getText());

            // A blocked account automatically triggers a logout
            AppService.LogoutActions();

            // Show the login page with the corresponding navigation parameter
            UiService.OnUiThread(() =>
            {
                NavigateService.Instance.Navigate(typeof(LoginAndCreateAccountPage), true,
                                                  NavigationObject.Create(typeof(MainViewModel), NavigationActionType.API_EBLOCKED,
                                                                          new Dictionary <NavigationParamType, object>
                {
                    { NavigationParamType.Number, ev.getNumber() },
                    { NavigationParamType.Text, ev.getText() }
                }));
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Enable the Multi-Factor Authentication
        /// </summary>
        private async Task <bool> EnableMultiFactorAuthAsync(string code)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return(false);
            }

            var enableMultiFactorAuth = new MultiFactorAuthEnableRequestListenerAsync();
            var result = await enableMultiFactorAuth.ExecuteAsync(() =>
                                                                  SdkService.MegaSdk.multiFactorAuthEnable(code, enableMultiFactorAuth));

            if (!result)
            {
                DialogService.SetMultiFactorAuthCodeInputDialogWarningMessage();
                return(result);
            }

            DialogService.ShowMultiFactorAuthEnabledDialog();

            NavigateService.Instance.Navigate(typeof(SettingsPage), false,
                                              NavigationObject.Create(typeof(MultiFactorAuthAppSetupViewModel),
                                                                      NavigationActionType.SecuritySettings));

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Display an alert dialog to notify that the user has exceeded or will exceed during
        /// the current operation (pre alert) the storage limit of the account.
        /// </summary>
        /// <param name="isPreAlert">Parameter to indicate if is a pre alert situation.</param>
        public static async void ShowStorageOverquotaAlert(bool isPreAlert)
        {
            if (StorageOverquotaAlertDisplayed)
            {
                return;
            }
            StorageOverquotaAlertDisplayed = true;

            var title = isPreAlert ? ResourceService.AppMessages.GetString("AM_StorageOverquotaPreAlert_Title") :
                        ResourceService.AppMessages.GetString("AM_StorageOverquotaAlert_Title");
            var message = isPreAlert ? ResourceService.AppMessages.GetString("AM_StorageOverquotaPreAlert") :
                          ResourceService.AppMessages.GetString("AM_StorageOverquotaAlert");

            var result = await ShowOkCancelAsync(title, message, TwoButtonsDialogType.YesNo);

            StorageOverquotaAlertDisplayed = false;

            if (!result)
            {
                return;
            }

            UiService.OnUiThread(() =>
            {
                NavigateService.Instance.Navigate(typeof(MyAccountPage), false,
                                                  NavigationObject.Create(typeof(MainViewModel), NavigationActionType.Upgrade));
            });
        }
Esempio n. 4
0
        private void OnImportFinished(object sender, EventArgs e)
        {
            ResetImport();

            // Navigate to the Cloud Drive page
            NavigateService.Instance.Navigate(typeof(CloudDrivePage), false,
                                              NavigationObject.Create(this.GetType()));
        }
Esempio n. 5
0
 private void RubbishBin()
 {
     OnUiThread(() =>
     {
         NavigateService.Instance.Navigate(typeof(CloudDrivePage), false,
                                           NavigationObject.Create(typeof(GeneralViewModel), NavigationActionType.RubbishBin));
     });
 }
Esempio n. 6
0
 private void OkButton()
 {
     OnUiThread(() =>
     {
         NavigateService.Instance.Navigate(typeof(MainPage), true,
                                           NavigationObject.Create(typeof(ConfirmChangeEmailViewModel), NavigationActionType.Default));
     });
 }
Esempio n. 7
0
        public virtual void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            switch (e.getErrorCode())
            {
            case MErrorType.API_EINCOMPLETE:
                if (request.getType() == MRequestType.TYPE_LOGOUT &&
                    request.getParamType() == (int)MErrorType.API_ESSL)
                {
                    if (SSLCertificateAlertDisplayed)
                    {
                        break;
                    }

                    SSLCertificateAlertDisplayed = true;
                    UiService.OnUiThread(async() =>
                    {
                        var result = await DialogService.ShowSSLCertificateAlert();
                        SSLCertificateAlertDisplayed = false;
                        switch (result)
                        {
                        // "Retry" button
                        case ContentDialogResult.Primary:
                            api.reconnect();
                            break;

                        // "Open browser" button
                        case ContentDialogResult.Secondary:
                            await Launcher.LaunchUriAsync(
                                new Uri(ResourceService.AppResources.GetString("AR_MegaUrl"),
                                        UriKind.RelativeOrAbsolute));
                            break;

                        // "Ignore" or "Close" button
                        case ContentDialogResult.None:
                        default:
                            api.setPublicKeyPinning(false);
                            api.reconnect();
                            break;
                        }
                    });
                }
                break;

            case MErrorType.API_ESID:
                AppService.LogoutActions();

                // Show the login page with the corresponding navigation parameter
                UiService.OnUiThread(() =>
                {
                    NavigateService.Instance.Navigate(typeof(LoginAndCreateAccountPage), true,
                                                      NavigationObject.Create(typeof(MainViewModel), NavigationActionType.API_ESID));
                });
                break;
            }
        }
Esempio n. 8
0
        private async void OpenLink()
        {
            if (!await IsUserOnlineAsync())
            {
                return;
            }

            var link = await DialogService.ShowInputDialogAsync(OpenLinkText,
                                                                ResourceService.UiResources.GetString("UI_TypeOrPasteLink"));

            if (string.IsNullOrEmpty(link) || string.IsNullOrWhiteSpace(link))
            {
                return;
            }

            LinkInformationService.ActiveLink = UriService.ReformatUri(link);

            if (LinkInformationService.ActiveLink.Contains(
                    ResourceService.AppResources.GetString("AR_FileLinkHeader")))
            {
                LinkInformationService.UriLink = UriLinkType.File;

                // Navigate to the file link page
                OnUiThread(() =>
                {
                    NavigateService.Instance.Navigate(typeof(FileLinkPage), false,
                                                      NavigationObject.Create(this.GetType()));
                });
            }
            else if (LinkInformationService.ActiveLink.Contains(
                         ResourceService.AppResources.GetString("AR_FolderLinkHeader")))
            {
                LinkInformationService.UriLink = UriLinkType.Folder;

                // Navigate to the folder link page
                OnUiThread(() =>
                {
                    NavigateService.Instance.Navigate(typeof(FolderLinkPage), false,
                                                      NavigationObject.Create(this.GetType()));
                });
            }
            else
            {
                OnUiThread(async() =>
                {
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_OpenLinkFailed_Title"),
                        ResourceService.AppMessages.GetString("AM_OpenLinkFailed"));
                });
            }
        }
Esempio n. 9
0
        private void Preview()
        {
            this.Parent.FocusedNode = this;

            // Navigate to the preview page
            OnUiThread(() =>
            {
                var parameters = new Dictionary <NavigationParamType, object>();
                parameters.Add(NavigationParamType.Data, this.Parent);

                NavigateService.Instance.Navigate(typeof(PreviewImagePage), true,
                                                  NavigationObject.Create(this.GetType(), NavigationActionType.Default, parameters));
            });
        }
Esempio n. 10
0
        /// <summary>
        /// Confirm the email change
        /// </summary>
        private async void ConfirmEmail()
        {
            if (string.IsNullOrWhiteSpace(this.Password))
            {
                OnPasswordError();
                return;
            }

            var changeEmail = new ConfirmChangeEmailRequestListenerAsync();
            var result      = await changeEmail.ExecuteAsync(() =>
                                                             this.MegaSdk.confirmChangeEmail(this.VerifyEmailLink, this.Password, changeEmail));

            switch (result)
            {
            case ConfirmChangeEmailResult.Success:
                AccountService.UserData.UserEmail = this.Email;
                OnEmailChanged();
                return;

            case ConfirmChangeEmailResult.UserNotLoggedIn:
                await DialogService.ShowAlertAsync(ResourceService.UiResources.GetString("UI_ChangeEmail"),
                                                   ResourceService.AppMessages.GetString("AM_UserNotOnline"));

                break;

            case ConfirmChangeEmailResult.WrongPassword:
                OnPasswordError();
                return;

            case ConfirmChangeEmailResult.WrongAccount:
                await DialogService.ShowAlertAsync(ResourceService.UiResources.GetString("UI_ChangeEmail"),
                                                   ResourceService.AppMessages.GetString("AM_WrongAccount"));

                break;

            case ConfirmChangeEmailResult.Unknown:
            default:
                await DialogService.ShowAlertAsync(ResourceService.UiResources.GetString("UI_ChangeEmail"),
                                                   ResourceService.AppMessages.GetString("AM_ChangeEmailGenericError"));

                break;
            }

            OnUiThread(() =>
            {
                NavigateService.Instance.Navigate(typeof(MainPage), true,
                                                  NavigationObject.Create(typeof(ConfirmChangeEmailViewModel), NavigationActionType.Default));
            });
        }
Esempio n. 11
0
        /// <summary>
        /// Process the verify email link
        /// </summary>
        public async void ProcessVerifyEmailLink()
        {
            if (string.IsNullOrWhiteSpace(LinkInformationService.ActiveLink) ||
                !LinkInformationService.ActiveLink.Contains("#verify"))
            {
                return;
            }

            this.VerifyEmailLink = LinkInformationService.ActiveLink;
            LinkInformationService.Reset();

            var verifyEmail = new QueryChangeEmailLinkRequestListenerAsync();
            var result      = await verifyEmail.ExecuteAsync(() =>
                                                             this.MegaSdk.queryChangeEmailLink(this.VerifyEmailLink, verifyEmail));

            switch (result)
            {
            case QueryChangeEmailLinkResult.Success:
                this.Email = verifyEmail.Email;
                return;

            case QueryChangeEmailLinkResult.InvalidLink:
                await DialogService.ShowAlertAsync(ResourceService.UiResources.GetString("UI_ChangeEmail"),
                                                   ResourceService.AppMessages.GetString("AM_ChangeEmailInvalidLink"));

                break;

            case QueryChangeEmailLinkResult.UserNotLoggedIn:
                await DialogService.ShowAlertAsync(ResourceService.UiResources.GetString("UI_ChangeEmail"),
                                                   ResourceService.AppMessages.GetString("AM_UserNotOnline"));

                break;

            case QueryChangeEmailLinkResult.Unknown:
            default:
                await DialogService.ShowAlertAsync(ResourceService.UiResources.GetString("UI_ChangeEmail"),
                                                   ResourceService.AppMessages.GetString("AM_ChangeEmailGenericError"));

                break;
            }

            OnUiThread(() =>
            {
                NavigateService.Instance.Navigate(typeof(MainPage), true,
                                                  NavigationObject.Create(typeof(ConfirmChangeEmailViewModel), NavigationActionType.Default));
            });
        }
Esempio n. 12
0
        public void onAccountUpdate(MegaSDK api)
        {
            UiService.OnUiThread(async() =>
            {
                var result = await DialogService.ShowOkCancelAsync(
                    ResourceService.AppMessages.GetString("AM_AccountUpdated_Title"),
                    ResourceService.AppMessages.GetString("AM_AccountUpdate"),
                    TwoButtonsDialogType.YesNo);

                if (!result)
                {
                    return;
                }

                NavigateService.Instance.Navigate(typeof(MyAccountPage), false,
                                                  NavigationObject.Create(typeof(MainViewModel), NavigationActionType.Default));
            });
        }
Esempio n. 13
0
        public static async void ShowOverquotaAlert()
        {
            var result = await ShowOkCancelAsync(
                ResourceService.AppMessages.GetString("AM_OverquotaAlert_Title"),
                ResourceService.AppMessages.GetString("AM_OverquotaAlert"),
                TwoButtonsDialogType.YesNo);

            if (!result)
            {
                return;
            }

            UiService.OnUiThread(() =>
            {
                NavigateService.Instance.Navigate(typeof(MyAccountPage), false,
                                                  NavigationObject.Create(typeof(MainViewModel), NavigationActionType.Upgrade));
            });
        }
Esempio n. 14
0
        /// <summary>
        /// Navigate to page that holds the specified viewmodel type
        /// </summary>
        /// <param name="viewModelType">Type of viewmodel to navigate to</param>
        /// <param name="action">Optional navigation action parameter</param>
        /// <param name="parameters">Optional navigation data parameters</param>
        public void NavigateTo(Type viewModelType,
                               NavigationActionType action = NavigationActionType.Default,
                               IDictionary <NavigationParamType, object> parameters = null)
        {
            if (viewModelType == null)
            {
                throw new ArgumentNullException(nameof(viewModelType));
            }

            var pageType = NavigateService.GetViewType(viewModelType);

            if (pageType == null)
            {
                throw new ArgumentException("Viewmodel is not bound to a view");
            }

            var navObj = NavigationObject.Create(this.GetType(), action, parameters);

            OnUiThread(() => this.Navigation.Navigate(pageType, false, navObj));
        }
Esempio n. 15
0
        public async void Download(TransferQueue transferQueue)
        {
            // User must be online to perform this operation
            if ((this.Parent?.Type != ContainerType.FolderLink) && !await IsUserOnlineAsync())
            {
                return;
            }
            if (transferQueue == null)
            {
                return;
            }

            var downloadFolder = await FolderService.SelectFolder();

            if (downloadFolder == null)
            {
                return;
            }
            if (!await TransferService.CheckExternalDownloadPathAsync(downloadFolder.Path))
            {
                return;
            }

            this.Transfer.ExternalDownloadPath = downloadFolder.Path;
            transferQueue.Add(this.Transfer);
            this.Transfer.StartTransfer();

            // If is a file or folder link, navigate to the Cloud Drive page
            if (this.ParentContainerType == ContainerType.FileLink ||
                this.ParentContainerType == ContainerType.FolderLink)
            {
                OnUiThread(() =>
                {
                    NavigateService.Instance.Navigate(typeof(CloudDrivePage), false,
                                                      NavigationObject.Create(this.GetType()));
                });
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Log in to a MEGA account.
        /// </summary>
        public async void Login()
        {
            if (!await NetworkService.IsNetworkAvailableAsync(true))
            {
                return;
            }

            // Reset the flag to store if the account has been blocked
            AccountService.IsAccountBlocked = false;

            SetWarning(false, string.Empty);
            SetInputState();

            if (!CheckInputParameters())
            {
                return;
            }

            var login = new LoginRequestListenerAsync();

            login.IsWaiting += OnIsWaiting;

            this.ControlState     = false;
            this.LoginButtonState = false;
            this.IsBusy           = true;

            this.ProgressHeaderText = ResourceService.ProgressMessages.GetString("PM_LoginHeader");
            this.ProgressText       = ResourceService.ProgressMessages.GetString("PM_LoginSubHeader");

            LoginResult result = await login.ExecuteAsync(() =>
                                                          this.MegaSdk.login(this.Email, this.Password, login));

            if (result == LoginResult.MultiFactorAuthRequired)
            {
                await DialogService.ShowAsyncMultiFactorAuthCodeInputDialogAsync(async (string code) =>
                {
                    result = await login.ExecuteAsync(() =>
                                                      this.MegaSdk.multiFactorAuthLogin(this.Email, this.Password, code, login));

                    if (result == LoginResult.MultiFactorAuthInvalidCode)
                    {
                        DialogService.SetMultiFactorAuthCodeInputDialogWarningMessage();
                        return(false);
                    }

                    return(true);
                });
            }

            // Set default error content
            var errorContent = ResourceService.AppMessages.GetString("AM_LoginFailed");

            switch (result)
            {
            case LoginResult.Success:
                SettingsService.SaveSessionToLocker(this.Email, this.MegaSdk.dumpSession());

                // Validate product subscription license on background thread
                Task.Run(() => LicenseService.ValidateLicensesAsync());

                // Initialize the DB
                AppService.InitializeDatabase();

                // Fetch nodes from MEGA
                var fetchNodesResult = await this.FetchNodes();

                if (fetchNodesResult != FetchNodesResult.Success)
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Fetch nodes failed.");
                    if (!AccountService.IsAccountBlocked)
                    {
                        this.ShowFetchNodesFailedAlertDialog();
                    }
                    return;
                }

                // Navigate to the main page to load the main application for the user
                NavigateService.Instance.Navigate(typeof(MainPage), true,
                                                  NavigationObject.Create(this.GetType(), NavigationActionType.Login));
                return;

            case LoginResult.UnassociatedEmailOrWrongPassword:
                errorContent = ResourceService.AppMessages.GetString("AM_WrongEmailPasswordLogin");
                break;

            case LoginResult.TooManyLoginAttempts:
                // Too many failed login attempts. Wait one hour.
                errorContent = string.Format(ResourceService.AppMessages.GetString("AM_TooManyFailedLoginAttempts"),
                                             DateTime.Now.AddHours(1).ToString("HH:mm:ss"));
                break;

            case LoginResult.AccountNotConfirmed:
                errorContent = ResourceService.AppMessages.GetString("AM_AccountNotConfirmed");
                break;

            case LoginResult.MultiFactorAuthRequired:
            case LoginResult.MultiFactorAuthInvalidCode:
            case LoginResult.Unknown:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            this.ControlState     = true;
            this.LoginButtonState = true;
            this.IsBusy           = false;

            // Show error message
            SetWarning(true, errorContent);
            SetInputState(InputState.Warning, InputState.Warning);
        }
Esempio n. 17
0
        public void onEvent(MegaSDK api, MEvent ev)
        {
            switch (ev.getType())
            {
            case MEventType.EVENT_ACCOUNT_BLOCKED:
                AccountService.IsAccountBlocked = true;

                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Blocked account: " + ev.getText());

                // A blocked account automatically triggers a logout
                AppService.LogoutActions();

                // Show the login page with the corresponding navigation parameter
                UiService.OnUiThread(() =>
                {
                    NavigateService.Instance.Navigate(typeof(LoginAndCreateAccountPage), true,
                                                      NavigationObject.Create(typeof(MainViewModel), NavigationActionType.API_EBLOCKED,
                                                                              new Dictionary <NavigationParamType, object>
                    {
                        { NavigationParamType.Number, ev.getNumber() },
                        { NavigationParamType.Text, ev.getText() }
                    }));
                });
                break;

            case MEventType.EVENT_STORAGE:
                var storageState = (MStorageState)ev.getNumber();
                switch (storageState)
                {
                case MStorageState.STORAGE_STATE_GREEN:
                    LogService.Log(MLogLevel.LOG_LEVEL_INFO, "STORAGE STATE GREEN");
                    UiService.OnUiThread(() =>
                    {
                        AccountService.AccountDetails.IsInStorageOverquota = false;
                        AccountService.AccountDetails.StorageState         = storageState;
                    });
                    break;

                case MStorageState.STORAGE_STATE_ORANGE:
                    LogService.Log(MLogLevel.LOG_LEVEL_INFO, "STORAGE STATE ORANGE");
                    UiService.OnUiThread(() =>
                    {
                        AccountService.AccountDetails.IsInStorageOverquota = false;
                        AccountService.AccountDetails.StorageState         = storageState;
                    });
                    break;

                case MStorageState.STORAGE_STATE_RED:
                    LogService.Log(MLogLevel.LOG_LEVEL_INFO, "STORAGE STATE RED");
                    UiService.OnUiThread(() =>
                    {
                        AccountService.AccountDetails.IsInStorageOverquota = true;
                        if (storageState > AccountService.AccountDetails.StorageState)
                        {
                            DialogService.ShowStorageOverquotaAlert(false);
                        }
                        AccountService.AccountDetails.StorageState = storageState;
                    });
                    break;

                case MStorageState.STORAGE_STATE_CHANGE:
                    LogService.Log(MLogLevel.LOG_LEVEL_INFO, "STORAGE STATE CHANGE");
                    AccountService.GetAccountDetails();
                    break;
                }
                break;
            }
        }
Esempio n. 18
0
 private void Upgrade()
 {
     NavigateService.Instance.Navigate(typeof(MyAccountPage), false,
                                       NavigationObject.Create(typeof(MainViewModel), NavigationActionType.Upgrade));
 }
Esempio n. 19
0
        public async void LoginToFolder(string link)
        {
            if (string.IsNullOrWhiteSpace(link))
            {
                return;
            }

            PublicLinkService.Link = link;

            if (_loginToFolder == null)
            {
                _loginToFolder            = new LoginToFolderRequestListenerAsync();
                _loginToFolder.IsWaiting += OnIsWaiting;
            }

            this.ControlState = false;
            this.IsBusy       = true;

            this.ProgressHeaderText = ResourceService.ProgressMessages.GetString("PM_LoginToFolderHeader");
            this.ProgressText       = ResourceService.ProgressMessages.GetString("PM_LoginToFolderSubHeader");

            var result = await _loginToFolder.ExecuteAsync(() =>
                                                           this.MegaSdk.loginToFolder(PublicLinkService.Link, _loginToFolder));

            bool navigateBack = true;

            switch (result)
            {
            case LoginToFolderResult.Success:
                if (!await this.FetchNodesFromFolder())
                {
                    break;
                }
                this.LoadFolder();
                navigateBack = false;
                break;

            case LoginToFolderResult.InvalidHandleOrDecryptionKey:
                LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "Login to folder failed. Invalid handle or decryption key.");
                PublicLinkService.ShowLinkNoValidAlert();
                break;

            case LoginToFolderResult.InvalidDecryptionKey:
                PublicLinkService.Link = await PublicLinkService.ShowDecryptionKeyNotValidAlertAsync();

                if (PublicLinkService.Link != null)
                {
                    this.LoginToFolder(PublicLinkService.Link);
                    return;
                }
                break;

            case LoginToFolderResult.NoDecryptionKey:
                PublicLinkService.Link = await PublicLinkService.ShowDecryptionAlertAsync();

                this._loginToFolder.DecryptionAlert = true;
                if (PublicLinkService.Link != null)
                {
                    this.LoginToFolder(PublicLinkService.Link);
                    return;
                }
                break;

            case LoginToFolderResult.Unknown:
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Login to folder failed.");
                await DialogService.ShowAlertAsync(
                    ResourceService.AppMessages.GetString("AM_LoginToFolderFailed_Title"),
                    ResourceService.AppMessages.GetString("AM_LoginToFolderFailed"));

                break;
            }

            this.ControlState = true;
            this.IsBusy       = false;

            if (!navigateBack)
            {
                return;
            }

            OnUiThread(() =>
            {
                // Navigate to the Cloud Drive page
                NavigateService.Instance.Navigate(typeof(CloudDrivePage), false,
                                                  NavigationObject.Create(this.GetType()));
            });
        }
Esempio n. 20
0
        public async void GetPublicNode(string link)
        {
            if (string.IsNullOrWhiteSpace(link))
            {
                return;
            }

            PublicLinkService.Link = link;

            if (_getPublicNode == null)
            {
                _getPublicNode = new GetPublicNodeRequestListenerAsync();
            }

            this.ControlState = false;
            this.IsBusy       = true;

            var result = await _getPublicNode.ExecuteAsync(() =>
                                                           this.MegaSdk.getPublicNode(PublicLinkService.Link, _getPublicNode));

            bool navigateBack = true;

            switch (result)
            {
            case GetPublicNodeResult.Success:
                LinkInformationService.PublicNode = _getPublicNode.PublicNode;

                // Save the handle of the last public node accessed (Task #10801)
                SettingsService.SaveLastPublicNodeHandle(_getPublicNode.PublicNode.getHandle());

                this.Node = NodeService.CreateNew(this.MegaSdk, App.AppInformation,
                                                  LinkInformationService.PublicNode, null);
                if (this.Node is ImageNodeViewModel)
                {
                    (this.Node as ImageNodeViewModel).SetThumbnailImage();
                    (this.Node as ImageNodeViewModel).SetPreviewImage();
                }
                navigateBack = false;
                break;

            case GetPublicNodeResult.InvalidHandleOrDecryptionKey:
                LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "Get public node failed. Invalid handle or decryption key.");
                PublicLinkService.ShowLinkNoValidAlert();
                break;

            case GetPublicNodeResult.InvalidDecryptionKey:
                PublicLinkService.Link = await PublicLinkService.ShowDecryptionKeyNotValidAlertAsync();

                if (PublicLinkService.Link != null)
                {
                    this.GetPublicNode(PublicLinkService.Link);
                    return;
                }
                break;

            case GetPublicNodeResult.NoDecryptionKey:
                PublicLinkService.Link = await PublicLinkService.ShowDecryptionAlertAsync();

                this._getPublicNode.DecryptionAlert = true;
                if (PublicLinkService.Link != null)
                {
                    this.GetPublicNode(PublicLinkService.Link);
                    return;
                }
                break;

            case GetPublicNodeResult.UnavailableLink:
                this.ShowUnavailableFileLinkAlert();
                break;

            case GetPublicNodeResult.AssociatedUserAccountTerminated:
                PublicLinkService.ShowAssociatedUserAccountTerminatedAlert();
                break;

            case GetPublicNodeResult.Unknown:
                LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "Get public node failed.");
                await DialogService.ShowAlertAsync(
                    ResourceService.AppMessages.GetString("AM_GetPublicNodeFailed_Title"),
                    ResourceService.AppMessages.GetString("AM_GetPublicNodeFailed"));

                break;
            }

            this.ControlState = true;
            this.IsBusy       = false;

            if (!navigateBack)
            {
                return;
            }

            OnUiThread(() =>
            {
                // Navigate to the Cloud Drive page
                NavigateService.Instance.Navigate(typeof(CloudDrivePage), false,
                                                  NavigationObject.Create(this.GetType()));
            });
        }
Esempio n. 21
0
        private async void ConfirmAccount(object obj)
        {
            SetWarning(false, string.Empty);
            this.EmailInputState    = InputState.Normal;
            this.PasswordInputState = InputState.Normal;

            if (!NetworkService.HasInternetAccess(true))
            {
                return;
            }

            if (!CheckInputParameters())
            {
                return;
            }

            this.ProgressHeaderText    = ResourceService.ProgressMessages.GetString("PM_ConfirmAccountHeader");
            this.ProgressSubHeaderText = ResourceService.ProgressMessages.GetString("PM_ConfirmAccountSubHeader");
            this.ProgressText          = ResourceService.ProgressMessages.GetString("PM_Patient");

            this.IsBusy       = true;
            this.ControlState = false;
            this.ConfirmAccountButtonState = false;

            var confirm = new ConfirmAccountRequestListenerAsync();
            var result  = await confirm.ExecuteAsync(() =>
            {
                SdkService.MegaSdk.confirmAccount(ConfirmLink, Password, confirm);
            });

            this.ControlState = true;
            this.ConfirmAccountButtonState = true;
            this.IsBusy = false;

            string messageContent;

            switch (result)
            {
            case ConfirmAccountResult.Success:
                messageContent = ResourceService.AppMessages.GetString("AM_ConfirmAccountSucces");
                break;

            case ConfirmAccountResult.WrongPassword:
                messageContent = ResourceService.AppMessages.GetString("AM_WrongPassword");
                break;

            case ConfirmAccountResult.Unknown:
                messageContent = ResourceService.AppMessages.GetString("AM_ConfirmAccountFailed");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            await DialogService.ShowAlertAsync(
                ResourceService.UiResources.GetString("UI_ConfirmAccount"),
                messageContent);

            if (result != ConfirmAccountResult.Success)
            {
                return;
            }

            if (Convert.ToBoolean(SdkService.MegaSdk.isLoggedIn()))
            {
                SdkService.MegaSdk.logout(new LogOutRequestListener(false));
            }

            var login = new LoginRequestListenerAsync();

            login.IsWaiting += OnIsWaiting;

            this.ProgressHeaderText    = ResourceService.ProgressMessages.GetString("PM_LoginHeader");
            this.ProgressSubHeaderText = null;
            this.ProgressText          = ResourceService.ProgressMessages.GetString("PM_LoginSubHeader");

            this.IsBusy       = true;
            this.ControlState = false;
            this.ConfirmAccountButtonState = false;

            var loginResult = await login.ExecuteAsync(() =>
            {
                SdkService.MegaSdk.login(this.Email, this.Password, login);
            });

            string errorContent;

            switch (loginResult)
            {
            case LoginResult.Success:
                SettingsService.SaveSessionToLocker(this.Email, SdkService.MegaSdk.dumpSession());

                // Fetch nodes from MEGA
                var fetchNodesResult = await this.FetchNodes();

                if (fetchNodesResult != FetchNodesResult.Success)
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Fetch nodes failed.");
                    this.ShowFetchNodesFailedAlertDialog();
                    NavigateService.Instance.Navigate(typeof(LoginAndCreateAccountPage), true);
                }
                else
                {       // Navigate to the main page to load the main application for the user
                    NavigateService.Instance.Navigate(typeof(MainPage), true,
                                                      NavigationObject.Create(this.GetType(), NavigationActionType.Login));
                }
                return;

            case LoginResult.UnassociatedEmailOrWrongPassword:
                errorContent = ResourceService.AppMessages.GetString("AM_WrongEmailPasswordLogin");
                break;

            case LoginResult.TooManyLoginAttempts:
                // Too many failed login attempts. Wait one hour.
                errorContent = string.Format(ResourceService.AppMessages.GetString("AM_TooManyFailedLoginAttempts"),
                                             DateTime.Now.AddHours(1).ToString("HH:mm:ss"));
                break;

            case LoginResult.AccountNotConfirmed:
                errorContent = ResourceService.AppMessages.GetString("AM_AccountNotConfirmed");
                break;

            case LoginResult.Unknown:
                errorContent = ResourceService.AppMessages.GetString("AM_LoginFailed");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            this.ControlState = true;
            this.ConfirmAccountButtonState = true;
            this.IsBusy = false;

            await DialogService.ShowAlertAsync(
                ResourceService.AppMessages.GetString("AM_LoginFailed_Title"),
                errorContent);

            NavigateService.Instance.Navigate(typeof(LoginAndCreateAccountPage), true);
        }
Esempio n. 22
0
 public override void GoBack()
 {
     NavigateService.Instance.Navigate(typeof(SettingsPage), false,
                                       NavigationObject.Create(typeof(MultiFactorAuthAppSetupViewModel),
                                                               NavigationActionType.SecuritySettings));
 }