示例#1
0
 private void NavigateToMainPage(UserAccount account)
 {
     if (account != null)
         App.CurrentAccount = account;
     
     this.NavigationService.Navigate(new Uri("/PivotView.xaml", UriKind.RelativeOrAbsolute));
 }
示例#2
0
        public UserAccount LoadCurrentUser(ISettingsModel settings)
        {
            string currentUser = settings.GetValueOrDefault<string>("currentUser", string.Empty);
            UserAccount currentAccount = this.Accounts.SingleOrDefault(item => item.Username.Equals(currentUser));
            if (currentAccount == null)
                currentAccount = new UserAccount();

            return currentAccount;
        }
示例#3
0
 public void SaveChanges(UserAccount account, ISettingsModel settings)
 {
     if (!isLoggedOut && !string.IsNullOrEmpty(account.Username))
     {
         settings.AddOrUpdate("currentUser", account.Username);
         settings.SaveSettings();
         this.SubmitChanges();
     }
 }
示例#4
0
        /// <summary>
        /// Authenticate with the SomethingAwful forums.
        /// </summary>
        /// <param name="username">the account's username.</param>
        /// <param name="password">the account's password.</param>
        /// <returns>On success, a UserAccount object with the user's privledges.</returns>
        /// <exception cref="Exception"></exception>
        public async Task<UserAccount> LoginAsync(string username, string password)
        {
            ForumAccessToken token = await AwfulWebClient.AuthenticateAsync(username, password);
            
            // find out if we already have an account under that username
            UserAccount selected = this.Accounts.SingleOrDefault(item => item.Username.Equals(username));
            if (selected == null)
            {
                selected = new UserAccount();
                this.Accounts.InsertOnSubmit(selected);
            }

            // update selected with token data
            selected.Update(token);
            // save changes
            SaveChanges(selected, SettingsModelFactory.GetSettingsModel());

            return selected;
        }
示例#5
0
        public async Task<UserAccount> LoadCurrentUser(ISettingsModel settings)
        {
            string currentUser = settings.GetValueOrDefault<string>("currentUser", string.Empty);
            UserAccount currentAccount = UserAccounts
                .Where(item => item.Username.Equals(currentUser))
                .SingleOrDefault();

            if (currentAccount == null)
            {
                // return an anonymous, public user.
                settings.AddOrUpdate("currentUser", string.Empty);
                settings.SaveSettings();
                currentAccount = new UserAccount();
            }
            else
            {
                // attach tokens and favorites
                currentAccount = await AttachAssociationsAsync(currentAccount);

                if (!currentAccount.AsForumAccessToken().IsActiveAccount)
                {
                    settings.AddOrUpdate("currentUser", string.Empty);
                    settings.SaveSettings();
                }
            }

            return currentAccount;
        }
示例#6
0
 public async Task SaveChangesAsync(UserAccount account, ISettingsModel settings)
 {
     if (!isLoggedOut && !string.IsNullOrEmpty(account.Username))
     {
         settings.AddOrUpdate("currentUser", account.Username);
         settings.SaveSettings();
         await StorageModelFactory.GetStorageModel().SaveToStorageAsync(ConnectionString, this);
     }
 }
示例#7
0
        /// <summary>
        /// Authenticate with the SomethingAwful forums.
        /// </summary>
        /// <param name="username">the account's username.</param>
        /// <param name="password">the account's password.</param>
        /// <returns>On success, a UserAccount object with the user's privledges.</returns>
        /// <exception cref="Exception"></exception>
        public async Task<UserAccount> LoginAsync(string username, string password)
        {
            ForumAccessToken token = await AwfulWebClient.AuthenticateAsync(username, password);

            // find out if we already have an account under that username
            UserAccount selected = UserAccounts
                .Where(item => item.Username.Equals(username))
                .SingleOrDefault();

            if (selected == null)
            {
                selected = new UserAccount();
                selected = await AttachAssociationsAsync(selected);
                selected.Update(token);
                UserAccounts.Add(selected);
            }
            else
            {
                // update selected with token data
                selected = await AttachAssociationsAsync(selected);
                selected.Update(token);
                
            }

            // save changes
            await SaveChangesAsync(selected, SettingsModelFactory.GetSettingsModel());

            return selected;
        }
