コード例 #1
0
        public void Confirm()
        {
            IsWorking = true;
            StateService.PhoneCode = new TLString(Code);
            MTProtoService.VerifyPhoneAsync(
                StateService.PhoneNumber,
                StateService.PhoneCodeHash,
                StateService.PhoneCode,
                auth => BeginOnUIThread(() =>
            {
                TimeCounterString = string.Empty;
                HelpVisibility    = Visibility.Collapsed;
                _callTimer.Stop();

                _isProcessing = false;

                var phoneNumberValue = _phoneNumberValue;
                if (phoneNumberValue == null)
                {
                    var secureRequiredType = _secureRequiredType != null ? _secureRequiredType.DataRequiredType as TLSecureRequiredType : null;
                    var secureType         = secureRequiredType != null && PhoneNumberViewModel.IsValidType(secureRequiredType.Type)
                            ? secureRequiredType.Type
                            : null;

                    // add new phone number from passport settings
                    if (_secureType != null && PhoneNumberViewModel.IsValidType(_secureType))
                    {
                        phoneNumberValue = new TLSecureValue85
                        {
                            Flags = new TLInt(0),
                            Type  = _secureType
                        };
                    }
                    // add new phone number from authorization form
                    else if (secureType != null)
                    {
                        phoneNumberValue = new TLSecureValue85
                        {
                            Flags = new TLInt(0),
                            Type  = secureType
                        };
                    }
                    else
                    {
                        return;
                    }
                }

                IsWorking =
                    PhoneNumberViewModel.SavePhoneAsync(
                        StateService.PhoneNumber, _passwordBase as TLPassword, MTProtoService,
                        result => Execute.BeginOnUIThread(() =>
                {
                    IsWorking = false;
                    if (_authorizationForm != null)
                    {
                        _authorizationForm.Values.Remove(_phoneNumberValue);
                        _authorizationForm.Values.Add(result);
                    }

                    phoneNumberValue.Update(result);
                    phoneNumberValue.NotifyOfPropertyChange(() => phoneNumberValue.Self);

                    if (_secureType != null)
                    {
                        EventAggregator.Publish(new AddSecureValueEventArgs {
                            Values = new List <TLSecureValue> {
                                phoneNumberValue
                            }
                        });
                    }

                    if (_secureRequiredType != null)
                    {
                        _secureRequiredType.UpdateValue();
                    }

                    NavigationService.RemoveBackEntry();
                    NavigationService.GoBack();
                }),
                        error => Execute.BeginOnUIThread(() =>
                {
                    IsWorking = false;

                    if (error.CodeEquals(ErrorCode.BAD_REQUEST) &&
                        error.TypeEquals(ErrorType.PHONE_VERIFICATION_NEEDED))
                    {
                        MTProtoService.SendVerifyPhoneCodeAsync(StateService.PhoneNumber, null,
                                                                sentCode => BeginOnUIThread(() =>
                        {
                            StateService.PhoneCodeHash   = sentCode.PhoneCodeHash;
                            StateService.PhoneRegistered = sentCode.PhoneRegistered;

                            Timeout = sentCode.SendCallTimeout;
                            ResendCodeVisibility = Timeout != null && Timeout.Value > 0
                                            ? Visibility.Collapsed
                                            : Visibility.Visible;

                            var sentCode50 = sentCode as TLSentCode50;
                            if (sentCode50 != null)
                            {
                                _type     = sentCode50.Type;
                                _nextType = sentCode50.NextType;

                                Subtitle = GetSubtitle();
                                NotifyOfPropertyChange(() => Subtitle);

                                var length = _type as ILength;
                                CodeLength = length != null ? length.Length.Value : Constants.DefaultCodeLength;
                                NotifyOfPropertyChange(() => CodeLength);
                            }
                        }),
                                                                error2 => BeginOnUIThread(() =>
                        {
                            if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID))
                            {
                                ShellViewModel.ShowCustomMessageBox(AppResources.PhoneNumberInvalidString, AppResources.Error, AppResources.Ok);
                            }
                            else if (error.CodeEquals(ErrorCode.FLOOD))
                            {
                                ShellViewModel.ShowCustomMessageBox(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, AppResources.Ok);
                            }
                            else
                            {
                                Telegram.Api.Helpers.Execute.ShowDebugMessage("account.sendVerifyPhoneCode error " + error);
                            }
                        }));
                    }
                }));
            }),
                error => BeginOnUIThread(() =>
            {
                IsWorking = false;
                if (error.TypeEquals(ErrorType.PHONE_CODE_INVALID))
                {
                    ShellViewModel.ShowCustomMessageBox(AppResources.PhoneCodeInvalidString, AppResources.Error, AppResources.Ok);
                }
                else if (error.TypeEquals(ErrorType.PHONE_CODE_EMPTY))
                {
                    ShellViewModel.ShowCustomMessageBox(AppResources.PhoneCodeEmpty, AppResources.Error, AppResources.Ok);
                }
                else if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID))
                {
                    ShellViewModel.ShowCustomMessageBox(AppResources.PhoneNumberInvalidString, AppResources.Error, AppResources.Ok);
                }
                else if (error.CodeEquals(ErrorCode.FLOOD))
                {
                    ShellViewModel.ShowCustomMessageBox(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, AppResources.Ok);
                }
                else
                {
                    Telegram.Api.Helpers.Execute.ShowDebugMessage("account.verifyPhone error " + error);
                }
            }));
        }
