Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public Session Load(string sessionUserId)
        {
            ConfigTelegram configTelegram = _context.GetConfiguration <ConfigTelegram>(_provider.ServiceName, _signUpSender.UserName).Result;

            return(null);
            //   configTelegram.Session.from
            //var sessionFileName = $"{sessionUserId}.dat";
            //if (!File.Exists(sessionFileName))
            //    return null;

            //using (var stream = new FileStream(sessionFileName, FileMode.Open))
            //{
            //    var buffer = new byte[2048];
            //    stream.Read(buffer, 0, 2048);

            //    return Session.FromBytes(buffer, this, sessionUserId);
            //}
        }
Ejemplo n.º 4
0
 public BaladorSessionStore(IBaladorContext context, ConfigTelegram configTelegram, IAppMessangerFactrory provider, SignUpSender signUpSender)
 {
     _context = context; _configTelegram = configTelegram;  _provider = provider; _signUpSender = signUpSender;
 }