示例#8
0
        private void OnAccountUserFavoritesChanged(UserAccount account, NotifyCollectionChangedEventArgs args)
        {
            List<UserFavorite> toAdd = new List<UserFavorite>();
            List<UserFavorite> toRemove = new List<UserFavorite>();
            switch (args.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    foreach (var item in args.NewItems)
                    {
                        var userFavorite = item as UserFavorite;
                        userFavorite.Fk_UserAccountId = account.UserAccountId;
                        toAdd.Add(userFavorite);
                    }
                    break;

                case NotifyCollectionChangedAction.Remove:
                    foreach (var item in args.OldItems)
                    {
                        var userFavorite = item as UserFavorite;
                        userFavorite.Fk_UserAccountId = "-1";
                        toRemove.Add(userFavorite);
                    }
                    break;
            }

            foreach (var item in toAdd)
                UserFavorites.Add(item);

            foreach (var item in toRemove)
                UserFavorites.Remove(item);
        }
示例#9
0
        private void OnAccountUserTokensChanged(UserAccount account, NotifyCollectionChangedEventArgs args)
        {
            List<UserToken> toAdd = new List<UserToken>();
            List<UserToken> toRemove = new List<UserToken>();
            switch (args.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    foreach (var item in args.NewItems)
                    {
                        var userToken = item as UserToken;
                        userToken.Fk_UserAccountId = account.UserAccountId;
                        toAdd.Add(userToken);
                    }
                    break;

                case NotifyCollectionChangedAction.Remove:
                    foreach (var item in args.OldItems)
                    {
                        var userToken = item as UserToken;
                        userToken.Fk_UserAccountId = "-1";
                        toRemove.Add(userToken);
                    }
                    break;
            }

            UserTokens.AddRange(toAdd);
            UserTokens.RemoveAll(item => toRemove.Contains(item));

            //return StorageModelFactory.GetStorageModel().SaveToStorageAsync(ConnectionString, this);
        }
示例#10
0
        private Task<UserAccount> AttachAssociationsAsync(UserAccount account)
        {
            var favorites = UserFavorites
                .Where(item => item.Fk_UserAccountId.Equals(account.UserAccountId))
                .ToList();

            var tokens = UserTokens
                .Where(item => item.Fk_UserAccountId.Equals(account.UserAccountId))
                .ToList();

            var accountFavorites = new ObservableCollection<UserFavorite>(favorites);
            accountFavorites.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) => { OnAccountUserFavoritesChanged(account, e); });
            account.UserFavorites = accountFavorites;
            var accountTokens = new ObservableCollection<UserToken>(tokens);
            accountTokens.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) => { OnAccountUserTokensChanged(account, e); });
            account.UserTokens = accountTokens;

            TaskCompletionSource<UserAccount> tcs = new TaskCompletionSource<UserAccount>();
            tcs.SetResult(account);
            return tcs.Task;
        }
示例#11
0
        /// <summary>
        /// Callback if the user sign in process failed.
        /// </summary>
        private void OnSignInSuccess(UserAccount account)
        {
            if (account != null)
                App.CurrentAccount = account;

            // for now, just navigate to the home page. we'll add more customization later.
            this.Frame.Navigate(typeof(ClassicPage), string.Empty);
        }
示例#12
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {

#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            if (CurrentAccount == null)
            {
                CurrentAccount = await UserContext.LoadCurrentUser(SettingsModelFactory.GetSettingsModel());
                ThreadDataGroup.PinChanged += (o, a) =>
                    {
                        var thread = o as ThreadDataGroup;
                        if (thread.IsPinned)
                            CurrentAccount.AddFavorite(thread);
                        else
                            CurrentAccount.RemoveFavorite(thread);
                    };
            }

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Load a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                // Set the default language
                rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                //rootFrame.Navigate(typeof(MainPage), e.Arguments);

                // should we go to the login page, or our start page?
                Func<bool> navToLogin = new Func<bool>(() => { return rootFrame.Navigate(typeof(MainPage), string.Empty); });
                Func<bool> navToHome = new Func<bool>(() => { return rootFrame.Navigate(typeof(ClassicPage), string.Empty); });
                Func<bool> nav = SignInDataModel.IsSignedIn() ? navToHome : navToLogin;
                nav();
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }