/// <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; }
/// <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; }
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; } }
private void bgw_DoWork(object sender, DoWorkEventArgs e) { e.Result = string.Empty; int? userId = e.Argument as int?; if (userId != null) { // read channels UserWS userRepo = new UserWS(); List<Group> chList = userRepo.GetChannelsOfUser((int)userId) as List<Group>; if (chList != null) chList.Sort(channelSorter); SnippetsWS snipRepo = new SnippetsWS(); lock (selectedChList) // we don't want that someone is updating this while we read it and vice-versa { selectedChList = snipRepo.GetChannels(this.SnippetId); if (chList != null) { // populate the control foreach (Group c in chList) { // if the snippet is already published on the channel, mark it as selected bool sel = false; if (selectedChList != null) { foreach (int cs in selectedChList) { if (c.ID == cs) { sel = true; break; } } } // populate the control listChannelWiew.Invoke(new Action(() => addItemToList(c.Name, c.ID, sel))); } } } if ((chList == null) || (chList.Count == 0)) e.Result = Properties.Resources.PublishNoChannelFollowed; } else { e.Result = Properties.Resources.ErrorCodes_UNKNOWN; } }