Beispiel #1
0
        /// <summary>
        /// Try to connect to the provided server URL
        /// </summary>
        /// <param name="newserv"></param>
        /// <returns>a structure to represent the results of this action</returns>
        public static AboutResultReport TryChangeServerURL(string newserv)
        {
            string oldserv = BaseWS.Server;

            AboutResultReport res = new AboutResultReport();

            res.newServer = newserv;
            res.oldServer = oldserv;

            if (newserv != oldserv) // we have changed something
            {
                // Ping the new server, if unreacheable display message
                if (WebConnector.Current.PingS2CServer(newserv + WebConnector.PING_URL))
                {
                    // test the login: if not successful, logout the user and display the window
                    BaseWS.Server = newserv;
                    UserWS usRepo   = new UserWS();
                    User   currUser = usRepo.LoginUser(BaseWS.Username, BaseWS.Password);
                    res.currentUser = currUser;
                }
                else
                {
                    // network down / invalid server
                    res.error = "The server inserted is unreacheable now!";
                }
            }

            return(res);
        }
Beispiel #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);
            }
        }
Beispiel #3
0
        // This method is called by the timer delegate.
        public void RecallLogin(Object stateInfo)
        {
            log.DebugFormat("Calling Login from Poller; LoginRefreshTimeSec={0}", AppConfig.Current.LoginRefreshTimeSec);
            User user = null;

            if (useOneAll)
            {
                user = m_userRepo.LoginUserOneAll(identToken);
            }
            else
            {
                user = m_userRepo.LoginUser(username, password);
            }

            log.DebugFormat("Called Login from Poller: user is {0}", user.PrintNull());
            if ((user != null) && user.IsValid && (user.ID > 0))
            {
                pluginManager.DisplayLoggedInButtons();
            }
            else
            {
                pluginManager.DisplayLoggedOutButtons();
            }
        }