Пример #1
0
        public void OnBackKeyPress()
        {
            if (Notifications.IsDisabled)
            {
                var result = MessageBox.Show(
                    AppResources.ConfirmPushMessage,
                    AppResources.ConfirmPushTitle,
                    MessageBoxButton.OKCancel);

                if (result != MessageBoxResult.OK)
                {
                    Notifications.Disable();
                }
                else
                {
                    Notifications.Enable();
                }
            }

            Settings.PropertyChanged -= OnSettingsChanged;
        }
        public void RecoverPassword()
        {
            if (_passwordBase == null)
            {
                return;
            }
            if (IsWorking)
            {
                return;
            }

            HasError = false;
            Error    = string.Empty;

            IsWorking = true;
            MTProtoService.RecoverPasswordAsync(new TLString(Code),
                                                auth => BeginOnUIThread(() =>
            {
                IsWorking = false;

                if (!_passwordBase.IsAuthRecovery)
                {
                    MTProtoService.GetPasswordAsync(
                        passwordResult => BeginOnUIThread(() =>
                    {
                        MessageBox.Show(AppResources.PasswordDeactivated, AppResources.AppName, MessageBoxButton.OK);

                        StateService.RemoveBackEntry = true;
                        StateService.Password        = passwordResult;
                        NavigationService.UriFor <PasswordViewModel>().Navigate();
                    }),
                        error2 =>
                    {
                        Execute.ShowDebugMessage("account.getPassword error " + error2);
                    });
                }
                else
                {
                    _passwordBase.IsAuthRecovery = false;
#if LOG_REGISTRATION
                    TLUtils.WriteLog("auth.recoverPassword result " + auth);
                    TLUtils.WriteLog("TLUtils.IsLogEnabled=false");
#endif

                    TLUtils.IsLogEnabled = false;
                    TLUtils.LogItems.Clear();

                    var result = MessageBox.Show(
                        AppResources.ConfirmPushMessage,
                        AppResources.ConfirmPushTitle,
                        MessageBoxButton.OKCancel);

                    if (result != MessageBoxResult.OK)
                    {
                        Notifications.Disable();
                    }
                    else
                    {
                        Notifications.Enable();
                    }

                    ConfirmViewModel.UpdateNotificationsAsync(MTProtoService, StateService);

                    MTProtoService.SetInitState();
                    StateService.CurrentUserId = auth.User.Index;
                    StateService.FirstRun      = true;
                    SettingsHelper.SetValue(Constants.IsAuthorizedKey, true);

                    ShellViewModel.Navigate(NavigationService);
                }
            }),
                                                error => BeginOnUIThread(() =>
            {
                IsWorking = false;

                var messageBuilder = new StringBuilder();
                //messageBuilder.AppendLine(AppResources.Error);
                //messageBuilder.AppendLine();
                messageBuilder.AppendLine("Method: account.recoveryPassword");
                messageBuilder.AppendLine("Result: " + error);

                if (TLRPCError.CodeEquals(error, ErrorCode.FLOOD))
                {
                    HasError = true;
                    Error    = AppResources.FloodWaitString;
                    Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.FloodWaitString, AppResources.Error, MessageBoxButton.OK));
                }
                else if (TLRPCError.CodeEquals(error, ErrorCode.INTERNAL))
                {
                    HasError = true;
                    Error    = AppResources.ServerError;
                    Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.ServerError, MessageBoxButton.OK));
                }
                else if (TLRPCError.CodeEquals(error, ErrorCode.BAD_REQUEST))
                {
                    if (TLRPCError.TypeEquals(error, ErrorType.CODE_EMPTY))
                    {
                        HasError = true;
                        Error    = string.Format("{0} {1}", error.Code, error.Message);
                        Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK));
                    }
                    else if (TLRPCError.TypeEquals(error, ErrorType.CODE_INVALID))
                    {
                        HasError = true;
                        Error    = string.Format("{0} {1}", error.Code, error.Message);
                        Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK));
                    }
                    else if (TLRPCError.TypeEquals(error, ErrorType.PASSWORD_EMPTY))
                    {
                        HasError = true;
                        Error    = string.Format("{0} {1}", error.Code, error.Message);
                        Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK));
                    }
                    else if (TLRPCError.TypeEquals(error, ErrorType.PASSWORD_RECOVERY_NA))
                    {
                        HasError = true;
                        Error    = AppResources.EmailInvalid;
                        Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.EmailInvalid, AppResources.Error, MessageBoxButton.OK));
                    }
                    else if (TLRPCError.TypeEquals(error, ErrorType.PASSWORD_RECOVERY_EXPIRED))
                    {
                        HasError = true;
                        Error    = string.Format("{0} {1}", error.Code, error.Message);
                        Execute.BeginOnUIThread(() => MessageBox.Show(AppResources.EmailInvalid, AppResources.Error, MessageBoxButton.OK));
                    }
                    else
                    {
                        HasError = true;
                        Error    = string.Format("{0} {1}", error.Code, error.Message);
                        Execute.BeginOnUIThread(() => MessageBox.Show(messageBuilder.ToString(), AppResources.Error, MessageBoxButton.OK));
                    }
                }
                else
                {
                    HasError = true;
                    Error    = string.Empty;
                    Execute.ShowDebugMessage("account.recoveryPassword error " + error);
                }
            }));
        }