コード例 #2
0
        private void SaveEmailAsync(TLString email)
        {
            var emailValue = _emailValue;

            if (emailValue == null)
            {
                var secureRequiredType = _secureRequiredType != null ? _secureRequiredType.DataRequiredType as TLSecureRequiredType : null;
                var secureType         = secureRequiredType != null && IsValidType(secureRequiredType.Type)
                    ? secureRequiredType.Type
                    : null;

                // add new email from passport settings
                if (_secureType != null && IsValidType(_secureType))
                {
                    emailValue = new TLSecureValue85
                    {
                        Flags = new TLInt(0),
                        Type  = _secureType
                    };
                }
                // add new email from authorization form
                else if (secureType != null)
                {
                    emailValue = new TLSecureValue85
                    {
                        Flags = new TLInt(0),
                        Type  = secureType
                    };
                }
                else
                {
                    return;
                }
            }

            IsWorking =
                SaveEmailAsync(
                    email, _passwordBase as TLPassword, MTProtoService,
                    result => Execute.BeginOnUIThread(() =>
            {
                IsWorking = false;
                if (_authorizationForm != null)
                {
                    _authorizationForm.Values.Remove(emailValue);
                    _authorizationForm.Values.Add(result);
                }

                emailValue.Update(result);
                emailValue.NotifyOfPropertyChange(() => emailValue.Self);

                if (_secureType != null)
                {
                    EventAggregator.Publish(new AddSecureValueEventArgs {
                        Values = new List <TLSecureValue> {
                            emailValue
                        }
                    });
                }

                if (_secureRequiredType != null)
                {
                    _secureRequiredType.UpdateValue();
                }

                NavigationService.GoBack();
            }),
                    error => Execute.BeginOnUIThread(() =>
            {
                IsWorking = false;

                if (error.CodeEquals(ErrorCode.BAD_REQUEST) &&
                    error.TypeEquals(ErrorType.EMAIL_VERIFICATION_NEEDED))
                {
                    MTProtoService.SendVerifyEmailCodeAsync(email,
                                                            result2 => BeginOnUIThread(() =>
                    {
                        StateService.SentEmailCode = result2;
                        StateService.CurrentEmail  = email;

                        StateService.Password           = _passwordBase;
                        StateService.AuthorizationForm  = _authorizationForm;
                        StateService.SecureValues       = _secureValues;
                        StateService.SecureType         = _secureType;
                        StateService.SecureRequiredType = _secureRequiredType;
                        NavigationService.UriFor <EmailCodeViewModel>().Navigate();
                    }),
                                                            error2 => BeginOnUIThread(() =>
                    {
                        if (error.TypeEquals(ErrorType.EMAIL_INVALID))
                        {
                            ShellViewModel.ShowCustomMessageBox(AppResources.EmailInvalidString, AppResources.Error, AppResources.Ok);
                        }
                        else if (error.CodeEquals(ErrorCode.FLOOD))
                        {
                            ShellViewModel.ShowCustomMessageBox(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, AppResources.Ok);
                        }
                        else
                        {
                            Telegram.Api.Helpers.Execute.ShowDebugMessage("account.sendVerifyEmailCode error " + error);
                        }
                    }));
                }
                else if (error.TypeEquals(ErrorType.EMAIL_INVALID))
                {
                    ShellViewModel.ShowCustomMessageBox(AppResources.EmailInvalidString, AppResources.Error, AppResources.Ok);
                }
                else if (error.CodeEquals(ErrorCode.BAD_REQUEST))
                {
                    ShellViewModel.ShowCustomMessageBox(
                        "account.saveSecureValue" + Environment.NewLine + error.Message,
                        AppResources.AppName,
                        AppResources.Ok);
                }
            }));
        }
