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 override TLObject FromBytes(byte[] bytes, ref int position) { bytes.ThrowExceptionIfIncorrect(ref position, Signature); Flags = GetObject <TLInt>(bytes, ref position); Type = GetObject <TLSentCodeTypeBase>(bytes, ref position); PhoneCodeHash = GetObject <TLString>(bytes, ref position); NextType = GetObject <TLCodeTypeBase>(Flags, (int)SentCodeFlags.NextType, null, bytes, ref position); SendCallTimeout = GetObject <TLInt>(Flags, (int)SentCodeFlags.Timeout, null, bytes, ref position); return(this); }
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); } })); }
public PhoneNumberCodeViewModel(ICacheService cacheService, ICommonErrorHandler errorHandler, IStateService stateService, INavigationService navigationService, IMTProtoService mtProtoService, ITelegramEventAggregator eventAggregator) : base(cacheService, errorHandler, stateService, navigationService, mtProtoService, eventAggregator) { _passwordBase = stateService.Password; stateService.Password = null; _authorizationForm = stateService.AuthorizationForm; stateService.AuthorizationForm = null; _secureValues = stateService.SecureValues; stateService.SecureValues = null; _secureType = stateService.SecureType; stateService.SecureType = null; _secureRequiredType = stateService.SecureRequiredType; stateService.SecureRequiredType = null; _phoneNumberValue = _secureRequiredType != null ? _secureRequiredType.DataValue : null; _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; SuppressUpdateStatus = true; EventAggregator.Subscribe(this); 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); }; }
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); }; }