Example #1
0
        public OAuthToken GetOAuth()
        {
            var localSettings = ApplicationData.Current.LocalSettings;
            OAuthToken o = new OAuthToken();
            ImgurUser u = new ImgurUser();

            try {
                u.Bio = (string)localSettings.Values["User_Bio"];
                u.Created = (int)localSettings.Values["User_Created"];
                u.Id = (int)localSettings.Values["User_Id"];
                u.Pro = (int)localSettings.Values["User_Pro"];
                u.Rep = (float)localSettings.Values["User_Rep"];
                u.Url = (string)localSettings.Values["User_Url"];
                o.Authenticated = (bool)localSettings.Values["Authenticated"];
                o.Expires = DateTime.FromBinary((long)localSettings.Values["Expires"]);
                o.RefreshToken = (string)localSettings.Values["RefreshToken"];
                o.Token = (string)localSettings.Values["Token"];
                o.User = u;

                BuisnessLayer.BLImgurAPI bl = new BuisnessLayer.BLImgurAPI();
                u = bl.logIn(u.Url, o.Token);
                o.User = u;
            }
            catch
            {
                o = new OAuthToken();
                u = new ImgurUser();
                o.User = u;
            }

            return o;
        }
Example #2
0
        public void StoreOAuth(OAuthToken OAuth)
        {
            var localSettings = ApplicationData.Current.LocalSettings;
            localSettings.Values["Authenticated"] = OAuth.Authenticated;
            localSettings.Values["Expires"] = OAuth.Expires.ToBinary();
            localSettings.Values["RefreshToken"] = OAuth.RefreshToken;
            localSettings.Values["Token"] = OAuth.Token;
            localSettings.Values["User_Bio"] = OAuth.User.Bio;
            localSettings.Values["User_Created"] = OAuth.User.Created;
            localSettings.Values["User_Id"] = OAuth.User.Id;
            localSettings.Values["User_Pro"] = OAuth.User.Pro;
            localSettings.Values["User_Rep"] = OAuth.User.Rep;
            localSettings.Values["User_Url"] = OAuth.User.Url;
            

        }
Example #3
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            MenuAnimationOpen.Begin();
            //Get Locally stored OAuth token
            DataLayer.Settings settings = new DataLayer.Settings();
            //settings.ClearOAuth();
            oat = settings.GetOAuth();         

            if (oat.Authenticated)
            {
                //refresh OAuth Token if it's about to expire or is expired
                if(oat.Expires>=DateTime.Now.AddDays(-7))
                { 
                    BuisnessLayer.BLImgurAPI bl = new BuisnessLayer.BLImgurAPI();
                    oat=bl.RefreshOAuth(oat);
                }
                txtUsername.Text = "\n" + oat.User.Url;
            }
        }