public void Resend() { if (_isResending) { return; } if (_nextType == null) { SendMail(); return; } _isResending = true; IsWorking = true; MTProtoService.ResendCodeAsync(StateService.PhoneNumber, StateService.PhoneCodeHash, sentCode => BeginOnUIThread(() => { _sentCode = sentCode; _isResending = false; IsWorking = false; 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); } UpdateDebugString(); _startTime = DateTime.Now; _callTimer.Start(); }), error => BeginOnUIThread(() => { _isResending = false; IsWorking = false; Telegram.Api.Helpers.Execute.ShowDebugMessage("auth.resendCode error " + error); })); }
public ResetAccountViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { _timer.Tick += OnTimerTick; var confirmWait = StateService.ConfirmWait; StateService.ConfirmWait = 0; _sentCode = StateService.SentCode; StateService.SentCode = null; UpdateInterval(confirmWait); }
public SignUpViewModel(IUploadFileManager fileManager, ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { SentCode = StateService.SentCode; StateService.SentCode = null; SuppressUpdateStatus = true; FileManager = fileManager; EventAggregator.Subscribe(this); PropertyChanged += (sender, args) => { if (Property.NameEquals(args.PropertyName, () => FirstName) || Property.NameEquals(args.PropertyName, () => LastName)) { NotifyOfPropertyChange(() => CanSignUp); } }; }
public ConfirmPasswordViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { _password = StateService.Password as TLPassword; StateService.Password = null; _sentCode = StateService.SentCode; StateService.SentCode = null; if (_password != null) { PasswordHint = !TLString.IsNullOrEmpty(_password.Hint) ? _password.Hint.ToString() : string.Empty; } PropertyChanged += (sender, args) => { if (Property.NameEquals(args.PropertyName, () => Code)) { NotifyOfPropertyChange(() => CanConfirm); } }; }
public void SignIn() { if (_changePhoneNumber) { ChangePhoneNumber(); return; } #if LOG_REGISTRATION TLUtils.WriteLog("auth.sendCode"); #endif IsWorking = true; NotifyOfPropertyChange(() => CanSignIn); var phoneNumber = PhoneCode + PhoneNumber; _startTime = DateTime.Now; _showHelpTimer.Start(); MTProtoService.SendCodeAsync(new TLString(phoneNumber), TLSmsType.Code, sentCode => BeginOnUIThread(() => { #if LOG_REGISTRATION TLUtils.WriteLog("auth.sendCode result: " + sentCode); #endif _sentCode = sentCode; _showHelpTimer.Stop(); StateService.PhoneNumber = new TLString(phoneNumber); StateService.PhoneNumberString = string.Format(AppResources.ConfirmMessage, PhoneNumberConverter.Convert(StateService.PhoneNumber)); StateService.PhoneCodeHash = sentCode.PhoneCodeHash; StateService.PhoneRegistered = sentCode.PhoneRegistered; StateService.SendCallTimeout = sentCode.SendCallTimeout; NavigationService.UriFor <ConfirmViewModel>().Navigate(); IsWorking = false; NotifyOfPropertyChange(() => CanSignIn); }), attemptNumber => BeginOnUIThread(() => { #if LOG_REGISTRATION TLUtils.WriteLog("auth.sendCode attempt failed " + attemptNumber); #endif Execute.ShowDebugMessage("auth.sendCode attempt failed " + attemptNumber); }), error => BeginOnUIThread(() => { #if LOG_REGISTRATION TLUtils.WriteLog("auth.sendCode error " + error); #endif _lastError = error; IsWorking = false; NotifyOfPropertyChange(() => CanSignIn); if (error.TypeEquals(ErrorType.PHONE_NUMBER_INVALID)) { MessageBox.Show(AppResources.PhoneNumberInvalidString, AppResources.Error, MessageBoxButton.OK); } else if (error.CodeEquals(ErrorCode.FLOOD)) { MessageBox.Show(AppResources.FloodWaitString + Environment.NewLine + "(" + error.Message + ")", AppResources.Error, MessageBoxButton.OK); } else { Execute.ShowDebugMessage("auth.sendCode error " + error); } })); }
public ConfirmViewModel(IExtendedDeviceInfoService extendedDeviceInfoService, DebugViewModel debug, ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { _extendedDeviceInfoService = extendedDeviceInfoService; #if DEBUG HelpVisibility = Visibility.Visible; #endif _type = stateService.Type; stateService.Type = null; _nextType = stateService.NextType; stateService.NextType = null; Subtitle = GetSubtitle(); var length = _type as ILength; CodeLength = length != null ? length.Length.Value : Constants.DefaultCodeLength; Timeout = stateService.SendCallTimeout; ResendCodeVisibility = stateService.SendCallTimeout != null && stateService.SendCallTimeout.Value > 0 ? Visibility.Collapsed : Visibility.Visible; UpdateDebugString(); EventAggregator.Subscribe(this); SuppressUpdateStatus = true; Debug = debug; if (StateService.ChangePhoneNumber) { _changePhoneNumber = true; StateService.ChangePhoneNumber = false; } _sentCode = StateService.SentCode; StateService.SentCode = null; //_updatesService = updatesService; PropertyChanged += (sender, args) => { if (Property.NameEquals(args.PropertyName, () => Code)) { NotifyOfPropertyChange(() => CanConfirm); if (!string.IsNullOrEmpty(Code) && Code.Length == CodeLength) { Confirm(); } } }; _callTimer.Tick += (sender, args) => { _timeCounter = Timeout == null ? 0 : (int)(Timeout.Value - (DateTime.Now - _startTime).TotalSeconds); if (_timeCounter > 0) { #if DEBUG TimeCounterString = _timeCounter.ToString(CultureInfo.InvariantCulture); #endif if (_nextType is TLCodeTypeCall) { TimeCounterString = string.Format(AppResources.WeWillCallYou, TimeSpan.FromSeconds(TimeCounter).ToString(@"m\:ss")); } } else { _timeCounter = 0; if (_nextType is TLCodeTypeCall) { TimeCounterString = AppResources.TelegramDialedYourNumber; } HelpVisibility = Visibility.Visible; ResendCodeVisibility = Visibility.Visible; _callTimer.Stop(); } NotifyOfPropertyChange(() => TimeCounter); }; }