コード例 #3
0
        private void SavePhoneAsync(TLString phone)
        {
            var phoneNumberValue = _phoneNumberValue;

            if (phoneNumberValue == null)
            {
                var secureRequiredType = _secureRequiredType != null ? _secureRequiredType.DataRequiredType as TLSecureRequiredType : null;
                var secureType         = secureRequiredType != null && IsValidType(secureRequiredType.Type)
                    ? secureRequiredType.Type
                    : null;

                // add new phone number from passport settings
                if (_secureType != null && IsValidType(_secureType))
                {
                    phoneNumberValue = new TLSecureValue85
                    {
                        Flags = new TLInt(0),
                        Type  = _secureType
                    };
                }
                // add new phone number from authorization form
                else if (secureType != null)
                {
                    phoneNumberValue = new TLSecureValue85
                    {
                        Flags = new TLInt(0),
                        Type  = secureType
                    };
                }
                else
                {
                    return;
                }
            }

            IsWorking =
                SavePhoneAsync(
                    phone, _passwordBase as TLPassword, MTProtoService,
                    result => Execute.BeginOnUIThread(() =>
            {
                IsWorking = false;
                if (_authorizationForm != null)
                {
                    _authorizationForm.Values.Remove(phoneNumberValue);
                    _authorizationForm.Values.Add(result);
                }

                phoneNumberValue.Update(result);
                phoneNumberValue.NotifyOfPropertyChange(() => phoneNumberValue.Self);

                if (_secureType != null)
                {
                    EventAggregator.Publish(new AddSecureValueEventArgs {
                        Values = new List <TLSecureValue> {
                            phoneNumberValue
                        }
                    });
                }

                if (_secureRequiredType != null)
                {
                    _secureRequiredType.UpdateValue();
                }

                NavigationService.GoBack();
            }),
                    error => Execute.BeginOnUIThread(() =>
            {
                IsWorking = false;

                if (error.CodeEquals(ErrorCode.BAD_REQUEST) &&
                    error.TypeEquals(ErrorType.PHONE_VERIFICATION_NEEDED))
                {
                    MTProtoService.SendVerifyPhoneCodeAsync(phone, null,
                                                            result2 => BeginOnUIThread(() =>
                    {
                        StateService.PhoneNumber       = phone;
                        StateService.PhoneNumberString = string.Format(AppResources.ConfirmMessage, PhoneNumberConverter.Convert(StateService.PhoneNumber));
                        StateService.PhoneCodeHash     = result2.PhoneCodeHash;
                        StateService.PhoneRegistered   = result2.PhoneRegistered;
                        StateService.SendCallTimeout   = result2.SendCallTimeout;
                        var sentCode50 = result2 as TLSentCode50;
                        if (sentCode50 != null)
                        {
                            StateService.Type     = sentCode50.Type;
                            StateService.NextType = sentCode50.NextType;
                        }
                        StateService.Password           = _passwordBase;
                        StateService.AuthorizationForm  = _authorizationForm;
                        StateService.SecureValues       = _secureValues;
                        StateService.SecureType         = _secureType;
                        StateService.SecureRequiredType = _secureRequiredType;
                        NavigationService.UriFor <PhoneNumberCodeViewModel>().Navigate();
                    }),
                                                            error2 => BeginOnUIThread(() =>
                    {
                        if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID))
                        {
                            ShellViewModel.ShowCustomMessageBox(AppResources.PhoneNumberInvalidString, AppResources.Error, AppResources.Ok);
                        }
                        else if (error.CodeEquals(ErrorCode.FLOOD))
                        {
                            ShellViewModel.ShowCustomMessageBox(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, AppResources.Ok);
                        }
                        else
                        {
                            Telegram.Api.Helpers.Execute.ShowDebugMessage("account.sendVerifyPhoneCode error " + error);
                        }
                    }));
                }
                else if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID))
                {
                    ShellViewModel.ShowCustomMessageBox(AppResources.PhoneNumberInvalidString, AppResources.Error, AppResources.Ok);
                }
                else if (error.CodeEquals(ErrorCode.BAD_REQUEST))
                {
                    ShellViewModel.ShowCustomMessageBox(
                        "account.saveSecureValue" + Environment.NewLine + error.Message,
                        AppResources.AppName,
                        AppResources.Ok);
                }
            }));
        }
