Exemplo n.º 1
0
        private async Task <bool> UnlockAccount(RSRecoveryForm recovery, RsWebHelper rsHelper)
        {
            var captchaRes = await GetCaptchaSolveKey(recovery, rsHelper);

            if (captchaRes == string.Empty)
            {
                return(false);
            }

            recovery.CaptchaSolve = captchaRes;
            StatusUpdate(ServiceStatusCode.Updated, recovery, "Requesting account recovery");

            var response = await
                           rsHelper.PostRequest(recovery);

            if (!response.Contains("Account Identified"))
            {
                StatusUpdate(ServiceStatusCode.Updated, recovery, "An error occured requesting recovery page");
                return(false);
            }

            var requestTime = DateTime.Now;
            var redirectUrl = GetUnlockUrl(response);

            response = (await rsHelper.GetRequest(redirectUrl)).message;

            if (!response.Contains("Proceeded to e-mail confirmation screen"))
            {
                StatusUpdate(ServiceStatusCode.Updated, recovery, "An error occured requesting account recovery");
                return(false);
            }


            StatusUpdate(ServiceStatusCode.Updated, recovery, "Connecting to mail provider");

            var mail = new MailHelper(MailProvider.Gmail);

            if (!mail.Connect
                    (recovery.MasterEmail ?? recovery.Email, recovery.EmailPassword))
            {
                StatusUpdate(ServiceStatusCode.Updated, recovery, "Failed to connect to mail provider");
                return(false);
            }

            StatusUpdate
                (ServiceStatusCode.Updated, recovery, "Searching for activation mail");

            var messageContent = string.Empty;

            for (int i = 0; i < 30; i++)
            {
                messageContent = mail.FindMailBySubjToHtml("Reset your Jagex password", requestTime);
                if (messageContent != string.Empty)
                {
                    break;
                }

                Thread.Sleep(5 * 1000);
            }

            if (messageContent == string.Empty)
            {
                StatusUpdate(ServiceStatusCode.Updated, recovery, "Unable to find recovery mail");
                return(false);
            }

            var resetPassUrl = GetResetPassUrl(messageContent);

            if (resetPassUrl == string.Empty)
            {
                StatusUpdate(ServiceStatusCode.Updated, recovery, "Error obtaining Password Reset link from email");
                return(false);
            }

            var passResetRequest = await rsHelper.GetRequest(resetPassUrl);

            if (passResetRequest.response == null)
            {
                StatusUpdate(ServiceStatusCode.Updated, recovery, "Error obtaining Password Reset page");
                return(false);
            }

            var passResetPage = passResetRequest.response.RequestMessage.RequestUri;
            var accountId     = GetAccountId(passResetPage.AbsoluteUri);

            recovery.AccountId     = accountId;
            recovery.RequestUrl    = passResetPage.AbsoluteUri;
            recovery.RecoveryStage = AccRecoveryStage.Complete;

            response = await rsHelper.PostRequest(recovery);

            return(response.Contains("Successfully set a new password and completed the process"));
        }
Exemplo n.º 2
0
        public static async Task LoadPriceLists()
        {
            ProvidersSection providersSection = (ProvidersSection)ConfigurationManager.GetSection("PricelistProviders");
            MailBoxSection   mailSection      = (MailBoxSection)ConfigurationManager.GetSection("MailConfig");

            var mailBox = mailSection.MailBoxes.Count > 1
                ? throw new ConfigurationErrorsException("Указано более одного почтового ящика")
                : mailSection.MailBoxes[0];


            System.Console.WriteLine("Чтение прайс листов с электронной  почты.");
            System.Console.WriteLine("Сисок постащиков.");
            foreach (ProviderElement provider in providersSection.Providers)
            {
                System.Console.WriteLine(provider.Name);
            }
            System.Console.WriteLine($"Адрес почтового сервера: {mailBox.ServerUrl}");

            var mailBoxOptions = new MailBoxOptions();

            FillUserCredentials(mailBoxOptions);
            mailBoxOptions.Port          = mailBox.Port;
            mailBoxOptions.ImapServerUrl = mailBox.ServerUrl;

            Action <ProgressOptions> progressOptionsFunc = progressOptions => System.Console.WriteLine(progressOptions.Message);

            using (var mailHelper = new MailHelper(mailBoxOptions))
            {
                var i         = 0;
                var connected = false;
                for (; i < 3 && !connected; i++)
                {
                    try
                    {
                        await mailHelper.Connect(new Progress <ProgressOptions>(progressOptionsFunc));

                        connected = true;
                    }
                    catch (MailAuthenticationException e)
                    {
                        System.Console.WriteLine(e.Message);
                        FillUserCredentials(mailHelper.MailOptions);
                    }
                }
                if (!connected)
                {
                    throw new ApplicationException("Превышен лимит попыток подключений");
                }

                var dbh = new DbHelper();

                await dbh.ClearPriceListsTable(new Progress <ProgressOptions>(progressOptionsFunc));

                List <Task <List <PriceItem> > > getMessagesTasks = new List <Task <List <PriceItem> > >();

                foreach (ProviderElement providersSectionProvider in providersSection.Providers)
                {
                    var progress = new Progress <ProgressOptions>(progressOptionsFunc);
                    ;
                    getMessagesTasks.Add(mailHelper.GetMessages(new ProviderOptions
                    {
                        Name = providersSectionProvider.Name,
                        ColumnDefinitions = providersSectionProvider.ToDictionary()
                    }, progress));
                }

                await Task.WhenAll(getMessagesTasks).ContinueWith(_ =>
                {
                    foreach (var messagesTask in getMessagesTasks)
                    {
                        dbh.WritePriceLists(messagesTask.Result, new Progress <ProgressOptions>(progressOptionsFunc));
                    }
                });
            }
        }