Exemplo n.º 1
0
        /// <summary>
        /// Performs all the operations needed to init the plugin/App
        /// </summary>
        /// <param name="user">singleton instance of UserPlugin</param>
        /// <param name="rootPath">path where the config files can be found</param>
        /// <returns>true if the user is already logged in; false if still logged out</returns>
        public static bool InitApp(UserClient user, string rootPath, IPluginManager pluginManager)
        {
            if (user == null)
                return false;

            // initialize the config file
            Snip2Code.Utils.AppConfig.Current.Initialize(rootPath);
            log = LogManager.GetLogger("ClientUtils");
 
            // login the user
            bool res = user.RetrieveUserPreferences();
            bool loggedIn = false;
            if (res && ((!BaseWS.Username.IsNullOrWhiteSpaceOrEOF()) || (!BaseWS.IdentToken.IsNullOrWhiteSpaceOrEOF())))
            {
                LoginPoller poller = new LoginPoller(BaseWS.Username, BaseWS.Password, BaseWS.IdentToken, BaseWS.UseOneAll,
                                                        pluginManager);
                LoginTimer = new System.Threading.Timer(poller.RecallLogin, null, 0, AppConfig.Current.LoginRefreshTimeSec * 1000);
                loggedIn = true;
            }

            System.Threading.ThreadPool.QueueUserWorkItem(delegate
            {
                user.LoadSearchHistoryFromFile();
            }, null);

            //set the empty profile picture for search list results:
            PictureManager.SetEmptyProfilePic(rootPath);

            return loggedIn;
        }
Exemplo n.º 2
0
        private static void DoLogout(UserClient user)
        {
            log.Debug("Logging out current user...");
            // deletes the stored credentials
            BaseWS.Logout();
            if (user != null)
                user.SaveUserPreferences();

            // disconnect the user and stop the periodic login thread
            WebConnector.Current.Logout();
            if (LoginTimer != null)
                LoginTimer.Dispose();
            log.Debug("Logout completed!");
        }
Exemplo n.º 3
0
        /////////////////////////////////////////////////////////////////////////////////

        #region Logout Actions
        /////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Performs the logout action for the current user
        /// </summary>
        /// <param name="pluginManager"></param>
        /// <param name="user"></param>
        public static void LogoutUser(IPluginManager pluginManager, UserClient user)
        {
            System.Threading.Thread th = new System.Threading.Thread(
                new System.Threading.ThreadStart(delegate { DoLogout(user); })
            );
            th.Start();

            // change the buttons 
            pluginManager.DisplayLoggedOutButtons();

            // clean up previous search contents (privacy concern)
            ISearchSnippetForm searchForm = pluginManager.FindWindow<ISearchSnippetForm>();
            if (searchForm != null)
                searchForm.DisplayCleanForm();

            // clean up previous publish info
            IPublishSnippetForm publishForm = pluginManager.FindWindow<IPublishSnippetForm>();
            if (publishForm != null)
                publishForm.ResetResults();

            // close publish window
            pluginManager.ClosePublishSnippetWindow();

            // close addSnippet Window
            pluginManager.CloseAddSnippetWindow();

            // cleanup previous login from login page
            ILoginForm loginForm = pluginManager.FindWindow<ILoginForm>();
            if (loginForm != null)
                loginForm.ResetFields();

            // show login page 
            PrepareLoginForm(pluginManager);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Do all the actions needed when a wrong login is detected after changing the server URL
        /// from About form
        /// </summary>
        /// <param name="pluginManager"></param>
        /// <param name="user"></param>
        /// <param name="oldServer">previous URL of the server</param>
        /// <param name="newServer">new URL of the server</param>
        public static void ManageInvalidLoginOnNewServerFromAbout(IPluginManager pluginManager, UserClient user,
            string oldServer, string newServer)
        {
            // change the visibility of buttons of top menu and right-click
            BaseWS.Server = oldServer;    // this is needed to logout the old session on the old server
            LogoutUser(pluginManager, user);
            BaseWS.Server = newServer;    // from now on, go ahead with the new server
            // save new server path
            user.SaveUserPreferences();

            // update the login page to address the one-all form to the new server
            LoginPageCleanup(pluginManager);
        }
Exemplo n.º 5
0
        public static ErrorCodes TryLoginOneAll(UserClient user, IPluginManager pluginManager)
        {
            UserWS repoUser = new UserWS();
            string identToken = BaseWS.IdentToken;
            Snip2Code.Model.Entities.User loggedUser = repoUser.LoginUserOneAll(identToken);

            if ((loggedUser != null) && (loggedUser.ID > 0))
            {
                // Save credentials
                BaseWS.Username = string.Empty;
                BaseWS.Password = string.Empty;
                user.SaveUserPreferences();

                // change the logged user on the package
                LoginPoller poller = new LoginPoller(string.Empty, string.Empty, identToken, true, pluginManager);
                if (ClientUtils.LoginTimer != null)
                    ClientUtils.LoginTimer.Dispose();
                ClientUtils.LoginTimer = new System.Threading.Timer(poller.RecallLogin, null, 0, AppConfig.Current.LoginRefreshTimeSec * 1000);

                return ErrorCodes.OK;
            }
            else
            {
                // something went wrong on the login: reload the oneAllPage
                BaseWS.IdentToken = string.Empty;

                if (repoUser.LastErrorCode == ErrorCodes.OK)
                    return ErrorCodes.NOT_LOGGED_IN;
                else
                    return repoUser.LastErrorCode;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Try to login into the remote erver with the given credentials
        /// </summary>
        /// <param name="user"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>true if the login has been successful; false otherwise</returns>
        public static ErrorCodes TryLogin(UserClient user, string username, string password, IPluginManager pluginManager)
        {
            // Test login
            UserWS repoUser = new UserWS();
            Snip2Code.Model.Entities.User loggedUser = repoUser.LoginUser(username, password);

            if ((loggedUser != null) && (loggedUser.ID > 0))
            {
                // Save credentials
                BaseWS.Username = username;
                BaseWS.Password = password;
                BaseWS.IdentToken = string.Empty;
                user.SaveUserPreferences();

                // change the logged user on the package
                LoginPoller poller = new LoginPoller(username, password, string.Empty, false, pluginManager);
                if (ClientUtils.LoginTimer != null)
                    ClientUtils.LoginTimer.Dispose();
                ClientUtils.LoginTimer = new System.Threading.Timer(poller.RecallLogin, null, 0, AppConfig.Current.LoginRefreshTimeSec * 1000);
                return ErrorCodes.OK;
            }

            if (repoUser.LastErrorCode == ErrorCodes.OK)
                return ErrorCodes.NOT_LOGGED_IN;
            else
                return repoUser.LastErrorCode;
        }