示例#1
0
        private async void SendExecute()
        {
            if (_sentCode == null)
            {
                //...
                return;
            }

            if (string.IsNullOrEmpty(_phoneCode))
            {
                RaisePropertyChanged("SENT_CODE_INVALID");
                return;
            }

            var phoneNumber   = _phoneNumber;
            var phoneCodeHash = _sentCode.PhoneCodeHash;

            IsLoading = true;

            var response = await LegacyService.ChangePhoneAsync(phoneNumber, phoneCodeHash, _phoneCode);

            if (response.IsSucceeded)
            {
                while (NavigationService.Frame.BackStackDepth > 1)
                {
                    NavigationService.Frame.BackStack.RemoveAt(1);
                }

                NavigationService.GoBack();
            }
            else
            {
                IsLoading = false;

                if (response.Error.TypeEquals(TLErrorType.PHONE_NUMBER_UNOCCUPIED))
                {
                    //var signup = await ProtoService.SignUpAsync(phoneNumber, phoneCodeHash, PhoneCode, "Paolo", "Veneziani");
                    //if (signup.IsSucceeded)
                    //{
                    //    ProtoService.SetInitState();
                    //    ProtoService.CurrentUserId = signup.Value.User.Id;
                    //    SettingsHelper.IsAuthorized = true;
                    //    SettingsHelper.UserId = signup.Value.User.Id;
                    //}

                    //this._callTimer.Stop();
                    //this.StateService.ClearNavigationStack = true;
                    //this.NavigationService.UriFor<SignUpViewModel>().Navigate();
                    var state = new SignUpPage.NavigationParameters
                    {
                        PhoneNumber = _phoneNumber,
                        PhoneCode   = _phoneCode,
                        //Result = _sentCode,
                    };

                    NavigationService.Navigate(typeof(SignUpPage), state);
                }
                else if (response.Error.TypeEquals(TLErrorType.PHONE_CODE_INVALID))
                {
                    //await new MessageDialog(Resources.PhoneCodeInvalidString, Resources.Error).ShowAsync();
                }
                else if (response.Error.TypeEquals(TLErrorType.PHONE_CODE_EMPTY))
                {
                    //await new MessageDialog(Resources.PhoneCodeEmpty, Resources.Error).ShowAsync();
                }
                else if (response.Error.TypeEquals(TLErrorType.PHONE_CODE_EXPIRED))
                {
                    //await new MessageDialog(Resources.PhoneCodeExpiredString, Resources.Error).ShowAsync();
                }
                else if (response.Error.TypeEquals(TLErrorType.SESSION_PASSWORD_NEEDED))
                {
                    //this.IsWorking = true;
                    var password = await LegacyService.GetPasswordAsync();

                    if (password.IsSucceeded && password.Result is TLAccountPassword)
                    {
                        var state = new SignInPasswordPage.NavigationParameters
                        {
                            PhoneNumber = _phoneNumber,
                            PhoneCode   = _phoneCode,
                            //Result = _sentCode,
                            //Password = password.Result as TLAccountPassword
                        };

                        NavigationService.Navigate(typeof(SignInPasswordPage), state);
                    }
                    else
                    {
                        Execute.ShowDebugMessage("account.getPassword error " + password.Error);
                    }
                }
                else if (response.Error.CodeEquals(TLErrorCode.FLOOD))
                {
                    //await new MessageDialog($"{Resources.FloodWaitString}\r\n\r\n({error.Message})", Resources.Error).ShowAsync();
                }

                Execute.ShowDebugMessage("account.signIn error " + response.Error);
            }
        }