Ejemplo n.º 1
0
        void YahooLoginStatus_Load(object sender, EventArgs e)
        {
            YahooSession yahooSession = YahooAuthenticationProvider.Instance.LoadSession();

            yahooSession.StatusChanged += new EventHandler(yahooSession_StatusChanged);
            UpdateButtons();
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        YahooSession yahooSession = YahooAuthenticationProvider.Instance.LoadSession();

        if (yahooSession.IsAuthenticated)
        {
            try
            {
                DataSet dsServices;
                dsServices = yahooSession.GetService(new Uri(YahooServiceUrl));

                foreach (DataTable dt in dsServices.Tables)
                {
                    Label label = new Label();
                    label.Text = dt.TableName;
                    GridView gv = new GridView();
                    gv.ID         = dt.TableName + "GridView";
                    gv.DataSource = dt;
                    gv.DataBind();
                    Panel1.Controls.Add(label);
                    Panel1.Controls.Add(gv);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Failure with photos url: " + YahooServiceUrl, ex);
            }
        }
    }
        public void ClearSession()
        {
            YahooSession yahooSession = LoadSession();

            yahooSession.ClearAuthentication();
            SaveSession(yahooSession);
        }
Ejemplo n.º 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        YahooSession yahooSession = YahooAuthenticationProvider.Instance.LoadSession();

        if (yahooSession.IsAuthenticated)
        {
            string url = "http://photos.yahooapis.com/V3.0/listPhotos";

            DataSet dsServices;
            dsServices = yahooSession.GetService(new Uri(url));

            dlPhotos.DataSource = dsServices.Tables["Image"];
            dlPhotos.DataBind();

            //foreach (DataRow row in dsServices.Tables["Image"].Rows)
            //{
            //    if ("thumb".Equals(row["type"]))
            //    {
            //        int width;
            //        int height;
            //        int.TryParse(row["Width"].ToString(), out width);
            //        int.TryParse(row["Height"].ToString(), out height);
            //        Image img = new Image();
            //        img.ID = "img_" + row["ImageList_Id"];
            //        img.Width = width;
            //        img.Height= height;
            //        img.AlternateText = "";
            //        img.ImageUrl = row["Image_Text"].ToString();
            //        Panel1.Controls.Add(img);
            //        Panel1.Controls.Add(new LiteralControl("<br />\n"));
            //    }
            //}
        }
    }
Ejemplo n.º 5
0
        private void UpdateButtons()
        {
            YahooSession yahooSession = YahooAuthenticationProvider.Instance.LoadSession();

            if (yahooSession.IsAuthenticated)
            {
                loginButton.Visible  = false;
                logoutButton.Visible = true;
            }
            else
            {
                loginButton.Visible  = true;
                logoutButton.Visible = false;
            }
        }
        public override void SaveSession(YahooSession yahooSession)
        {
            if (HttpContext.Current.Session != null &&
                HttpContext.Current.Session["YahooSession"] == null)
            {
                HttpContext.Current.Session["YahooSession"] = yahooSession;
            }

            // protected against concurrency
            lock (padLock)
            {
                DataSet authenticationState = LoadAuthenticationState();
                if (authenticationState == null)
                {
                    authenticationState = CreateAuthenticationState();
                }

                DataRow row = GetYahooSessionRow(authenticationState);
                if (row == null)
                {
                    DataRow dRow = authenticationState.Tables[YahooSessionsTable].NewRow();
                    dRow["UserID"]          = UserID;
                    dRow["ApplicationID"]   = yahooSession.ApplicationId;
                    dRow["Token"]           = yahooSession.Token;
                    dRow["ApplicationData"] = yahooSession.ApplicationData;
                    dRow["LoginDate"]       = yahooSession.LoginDate;
                    dRow["ValidUntil"]      = yahooSession.ValidUntil;
                    dRow["CreationDate"]    = DateTime.Now;
                    dRow["ModifiedDate"]    = DateTime.Now;
                    authenticationState.Tables[YahooSessionsTable].Rows.Add(dRow);
                }
                else
                {
                    row["ApplicationID"]   = yahooSession.ApplicationId;
                    row["Token"]           = yahooSession.Token;
                    row["ApplicationData"] = yahooSession.ApplicationData;
                    row["LoginDate"]       = yahooSession.LoginDate;
                    row["ValidUntil"]      = yahooSession.ValidUntil;
                    row["ModifiedDate"]    = DateTime.Now;
                }

                // write out changes
                StreamWriter xmlSW = new StreamWriter(AuthenticationStateFileName);
                authenticationState.WriteXml(xmlSW, XmlWriteMode.WriteSchema);
                xmlSW.Close();
            }
        }