コード例 #4
0
        public void Confirm()
        {
            IsWorking = true;
            MTProtoService.VerifyEmailAsync(
                CurrentEmail,
                new TLString(Code),
                auth => BeginOnUIThread(() =>
            {
                var emailValue = _emailValue;
                if (emailValue == null)
                {
                    var secureType = _authorizationForm != null
                            ? _authorizationForm.RequiredTypes.FirstOrDefault(EmailViewModel.IsValidType)
                            : null;

                    // add new email from passport settings
                    if (_secureType != null && EmailViewModel.IsValidType(_secureType))
                    {
                        emailValue = new TLSecureValue85
                        {
                            Flags = new TLInt(0),
                            Type  = _secureType
                        };
                    }
                    // add new email from authorization form
                    else if (secureType != null)
                    {
                        emailValue = new TLSecureValue85
                        {
                            Flags = new TLInt(0),
                            Type  = secureType
                        };
                    }
                    else
                    {
                        return;
                    }
                }

                IsWorking =
                    EmailViewModel.SaveEmailAsync(
                        CurrentEmail, _passwordBase as TLPassword, MTProtoService,
                        result => Execute.BeginOnUIThread(() =>
                {
                    IsWorking = false;
                    if (_authorizationForm != null)
                    {
                        _authorizationForm.Values.Remove(emailValue);
                        _authorizationForm.Values.Add(result);
                    }

                    emailValue.Update(result);
                    emailValue.NotifyOfPropertyChange(() => emailValue.Self);

                    if (_secureType != null)
                    {
                        EventAggregator.Publish(new AddSecureValueEventArgs {
                            Values = new List <TLSecureValue> {
                                emailValue
                            }
                        });
                    }

                    if (_secureRequiredType != null)
                    {
                        _secureRequiredType.UpdateValue();
                    }

                    NavigationService.RemoveBackEntry();
                    NavigationService.GoBack();
                }),
                        error => Execute.BeginOnUIThread(() =>
                {
                    IsWorking = false;

                    if (error.CodeEquals(ErrorCode.BAD_REQUEST) &&
                        error.TypeEquals(ErrorType.EMAIL_VERIFICATION_NEEDED))
                    {
                        MTProtoService.SendVerifyEmailCodeAsync(CurrentEmail,
                                                                sentCode => BeginOnUIThread(() =>
                        {
                            _sentCode = sentCode;

                            Subtitle = GetSubtitle();
                            NotifyOfPropertyChange(() => Subtitle);

                            var length = _sentCode as ILength;
                            CodeLength = length != null ? length.Length.Value : Constants.DefaultCodeLength;
                            NotifyOfPropertyChange(() => CodeLength);
                        }),
                                                                error2 => BeginOnUIThread(() =>
                        {
                            if (error.TypeEquals(ErrorType.EMAIL_INVALID))
                            {
                                ShellViewModel.ShowCustomMessageBox(AppResources.EmailInvalidString, AppResources.Error, AppResources.Ok);
                            }
                            else if (error.CodeEquals(ErrorCode.FLOOD))
                            {
                                ShellViewModel.ShowCustomMessageBox(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, AppResources.Ok);
                            }
                            else
                            {
                                Telegram.Api.Helpers.Execute.ShowDebugMessage("account.sendVerifyEmailCode error " + error);
                            }
                        }));
                    }
                    else if (error.TypeEquals(ErrorType.EMAIL_INVALID))
                    {
                        ShellViewModel.ShowCustomMessageBox(AppResources.EmailInvalidString, AppResources.Error, AppResources.Ok);
                    }
                }));
            }),
                error => BeginOnUIThread(() =>
            {
                IsWorking = false;
                if (error.TypeEquals(ErrorType.CODE_INVALID))
                {
                    ShellViewModel.ShowCustomMessageBox(AppResources.EmailCodeInvalidString, AppResources.Error, AppResources.Ok);
                }
                else if (error.TypeEquals(ErrorType.CODE_EMPTY))
                {
                    ShellViewModel.ShowCustomMessageBox(AppResources.EmailCodeEmpty, AppResources.Error, AppResources.Ok);
                }
                else if (error.TypeEquals(ErrorType.EMAIL_VERIFY_EXPIRED))
                {
                    ShellViewModel.ShowCustomMessageBox(AppResources.EmailCodeExpiredString, AppResources.Error, AppResources.Ok);
                }
                else if (error.TypeEquals(ErrorType.EMAIL_INVALID))
                {
                    ShellViewModel.ShowCustomMessageBox(AppResources.EmailInvalidString, AppResources.Error, AppResources.Ok);
                }
                else if (error.CodeEquals(ErrorCode.FLOOD))
                {
                    ShellViewModel.ShowCustomMessageBox(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, AppResources.Ok);
                }
                else
                {
                    Telegram.Api.Helpers.Execute.ShowDebugMessage("account.verifyEmail error " + error);
                }
            }));
        }