Пример #3
0
        public void Confirm()
        {
            if (_changePhoneNumber)
            {
                ConfirmChangePhoneNumber();
                return;
            }

            IsWorking = true;
            StateService.PhoneCode = new TLString(Code);
#if LOG_REGISTRATION
            TLUtils.WriteLog("auth.signIn");
#endif
            MTProtoService.SignInAsync(
                StateService.PhoneNumber, StateService.PhoneCodeHash, StateService.PhoneCode,
                auth => BeginOnUIThread(() =>
            {
#if LOG_REGISTRATION
                TLUtils.WriteLog("auth.signIn result " + auth);
                TLUtils.WriteLog("TLUtils.IsLogEnabled=false");
#endif

                TLUtils.IsLogEnabled = false;
                TLUtils.LogItems.Clear();

                TimeCounterString = string.Empty;
                HelpVisibility    = Visibility.Collapsed;
                _callTimer.Stop();

                var result = MessageBox.Show(
                    AppResources.ConfirmPushMessage,
                    AppResources.ConfirmPushTitle,
                    MessageBoxButton.OKCancel);

                if (result != MessageBoxResult.OK)
                {
                    Notifications.Disable();
                }
                else
                {
                    Notifications.Enable();
                }

                UpdateNotificationsAsync(MTProtoService, StateService);

                MTProtoService.SetInitState();
                CacheService.ClearConfigImportAsync();
                //_updatesService.SetCurrentUser(auth.User);
                _isProcessing = false;
                StateService.CurrentUserId = auth.User.Index;
                StateService.FirstRun      = true;
                SettingsHelper.SetValue(Constants.IsAuthorizedKey, true);

                ShellViewModel.Navigate(NavigationService);

                IsWorking = false;
            }),
                error => BeginOnUIThread(() =>
            {
#if LOG_REGISTRATION
                TLUtils.WriteLog("auth.signIn error " + error);
#endif
                _lastError = error;
                IsWorking  = false;
                if (error.TypeEquals(ErrorType.PHONE_NUMBER_UNOCCUPIED))
                {
                    _callTimer.Stop();
                    StateService.SentCode             = _sentCode;
                    StateService.ClearNavigationStack = true;
                    NavigationService.UriFor <SignUpViewModel>().Navigate();
                }
                else if (error.TypeEquals(ErrorType.PHONE_CODE_INVALID))
                {
                    MessageBox.Show(AppResources.PhoneCodeInvalidString, AppResources.Error, MessageBoxButton.OK);
                }
                else if (error.TypeEquals(ErrorType.PHONE_CODE_EMPTY))
                {
                    MessageBox.Show(AppResources.PhoneCodeEmpty, AppResources.Error, MessageBoxButton.OK);
                }
                else if (error.TypeEquals(ErrorType.PHONE_CODE_EXPIRED))
                {
                    MessageBox.Show(AppResources.PhoneCodeExpiredString, AppResources.Error, MessageBoxButton.OK);
                    OnBackKeyPress();
                    NavigationService.GoBack();
                }
                else if (error.TypeEquals(ErrorType.SESSION_PASSWORD_NEEDED))
                {
                    IsWorking = true;
                    MTProtoService.GetPasswordAsync(
                        password => BeginOnUIThread(() =>
                    {
                        IsWorking = false;
                        _callTimer.Stop();
                        StateService.Password        = password;
                        StateService.RemoveBackEntry = true;
                        NavigationService.UriFor <ConfirmPasswordViewModel>().Navigate();
                    }),
                        error2 =>
                    {
                        IsWorking = false;
                        Telegram.Api.Helpers.Execute.ShowDebugMessage("account.getPassword error " + error);
                    });
                }
                else if (error.CodeEquals(ErrorCode.FLOOD))
                {
                    MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK);
                }
                else
                {
                    Telegram.Api.Helpers.Execute.ShowDebugMessage("account.signIn error " + error);
                }
            }));
        }
        public void Confirm()
        {
            if (_password == null)
            {
                return;
            }
            if (!CanConfirm)
            {
                return;
            }

            var password84 = _password as TLPassword84;

            if (password84 == null)
            {
                return;
            }

            var algo = password84.CurrentAlgo as TLPasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow;

            if (algo == null)
            {
                return;
            }

            IsWorking = true;
#if LOG_REGISTRATION
            TLUtils.WriteLog("auth.checkPassword");
#endif

            BeginOnThreadPool(() =>
            {
                //var passwordHash = Utils.Password.GetHash(_password.CurrentSalt, new TLString(Code));
                var passwordHash = SRP.GetX(new TLString(Code), algo);
                var password     = SRP.GetCheck(passwordHash, password84.SRPId, password84.SRPB, algo);

                MTProtoService.CheckPasswordAsync(
                    password,
                    auth => BeginOnUIThread(() =>
                {
#if LOG_REGISTRATION
                    TLUtils.WriteLog("auth.checkPassword result " + auth);
                    TLUtils.WriteLog("TLUtils.IsLogEnabled=false");
#endif

                    TLUtils.IsLogEnabled = false;
                    TLUtils.LogItems.Clear();

                    var result = MessageBox.Show(
                        AppResources.ConfirmPushMessage,
                        AppResources.ConfirmPushTitle,
                        MessageBoxButton.OKCancel);

                    if (result != MessageBoxResult.OK)
                    {
                        Notifications.Disable();
                    }
                    else
                    {
                        Notifications.Enable();
                    }

                    ConfirmViewModel.UpdateNotificationsAsync(MTProtoService, StateService);

                    MTProtoService.SetInitState();
                    StateService.CurrentUserId = auth.User.Index;
                    StateService.FirstRun      = true;
                    SettingsHelper.SetValue(Constants.IsAuthorizedKey, true);

                    ShellViewModel.Navigate(NavigationService);

                    IsWorking = false;
                }),
                    error => BeginOnUIThread(() =>
                {
#if LOG_REGISTRATION
                    TLUtils.WriteLog("auth.checkPassword error " + error);
#endif
                    IsWorking = false;
                    if (error.TypeEquals(ErrorType.PASSWORD_HASH_INVALID))
                    {
                        MTProtoService.GetPasswordAsync(
                            result1 => BeginOnUIThread(() =>
                        {
                            _password = result1 as TLPassword84;
                            MessageBox.Show(AppResources.PasswordInvalidString, AppResources.Error, MessageBoxButton.OK);
                        }),
                            error1 => BeginOnUIThread(() =>
                        {
                            MessageBox.Show(AppResources.PasswordInvalidString, AppResources.Error, MessageBoxButton.OK);
                        }));
                    }
                    else if (error.CodeEquals(ErrorCode.FLOOD))
                    {
                        MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK);
                    }
                    else if (error.TypeEquals(ErrorType.SRP_ID_INVALID))
                    {
                        IsWorking = true;
                        MTProtoService.GetPasswordAsync(
                            result1 => BeginOnUIThread(() =>
                        {
                            IsWorking = false;
                            _password = result1 as TLPassword84;
                            Confirm();
                        }),
                            error1 => BeginOnUIThread(() =>
                        {
                            IsWorking = false;
                        }));
                    }
                    else
                    {
                        Execute.ShowDebugMessage("account.checkPassword error " + error);
                    }
                }));
            });
        }
