public async Task SignIn(string phone) { var sentCode = await _clientApi.AuthService.SendCodeAsync(phone).ConfigureAwait(false); var code = ReadLineHelper.Read("Write a code:"); try { _user = await _clientApi.AuthService.SignInAsync(phone, sentCode, code).ConfigureAwait(false); Console.WriteLine($"User login. Current user is {_user.FirstName} {_user.LastName}"); } catch (CloudPasswordNeededException) { ReadLine.PasswordMode = true; var passwordStr = ReadLineHelper.ReadPassword("Write a password:"); ReadLine.PasswordMode = false; _user = await _clientApi.AuthService.CheckCloudPasswordAsync(passwordStr).ConfigureAwait(false); } catch (PhoneCodeInvalidException) { } _clientApi.UpdatesService.StartReceiveUpdates(TimeSpan.FromSeconds(1)); }
private static void Main(string[] args) { var configuration = Initialize(); var client = new Client(); client.Init( new FactorySettings { AppHash = configuration["AppHash"], AppId = int.Parse(configuration["AppId"]), ServerAddress = configuration["ServerAddress"], ServerPublicKey = configuration["PublicKey"], ServerPort = Convert.ToInt32(configuration["Port"]), SessionTag = "session", Properties = new ApplicationProperties { AppVersion = "1.0.0", DeviceModel = "PC", LangCode = "en", LangPack = "tdesktop", SystemLangCode = "en", SystemVersion = "Win 10 Pro" } }).Wait(); while (true) { var input = ReadLineHelper.Read("(prompt)>"); Parser.Default.ParseArguments <SignInOptions, LogOutOptions>(input.Split(' ')) .MapResult <SignInOptions, LogOutOptions, Task>( opt => client.SignIn(opt.Phone), opt => client.LogOut(), errors => Task.FromResult(1)) .Wait(); } }