Example #1
0
        public override async Task <ResponseBase> SetObservableToken(SignUpSender signUpSender, BToken token)
        {
            ConfigTelegram configTelegram = await Context.GetConfiguration <ConfigTelegram>(Provider.ServiceName, signUpSender.UserName);

            var store  = new BaladorSessionStore(this.Context, configTelegram, this.Provider, signUpSender);
            var client = new TelegramClient(configTelegram.Api, configTelegram.Api_Hash, store);
            var user   = await client.MakeAuthAsync(configTelegram.Phone, configTelegram.CodeRequest, token.Token);

            configTelegram.Token = token.Token;
            var result = await this.Context.SetConfiguration(this.Provider.ServiceName, signUpSender.UserName, configTelegram);

            return(result);
        }
Example #2
0
        public override async Task <Response <AuthenticationUser> > SignIn(SignUpSender senderDetail, NameValueCollection extraDataForm)
        {
            var response = new Response <AuthenticationUser>();

            response.Result = new AuthenticationUser {
                IsTwoFactorAuthentication = true, UserId = senderDetail.UserName
            };
            response.IsError = true;

            var            phone          = extraDataForm["phone"];
            var            api            = extraDataForm["API_ID"];
            var            apiHash        = extraDataForm["API_HASH"];
            int            apiId          = int.Parse(api);
            ConfigTelegram configTelegram = await Context.GetConfiguration <ConfigTelegram>(Provider.ServiceName, senderDetail.UserName);

            var store       = new BaladorSessionStore(this.Context, configTelegram, this.Provider, senderDetail);
            var client      = new TelegramClient(apiId, apiHash, store);
            var isconnected = await client.ConnectAsync();

            if (!isconnected)
            {
                return(new Response <AuthenticationUser> {
                    IsError = true, Message = "unable to connect"
                });
            }

            configTelegram = configTelegram ?? new ConfigTelegram {
                Token = "", Phone = phone, Api = apiId, Api_Hash = apiHash
            };
            var estaRegistrado = await client.IsPhoneRegisteredAsync(phone);

            if (estaRegistrado)
            {
                if (!client.IsUserAuthorized())
                {
                    configTelegram.CodeRequest = await client.SendCodeRequestAsync(phone);
                }
            }

            var isregister = await client.ConnectAsync();

            if (isregister)
            {
                response.IsError = false;
                await Context.SetConfiguration(this.Provider.ServiceName, senderDetail.UserName, new ConfigTelegram { Token = "", Phone = phone });
            }
            return(response);
        }