Пример #1
0
        private void HandleUnlock(RSRecoveryForm recovery)
        {
            var account = MainWindow.GetAccountsHandler().FirstOrDefault
                              (x => x.Username == recovery.Email);

            if (account != null)
            {
                account.Password = recovery.NewPassword;
                DataProvider.SaveAccount(account);
            }

            Invoke(() =>
            {
                var item = unlocksListItems.FirstOrDefault(x => x.Email == recovery.Email);
                if (item != null)
                {
                    unlocksListItems.Remove(item);
                }
            });
        }
Пример #2
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"));
        }