Пример #5
0
        public void SignUp()
        {
            var result = MessageBox.Show(
                AppResources.ConfirmAgeMessage,
                AppResources.ConfirmAgeTitle,
                MessageBoxButton.OKCancel);

            if (result != MessageBoxResult.OK)
            {
                return;
            }

            IsWorking = true;
            NotifyOfPropertyChange(() => CanSignUp);
            MTProtoService.SignUpAsync(
                StateService.PhoneNumber, StateService.PhoneCodeHash, StateService.PhoneCode,
                new TLString(FirstName), new TLString(LastName),
                auth => BeginOnUIThread(() =>
            {
                TLUtils.IsLogEnabled = false;
                TLUtils.LogItems.Clear();

                result = MessageBox.Show(
                    AppResources.ConfirmPushMessage,
                    AppResources.ConfirmPushTitle,
                    MessageBoxButton.OKCancel);

                if (result != MessageBoxResult.OK)
                {
                    Notifications.Disable();
                }
                else
                {
                    Notifications.Enable();
                }

                ConfirmViewModel.UpdateNotificationsAsync(MTProtoService, StateService);

                MTProtoService.SetInitState();

                StateService.CurrentUserId = auth.User.Index;
                StateService.FirstRun      = true;
                SettingsHelper.SetValue(Constants.IsAuthorizedKey, true);

                ShellViewModel.Navigate(NavigationService);

                IsWorking = false;
                NotifyOfPropertyChange(() => CanSignUp);

                if (StateService.ProfilePhotoBytes != null)
                {
                    var bytes = StateService.ProfilePhotoBytes;
                    StateService.ProfilePhotoBytes = null;
                    var fileId = TLLong.Random();
                    FileManager.UploadFile(fileId, new TLUser66 {
                        IsSelf = true
                    }, bytes);
                }
            }),
                error => BeginOnUIThread(() =>
            {
                IsWorking = false;
                NotifyOfPropertyChange(() => CanSignUp);

                if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID))
                {
                    MessageBox.Show(AppResources.PhoneNumberInvalidString, AppResources.Error, MessageBoxButton.OK);
                }
                else if (error.TypeEquals(ErrorType.PHONE_CODE_INVALID))
                {
                    MessageBox.Show(AppResources.PhoneCodeInvalidString, AppResources.Error, MessageBoxButton.OK);
                }
                else if (error.TypeEquals(ErrorType.PHONE_CODE_EMPTY))
                {
                    MessageBox.Show(AppResources.PhoneCodeEmpty, AppResources.Error, MessageBoxButton.OK);
                }
                else if (error.TypeEquals(ErrorType.PHONE_CODE_EXPIRED))
                {
                    MessageBox.Show(AppResources.PhoneCodeExpiredString, AppResources.Error, MessageBoxButton.OK);
                    ClearViewModel();
                    NavigationService.GoBack();
                }
                else if (error.CodeEquals(ErrorCode.FLOOD))
                {
                    MessageBox.Show(AppResources.FloodWaitString, AppResources.Error, MessageBoxButton.OK);
                }
                else if (error.TypeEquals(ErrorType.FIRSTNAME_INVALID))
                {
                    MessageBox.Show(AppResources.FirstNameInvalidString, AppResources.Error, MessageBoxButton.OK);
                }
                else if (error.TypeEquals(ErrorType.LASTNAME_INVALID))
                {
                    MessageBox.Show(AppResources.LastNameInvalidString, AppResources.Error, MessageBoxButton.OK);
                }
                else
                {
                    Telegram.Api.Helpers.Execute.ShowDebugMessage("auth.signUp error " + error);
                }
            }));
        }