Пример #1
0
        /// <inheritdoc />
        public async Task<TUser> SignUpAsync(string phoneNumber,
                                             ISentCode sentCode,
                                             string code,
                                             string firstName,
                                             string lastName,
                                             CancellationToken cancellationToken = default(CancellationToken))
        {
            Guard.That(phoneNumber, nameof(phoneNumber)).IsNotNullOrWhiteSpace();
            Guard.That(code, nameof(code)).IsNotNullOrWhiteSpace();
            Guard.That(firstName, nameof(firstName)).IsNotNullOrWhiteSpace();
            Guard.That(lastName, nameof(lastName)).IsNotNullOrWhiteSpace();

            var request = new RequestSignUp
                          {
                              PhoneNumber = phoneNumber,
                              PhoneCode = code,
                              PhoneCodeHash = sentCode.PhoneCodeHash,
                              FirstName = firstName,
                              LastName = lastName
                          };
            var result = (TAuthorization)await RequestSender.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);

            var user = result.User.Is<TUser>();

            await OnUserAuthenticated(user).ConfigureAwait(false);
            return user;
        }
Пример #2
0
            public async Task <string> HandleAsync(Query query)
            {
                string     hashedPhoneId = HashHelper.GetHash(query.PhoneNumber);
                IClientApi client        = await _telegramService.BuildAsync(hashedPhoneId).ConfigureAwait(false);

                ISentCode result = await TelegramRequest.HandleAsync(() =>
                {
                    return(client.AuthService.SendCodeAsync(query.PhoneNumber));
                }).ConfigureAwait(false);

                return(result.PhoneCodeHash);
            }
Пример #3
0
 private void btnTelegramLogin_Click(object sender, EventArgs e)
 {
     try
     {
         hash = Task.Run(() => Telegram.clientApi.AuthService.SendCodeAsync(txtPhoneNumber.Text)).Result;
         Properties.Settings.Default.PhoneNumber = txtPhoneNumber.Text;
         Properties.Settings.Default.Save();
         txtVerificationCode.Enabled = true;
         btnSendVerification.Enabled = true;
         txtPhoneNumber.Enabled      = false;
         btnTelegramLogin.Enabled    = false;
     }
     catch (AggregateException ex)
     {
         MessageBox.Show(ex.InnerExceptions[0].Message, "Telecord");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Telecord");
     }
 }