Ejemplo n.º 7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        YahooSession yahooSession = YahooAuthenticationProvider.Instance.LoadSession();

        if (yahooSession.IsAuthenticated)
        {
            lblApplicationID.Text   = yahooSession.ApplicationId;
            lblToken.Text           = yahooSession.Token;
            lblLoginDateTime.Text   = yahooSession.LoginDate.ToString();
            lblTokenExpiration.Text = yahooSession.TokenExpiration.ToString();
            lblValidUntil.Text      = yahooSession.ValidUntil.ToString();
            lblDateTime.Text        = DateTime.Now.ToString();
            lblApplicationData.Text = Session["YahooApplicationData"] as String;

            foreach (String key in Session.Keys)
            {
                Logger.Info(String.Format("{0}: {1}", key, Session[key].ToString()));
            }
        }
    }
        public override YahooSession LoadSession()
        {
            YahooSession yahooSession = null;

            if (HttpContext.Current.Session != null &&
                HttpContext.Current.Session["YahooSession"] != null)
            {
                yahooSession = HttpContext.Current.Session["YahooSession"] as YahooSession;
            }

            // Load from XML when not found in the Session
            if (yahooSession == null)
            {
                yahooSession = new YahooSession();
                DataSet authenticationState = LoadAuthenticationState();
                if (authenticationState != null)
                {
                    DataRow row = GetYahooSessionRow(authenticationState);
                    if (row != null)
                    {
                        yahooSession.ApplicationId   = row["ApplicationId"] as String;
                        yahooSession.Token           = row["Token"] as String;
                        yahooSession.ApplicationData = row["ApplicationData"] as String;
                        yahooSession.LoginDate       = (DateTime)row["LoginDate"];
                        yahooSession.ValidUntil      = (DateTime)row["ValidUntil"];
                        if (yahooSession.ValidUntil > DateTime.Now &&
                            !String.IsNullOrEmpty(yahooSession.Token))
                        {
                            yahooSession.UpdateCredentials();
                        }
                        if (HttpContext.Current.Session != null)
                        {
                            HttpContext.Current.Session["YahooSession"] = yahooSession;
                        }
                    }
                }
            }

            return(yahooSession);
        }
Ejemplo n.º 9
0
        protected void loginButton_Click(object sender, EventArgs e)
        {
            CancelEventArgs args = new CancelEventArgs(false);

            OnLoggingIn(args);

            if (!args.Cancel)
            {
                YahooSession  yahooSession = YahooAuthenticationProvider.Instance.LoadSession();
                StringBuilder appData      = new StringBuilder();
                if (ApplicationData.Count > 0)
                {
                    foreach (string key in ApplicationData.Keys)
                    {
                        if (key.Contains("_") || key.Contains("."))
                        {
                            throw new InvalidDataException(
                                      "Application Data Key cannot contain periods or underscores: " +
                                      key);
                        }
                        if (ApplicationData[key].Contains("_") ||
                            ApplicationData[key].Contains("."))
                        {
                            throw new InvalidDataException(
                                      "Application Data Value cannot contain periods or underscores: " +
                                      ApplicationData[key]);
                        }
                        appData.Append(key);
                        appData.Append("_");
                        appData.Append(ApplicationData[key]);
                        appData.Append(".");
                    }
                    Logger.Debug("appData: " + appData.ToString());
                }
                string loginUrl = yahooSession.GetLoginUrl(appData.ToString());
                HttpContext.Current.Response.Redirect(loginUrl);
            }
        }
Ejemplo n.º 10
0
 public override void SaveSession(YahooSession yahooSession)
 {
     throw new NotImplementedException();
 }
 public abstract void SaveSession(YahooSession yahooSession);