Ejemplo 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;
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo 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;
            }
        }
Ejemplo 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;
        }