/// <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); } }
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; } }
public void SubscribeThrowsErrorForNullCompany() { var _subscriptionWs = new SubscriptionWS(); var user = new UserWS() { id = "1" }; _subscriptionWs.paymentPlanId = "0"; _subscriptionWs.user = user; Assert.Throws <ArgumentNullException>(() => _appDirectApi.SubscribeUser(_subscriptionWs)); }
public void SubscribeUserNullWhenNotAuthenticated() { var _subscriptionWs = new SubscriptionWS(); var user = new UserWS() { id = "1" }; var company = new CompanyWS() { id = "2" }; _subscriptionWs.paymentPlanId = "0"; _subscriptionWs.user = user; _subscriptionWs.company = company; Assert.IsNull(_appDirectApi.SubscribeUser(_subscriptionWs)); }
public void Init() { _xmlSerializer = new XmlSerializer(typeof(SubscriptionWS)); _subscriptionWs = new SubscriptionWS(); var user = new UserWS() { id = "1" }; var company = new CompanyWS() { id = "2" }; _subscriptionWs.paymentPlanId = "0"; _subscriptionWs.user = user; _subscriptionWs.company = company; _serializedXml = SerializeToString(_subscriptionWs); }
public ActionResult Index(UserBE UserBE) { var db = new UserWS(); var UsuarioBe = db.ObtenerUsuario(UserBE.UserLogin); if (UsuarioBe == null) { ModelState.AddModelError("", "El Usuario no Existe"); return(View(UserBE)); } else if (UsuarioBe.UserPassword.Equals(UserBE.UserPassword)) { FormsAuthentication.SetAuthCookie(UserBE.UserLogin, true); Session["Usuario"] = UsuarioBe; return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Usuario o Contraseña Incorrectos"); return(View(UserBE)); } }
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); } } }
public static void Main(String[] args) { WebServicesSessionLocalService service = new WebServicesSessionLocalService(); NetworkCredential cre = new NetworkCredential(); cre.UserName = "******"; cre.Password = "******"; service.PreAuthenticate = true; service.Credentials = cre; // create a new user type customer UserWS newUser = new UserWS(); newUser.userName = "******"; newUser.password = "******"; newUser.currencyId = 1; // US Dollars newUser.languageId = 1; // English newUser.mainRoleId = 5; // Type Customer newUser.statusId = 1; // Status Active // add a contact (all fields optional) ContactWS contact = new ContactWS(); contact.email = "*****@*****.**"; contact.firstName = "John"; contact.lastName = "Smith"; contact.initial = "J."; contact.title = "Owner"; contact.countryCode = "US"; // two digits code (ISO-3166) contact.organizationName = "Trend Inc."; contact.address1 = "1234 Main St"; contact.address2 = "Suite 100"; contact.city = "Miami"; contact.stateProvince = "FL"; contact.postalCode = "12345"; contact.phoneCountryCode = 1; contact.phoneAreaCode = 800; contact.phoneNumber = "303-3030"; newUser.contact = contact; // add a credit card CreditCardDTO cc = new CreditCardDTO(); cc.name = "John J. Smith"; cc.number = "4111-1111 1111-1111 "; cc.expiry = DateTime.Now; newUser.creditCard = cc; Console.WriteLine("Creating new customer ... "); int newUserId = service.createUser(newUser); if (newUserId == 0) { Console.WriteLine("The user " + newUser.userName + " already exists in the system. Please select a new one"); return; } Console.WriteLine("New user id is " + newUserId); // fetch the user we have just created UserWS myUser = service.getUserWS(newUserId); // show some fields Console.WriteLine("my user name = " + myUser.contact.firstName + " " + myUser.contact.lastName); Console.WriteLine("my user credit card = " + myUser.creditCard.number); // Add a purchase order for my new user OrderWS newOrder = new OrderWS(); newOrder.userId = newUserId; newOrder.billingTypeId = 1; // pre-paid newOrder.period = 1; // one time newOrder.currencyId = 1; // US Dollars // now add some lines OrderLineWS[] lines = new OrderLineWS[2]; // This line will be using the information from the item lines[1] = new OrderLineWS(); lines[1].typeId = 1; // line with items lines[1].quantity = 1; lines[1].itemId = 307; lines[1].useItem = true; // this indicates that price, and description are those from the item // I put all the information manually by not setting the 'useItem' flag lines[0] = new OrderLineWS(); lines[0].price = 10; lines[0].typeId = 1; // line with items lines[0].quantity = 1; lines[0].amount = 10; // usually is price * quantity lines[0].description = "Monthly top banner subscription"; lines[0].itemId = 308; newOrder.orderLines = lines; Console.WriteLine("Creating new purchase order ... "); int newOrderId = service.createOrder(newOrder); Console.WriteLine("New order id is " + newOrderId); // get the latest purchase order of my user OrderWS latestOrder = service.getLatestOrder(newUserId); Console.WriteLine(latestOrder.id + " should be equal to " + newOrderId); /* * Mega call: Creates a user with a purchase order in one call. * Creates the user, the purchase order, generates an invoice and * process a payment in real-time. * Use this for the initial signup of a customer. * Future invoices/payments will be done automatically by the billing * process. */ // Delete the user so it can be recreated with a mega-call service.deleteUser(newUserId); // make the call Console.WriteLine("Now making a mega call ... "); CreateResponseWS result = service.create(myUser, newOrder); // show the results Console.WriteLine("new user= "******" new order= " + result.orderId + " new invoice= " + result.invoiceId + " new payment= " + result.paymentId + " payment result = " + result.paymentResult); // Clean up so this test can run again service.deleteUser(result.userId); Console.WriteLine("Done!"); }