Example #1
0
        /// <summary>
        /// Method used to sign in account for passing of retrieved sign in cookies (used for puid-based-auth)
        /// </summary>
        /// <param name="email">string email address</param>
        /// <param name="password">string password</param>
        /// <returns>CookieContainer object including all cookies created during account authentication</returns>
        private static CookieContainer LoginAccount(string email, string password)
        {
            CookieContainer cookieJar = null;
            Uri             ppURL     = Helper.PassportURL;
            Uri             ppRU      = Helper.PassportRU;

            string siteID     = Helper.SiteId.ToString();
            bool   getCookies = true;

            try
            {
                Logger.AddComment("PP URL: " + ppURL.ToString(), Logger.CommentType.Message);
                Logger.AddComment("PP RU URL: " + ppRU.ToString(), Logger.CommentType.Message);
                Logger.AddComment("Site ID: " + siteID, Logger.CommentType.Message);
                Logger.AddComment("Email: " + email, Logger.CommentType.Message);
                Logger.AddComment("Password: "******"User authenticated sucessfully.", Logger.CommentType.Message);
            }

            return(cookieJar);
        }
Example #2
0
        /// <summary>
        /// Method used authenticate user and get cookie and authenticate ticket.
        /// </summary>
        /// <returns>Authentication ticket.</returns>
        private string AuthenticateUser()
        {
            string authTicket = string.Empty;
            string loginUrl   = string.Empty;
            string cid        = string.Empty;

            Logger.AddComment(PhotomailMessages.TextEmail + this.objHelper.UserEmailAddress, Logger.CommentType.Message);
            Logger.AddComment(PhotomailMessages.TextPassword + this.objHelper.UserPassword, Logger.CommentType.Message);

            if (string.IsNullOrEmpty(this.objHelper.EnvNode[PhotomailMessages.TextPassportServer]))
            {
                Logger.AddComment(PhotomailMessages.TextPassportServer + PhotomailMessages.MsgMissingValue, Logger.CommentType.Error);
                throw new PhotomailException(PhotomailMessages.TextPassportServer + PhotomailMessages.MsgMissingValue);
            }
            else
            {
                loginUrl = "https://" + this.objHelper.EnvNode[PhotomailMessages.TextPassportServer] + "/ppsecure/clientpost.srf";
                Logger.AddComment(PhotomailMessages.TextPassportServer + ": " + this.objHelper.EnvNode[PhotomailMessages.TextPassportServer], Logger.CommentType.Message);
            }

            if (string.IsNullOrEmpty(this.objHelper.EnvNode[PhotomailMessages.TextSiteId]))
            {
                Logger.AddComment(PhotomailMessages.TextSiteId + PhotomailMessages.MsgMissingValue, Logger.CommentType.Error);
                throw new PhotomailException(PhotomailMessages.TextSiteId + PhotomailMessages.MsgMissingValue);
            }
            else
            {
                loginUrl += "?id=" + this.objHelper.EnvNode[PhotomailMessages.TextSiteId];
            }

            if (string.IsNullOrEmpty(this.objHelper.EnvNode[PhotomailMessages.TextPassportRU]))
            {
                Logger.AddComment(PhotomailMessages.TextPassportRU + PhotomailMessages.MsgMissingValue, Logger.CommentType.Error);
                throw new PhotomailException(PhotomailMessages.TextPassportRU + PhotomailMessages.MsgMissingValue);
            }
            else
            {
                loginUrl += "&ru=" + this.objHelper.EnvNode[PhotomailMessages.TextPassportRU];
                Logger.AddComment(PhotomailMessages.TextPassportRU + ": " + this.objHelper.EnvNode[PhotomailMessages.TextPassportRU], Logger.CommentType.Message);
            }

            loginUrl += "&wp=MBI";

            string loginData = string.Format(loginDataTemplate, this.objHelper.EnvNode[PhotomailMessages.TextUserEmailAddress], this.objHelper.EnvNode[PhotomailMessages.TextUserPassword]);

            try
            {
                this.objHelper.CookieJar = PCLogin.XmlLogOnReturnCookieContainer(this.objHelper.UserEmailAddress, this.objHelper.UserPassword, new Uri("https://" + this.objHelper.EnvNode[PhotomailMessages.TextPassportServer]), new Uri(this.objHelper.EnvNode[PhotomailMessages.TextPassportRU]), this.objHelper.EnvNode[PhotomailMessages.TextSiteId], string.Empty, HelperClass.ProxyAddress, HelperClass.Port.ToString());

                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(loginUrl));
                request.Method            = "POST";
                request.ContentLength     = loginData.Length;
                request.ContentType       = "text/xml";
                request.Accept            = "application/atom+xml";
                request.UserAgent         = @"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 5.0) [MSN Photos Upload Tool]";
                request.AllowAutoRedirect = false;
                using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                {
                    writer.Write(loginData);
                    writer.Flush();
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                        {
                            // get XML response
                            XmlDocument loginResponseXml = new XmlDocument();
                            loginResponseXml.LoadXml(reader.ReadToEnd());
                            XmlNode redirectNode = loginResponseXml.SelectSingleNode("LoginResponse/Redirect");
                            if (redirectNode != null)
                            {
                                string redirect = redirectNode.InnerText;
                                int    start    = redirect.IndexOf("&t=");
                                authTicket = redirect.Substring(start + 1);
                                this.objHelper.AuthenticationTicket = authTicket;

                                this.objHelper.CID = this.GetCIDFromCookies(response.Headers["Set-Cookie"]);

                                if (this.objHelper.CID == string.Empty)
                                {
                                    throw new PhotomailException(string.Format(PhotomailMessages.MsgFormat_FailForUse + PhotomailMessages.MsgPromptEmptyCID, this.objHelper.EnvNode[PhotomailMessages.TextUserEmailAddress]));
                                }

                                if (string.IsNullOrEmpty(authTicket))
                                {
                                    throw new PhotomailException(string.Format(PhotomailMessages.MsgFormat_FailForUse + PhotomailMessages.MsgPromptEmptyAuthTicket, this.objHelper.EnvNode[PhotomailMessages.TextUserEmailAddress]));
                                }

                                this.objHelper.InCIDUser = Int64.Parse(this.objHelper.CID, System.Globalization.NumberStyles.HexNumber).ToString();

                                Logger.AddComment(PhotomailMessages.TextUserAuthentication + PhotomailMessages.MsgPass, Logger.CommentType.Message);
                                Logger.AddComment(string.Empty, Logger.CommentType.Pass);
                            }
                        }
                    }
                }
            }
            catch (WebException we)
            {
                throw new PhotomailException(we.Message);
            }
            catch (Exception ex)
            {
                throw new PhotomailException(ex.Message);
            }

            return(authTicket);
        }