public static ProviderAccount addProviderAccount(Providers providers) { JsonSerializer serialiser = new JsonSerializer(); serialiser.NullValueHandling = NullValueHandling.Ignore; Provider p = providers.getProvider()[0]; String providerJson = JsonConvert.SerializeObject(p.loginForm, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); providerJson = "{\"loginForm\":" + providerJson; providerJson = providerJson.Replace("\r\n", ""); // providerJson = providerJson.Replace(" ", ""); providerJson = providerJson + "}"; string aa = providerJson; Console.WriteLine(aa); String addSiteURL = LoginApp.localURLVer1 + "providers/providerAccounts?providerId=" + providers.getProvider()[0].getId(); List <string> headers = new List <string>(); string usersessionid = LoginApp.usession; string cbrandsessionid = LoginApp.cbsession; headers.Add("Authorization:{userSession= " + usersessionid + ",cobSession=" + cbrandsessionid + "}"); String jsonResponse = HTTP.doPost(addSiteURL, providerJson, headers); ProviderAccount providerAccount = (ProviderAccount)GSONParser.handleJson(jsonResponse, typeof(ProviderAccount)); return(providerAccount); }
public static ProviderAccount addNonMFA_Account(Providers providers) { Console.WriteLine(" Add Non_MFA_Account: "); Console.WriteLine("Enter your provider userName : "******"DBmet1.site16441.1";// providers.getProvider()[0].getLoginForm().getRow()[0].getField()[0].setValue(userName); Console.WriteLine("Enter provider password : "******"site16441.1";// providers.getProvider()[0].getLoginForm().getRow()[1].getField()[0].setValue(password); ProviderAccount providerAccount = AddProviderAccountNew.addProviderAccount(providers); string refMsg; ProviderAccount pAcnt; do { pAcnt = AddProviderAccountNew.getProviderAccount(providerAccount.providerAccount.id); refMsg = pAcnt.providerAccount.refreshInfo.status; Console.WriteLine("status" + refMsg + ", additionalStatus " + providerAccount.providerAccount.refreshInfo.additionalStatus); if (refMsg == "FAILED") { Console.WriteLine("login failed please try again" + refMsg); break; } } while (refMsg != "SUCCESS"); if (refMsg == "SUCCESS") { Console.WriteLine("Account added successfully"); } return(pAcnt); }
public ProviderAccount parseJSON(String json) { ProviderAccount providerAccount = JsonConvert.DeserializeObject <ProviderAccount>(json); //deserializing the values for Account app. // Accounts a = new Accounts(); // a.account = account; //return a; return(providerAccount); }
public static ProviderAccount getProviderAccount(String providerAccountId) { String getRefreshStatusURL = LoginApp.localURLVer1 + "providers/providerAccounts/" + providerAccountId.ToString(); List <string> headers = new List <string>(); string usersessionid = LoginApp.usession; string cbrandsessionid = LoginApp.cbsession; headers.Add("Authorization:{userSession= " + usersessionid + ",cobSession=" + cbrandsessionid + "}"); String jsonResponse = HTTP.doGet(getRefreshStatusURL, headers); // Console.WriteLine(jsonResponse); ProviderAccount providerAccount = (ProviderAccount)GSONParser.handleJson(jsonResponse, typeof(ProviderAccount)); return(providerAccount); }
/// <summary> /// Update a Provider's account on the database. /// </summary> /// <param name="providerAccount"></param> /// <returns></returns> public async Task <bool> UpdateProviderAccountAsync(ProviderAccount providerAccount) { var existingEntity = await _context.ProviderAccount.FirstOrDefaultAsync(p => p.ProviderId == providerAccount.ProviderId); if (existingEntity == null) { return(false); } var updatedEntity = _mapper.MapProvider(providerAccount); _context.Entry(existingEntity).CurrentValues.SetValues(updatedEntity); return(true); }
public ActionResult Edit(int providerAccId, int providerId, bool enable, FormCollection collection) { try { using (var ae = new AvtoritetEntities()) { ProviderAccount providerAcc = null; if (providerAccId == 0) { providerAcc = new ProviderAccount { Uri = collection["Uri"], Login = collection["Login"], Password = collection["Password"], ProviderId = providerId, Enable = enable, Order = !string.IsNullOrEmpty(collection["order"]) ? int.Parse(collection["order"]) : 0 }; ae.ProviderAccount.Add(providerAcc); } else { providerAcc = ae.ProviderAccount.FirstOrDefault(t => t.ProviderId == providerId); if (providerAcc != null) { providerAcc.Uri = collection["Uri"]; providerAcc.Login = collection["Login"]; providerAcc.Password = collection["Password"]; providerAcc.Enable = enable; providerAcc.Order = !string.IsNullOrEmpty(collection["order"]) ? int.Parse(collection["order"]) : 0; } } ae.SaveChanges(); return(RedirectToAction("Index", new { ProviderId = providerId })); } } catch { return(View()); } }
public async Task <IActionResult> Put(Guid providerId, [FromBody, Bind("CoordinatorId, Name, Email")] ProviderAccount provider) { _logger.LogInformation($"PUT - Put request for provider ID: {providerId}"); var existingProvider = await _repo.GetProviderAccountByIdAsync(providerId); if (existingProvider != null) { existingProvider.CoordinatorId = provider.CoordinatorId; existingProvider.Name = provider.Name; existingProvider.Email = provider.Email; await _repo.UpdateProviderAccountAsync(existingProvider); await _repo.SaveAsync(); _logger.LogInformation($"Put request persisted for {providerId}"); return(NoContent()); } _logger.LogWarning($"Put request failed for {providerId}"); return(NotFound()); }
public static ProviderAccount doChallenge(LoginForm loginForm, String providerAccountId) { String mn = "doChallenge( " + loginForm.ToString() + " providerAccountId = " + providerAccountId; String providerJson = JsonConvert.SerializeObject(loginForm, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); providerJson = providerJson.Replace("\r\n", ""); providerJson = "{\"loginForm\":" + providerJson + "}"; Console.WriteLine(providerJson); String addSiteURL = LoginApp.localURLVer1 + "providers/providerAccounts?providerAccountIds=" + providerAccountId; List <string> headers = new List <string>(); string usersessionid = LoginApp.usession; string cbrandsessionid = LoginApp.cbsession; headers.Add("Authorization:{userSession= " + usersessionid + ",cobSession=" + cbrandsessionid + "}"); String jsonResponse = HTTP.doPutNew(addSiteURL, headers, providerJson); ProviderAccount providerAccount = (ProviderAccount)GSONParser.handleJson(jsonResponse, typeof(ProviderAccount)); return(providerAccount); }
public static void addMFA_Account(Providers providers) { Console.WriteLine(" Add MFA_Account: "); Console.WriteLine("Enter your provider userName : "******"Enter provider password : "******"refresh status" + refMsg); if (refMsg == "FAILED") { Console.WriteLine("login failed please try again" + refMsg); break; } } while (providerAccount.providerAccount.getLoginForm() == null); //while (refMsg != "FAILED") //{ // refMsg = providerAccount.providerAccount.refreshInfo.status; // Console.WriteLine("refresh status" + refMsg); // if (refMsg == "FAILED") // { // Console.WriteLine("login failed please try again" + refMsg); // break; // } // providerAccount = AddProviderAccountNew.getProviderAccount(providerAccount.providerAccount.id); //} if (refMsg != "FAILED") { Console.WriteLine("received form:" + providerAccount.providerAccount.getLoginForm()); providerAccount.providerAccount.getLoginForm().getRow()[0].getField()[0].setValue("123456"); Console.WriteLine("putting mfa token"); providerAccount = doChallenge(providerAccount.providerAccount.getLoginForm(), providerAccount.providerAccount.id); } while (providerAccount.providerAccount.getLoginForm() == null && refMsg != "FAILED" && refMsg != "SUCCESS" && refMsg != "PARTIAL_SUCCESS") { refMsg = providerAccount.providerAccount.refreshInfo.status; Console.WriteLine("refresh status" + refMsg); if (refMsg == "FAILED") { Console.WriteLine("login failed please try again" + refMsg); break; } providerAccount = AddProviderAccountNew.getProviderAccount(providerAccount.providerAccount.id); } if (refMsg != "FAILED" && refMsg != "SUCCESS" && refMsg != "PARTIAL_SUCCESS") { Console.WriteLine("received form:" + providerAccount.providerAccount.getLoginForm()); providerAccount.providerAccount.getLoginForm().getRow()[0].getField()[0].setValue("Texas"); providerAccount.providerAccount.getLoginForm().getRow()[1].getField()[0].setValue("w3schools"); Console.WriteLine("putting mfa Q&A"); providerAccount = doChallenge(providerAccount.providerAccount.getLoginForm(), providerAccount.providerAccount.id); refMsg = providerAccount.providerAccount.refreshInfo.status; } while (refMsg != "SUCCESS" && refMsg != "PARTIAL_SUCCESS") { Console.WriteLine("refresh status" + refMsg + ",additional_Status " + providerAccount.providerAccount.refreshInfo.additionalStatus); if (refMsg == "FAILED") { Console.WriteLine("login failed please try again" + refMsg); break; } providerAccount = AddProviderAccountNew.getProviderAccount(providerAccount.providerAccount.id); refMsg = providerAccount.providerAccount.refreshInfo.status; } if (refMsg == "SUCCESS") { Console.WriteLine("acount aded successfully"); } if (refMsg == "PARTIAL_SUCCESS") { Console.WriteLine("acount aded partially"); } // Fetch the accounts if you need ! }
public void OnChangeProviderAccount(ProviderAccount entity, UpdateOperations operations) { InterceptChange(entity, operations); }
private static string ReadConfigToString() { string buffer = string.Empty; string zipBuffer = string.Empty; Catalog catalog = new Catalog(); catalog.Rows = 2; using (AvtoritetEntities ae = new AvtoritetEntities()) { System.Collections.Generic.List <RelayServer.DataContext.Group> groups = (from r in ae.Group where r.Enable select r into t orderby t.Order select t).ToList <RelayServer.DataContext.Group>(); catalog.Groups = new System.Collections.Generic.List <RelayServer.Models.Group>(); using (System.Collections.Generic.List <RelayServer.DataContext.Group> .Enumerator enumerator = groups.GetEnumerator()) { while (enumerator.MoveNext()) { RelayServer.DataContext.Group group = enumerator.Current; RelayServer.Models.Group catalogGroup = new RelayServer.Models.Group(); System.Collections.Generic.List <RelayServer.DataContext.GroupBox> groupboxs = (from t in ae.GroupBox where t.GroupId == @group.GroupId && t.Enable select t into r orderby r.Title select r).ToList <RelayServer.DataContext.GroupBox>(); catalogGroup.GroupBoxs = new System.Collections.Generic.List <RelayServer.Models.GroupBox>(); using (System.Collections.Generic.List <RelayServer.DataContext.GroupBox> .Enumerator enumerator2 = groupboxs.GetEnumerator()) { while (enumerator2.MoveNext()) { RelayServer.DataContext.GroupBox groupBox = enumerator2.Current; RelayServer.Models.GroupBox catalogGroupBox = new RelayServer.Models.GroupBox(); System.Collections.Generic.List <RelayServer.DataContext.Brand> brands = (from t in ae.Brand where t.GroupBoxId == groupBox.GroupBoxId && t.Enable select t into r orderby r.NameAndFolder select r).ToList <RelayServer.DataContext.Brand>(); catalogGroupBox.Brands = new System.Collections.Generic.List <RelayServer.Models.Brand>(); using (System.Collections.Generic.List <RelayServer.DataContext.Brand> .Enumerator enumerator3 = brands.GetEnumerator()) { while (enumerator3.MoveNext()) { RelayServer.DataContext.Brand brand = enumerator3.Current; RelayServer.Models.Brand catalogBrand = new RelayServer.Models.Brand(); System.Collections.Generic.List <RelayServer.DataContext.Provider> providers = (from t in ae.Provider where t.BrandId == brand.BrandId && t.Enable select t into r orderby r.Order select r).ToList <RelayServer.DataContext.Provider>(); catalogBrand.Providers = new System.Collections.Generic.List <RelayServer.Models.Provider>(); using (System.Collections.Generic.List <RelayServer.DataContext.Provider> .Enumerator enumerator4 = providers.GetEnumerator()) { while (enumerator4.MoveNext()) { RelayServer.DataContext.Provider provider = enumerator4.Current; ProviderAccount provAcc = ae.ProviderAccount.FirstOrDefault((ProviderAccount t) => t.ProviderId == provider.ProviderId && t.Enable); System.Collections.Generic.List <RelayServer.Models.CommandFile> commandFiles = (from t in ae.CommandFile where t.ProviderId == (int?)provider.ProviderId select t into r select new RelayServer.Models.CommandFile { FileName = r.FileName, FileContent = r.FileContent }).ToList <RelayServer.Models.CommandFile>(); System.Collections.Generic.List <RelayServer.Models.ProviderFile> providerFiles = (from t in ae.ProviderFile where t.ProviderId == (int?)provider.ProviderId select t into r select new RelayServer.Models.ProviderFile { FileName = r.FileName, FileExt = r.FileExt, FileSize = (long)r.FileSize, FileContent = r.FileContent }).ToList <RelayServer.Models.ProviderFile>(); catalogBrand.Providers.Add(new RelayServer.Models.Provider { Uri = provider.Uri.Trim(), IconPath = provider.IconPath, Title = provider.Title, Order = (provider.Order ?? 0), Commands = provider.commandcontent, Login = ((provAcc != null) ? provAcc.Login.Trim() : string.Empty), Password = ((provAcc != null) ? provAcc.Password.Trim() : string.Empty), CommandFiles = commandFiles, ProviderFiles = providerFiles }); } } catalogBrand.NameAndFolder = brand.NameAndFolder; catalogBrand.IconPath = brand.IconPath; catalogBrand.IconPath2 = brand.IconPath2; catalogBrand.IconPathImg = brand.IconPathImg; catalogBrand.IconPath2Img = brand.IconPath2Img; catalogBrand.Top = (brand.Top ?? 0); catalogBrand.Left = (brand.Left ?? 0); catalogBrand.Width = (brand.Width ?? 0); catalogBrand.Height = (brand.Height ?? 0); catalogBrand.BrandId = brand.BrandId; catalogBrand.ButtonStyle = brand.ButtonStyle; catalogBrand.MenuWindow = brand.MenuWindow.Value; catalogGroupBox.Brands.Add(catalogBrand); } } catalogGroupBox.Left = groupBox.Left.Value; catalogGroupBox.Top = groupBox.Top.Value; catalogGroupBox.Width = groupBox.Width.Value; catalogGroupBox.Height = groupBox.Height.Value; catalogGroupBox.Title = groupBox.Title; catalogGroupBox.VisibleBorder = groupBox.VisibleBorder.Value; catalogGroup.GroupBoxs.Add(catalogGroupBox); } } catalogGroup.Name = group.Name; catalogGroup.Width = group.Width.Value; catalogGroup.Height = group.Height.Value; catalogGroup.Order = (group.Order ?? 0); catalog.Groups.Add(catalogGroup); } } buffer = StringZip.Zip(new JavaScriptSerializer { MaxJsonLength = 2147483647 }.Serialize(catalog)); } return(buffer); }
/// <summary> /// Add a Provider to the database. /// </summary> /// <param name="newAccount"></param> public void AddProviderAccountAsync(ProviderAccount newAccount) { var newEntity = _mapper.MapProvider(newAccount); _context.Add(newEntity); }
public async Task <ActionResult> Get() { _logger.LogInformation($"GET - Retrieving user ID and verifying correct metadata is in token."); try { var auth0 = _authHelperFactory.Create(Request); var authUser = await auth0.Client.Users.GetUsersByEmailAsync(auth0.Email); var authRoles = await auth0.Client.Roles.GetAllAsync(new GetRolesRequest()); var id = await _repo.GetCoordinatorIdByEmailAsync(auth0.Email); if (id != Guid.Empty) { // If their roles arent set properly, set them if (!auth0.Roles.Contains(Auth0Helper.CoordinatorRole)) { await auth0.AddRoleAsync(authUser[0].UserId, authRoles.First(r => r.Name == Auth0Helper.CoordinatorRole).Id); } } else { // Check the provider db id = await _repo.GetProviderIdByEmailAsync(auth0.Email); if (id != Guid.Empty && !auth0.Roles.Contains(Auth0Helper.UnapprovedProviderRole) && !auth0.Roles.Contains(Auth0Helper.ApprovedProviderRole)) { // They have no role, so set them as unapproved await auth0.AddRoleAsync(authUser[0].UserId, authRoles.First(r => r.Name == Auth0Helper.UnapprovedProviderRole).Id); } } if (id == Guid.Empty) { // They have no account anywhere - check roles for coordinator role if (auth0.Roles.Contains(Auth0Helper.CoordinatorRole)) { // They have been set as a coordinator on the Auth0 site, so make a new account var coordinator = new CoordinatorAccount { Name = authUser[0].FirstName != null && authUser[0].LastName != null ? authUser[0].FirstName + " " + authUser[0].LastName : "No Name", Email = auth0.Email, TrainingCenterName = "No Name", TrainingCenterAddress = "No Address" }; // Add them _repo.AddCoordinatorAccount(coordinator); } else { // Make a new provider var provider = new ProviderAccount { Name = authUser[0].FirstName != null && authUser[0].LastName != null ? authUser[0].FirstName + " " + authUser[0].LastName : "No Name", Email = auth0.Email, Status = new Status(Status.Pending), AccountCreatedAt = DateTime.Now, AccountExpiresAt = DateTime.Now.AddDays(7) }; // Add them _repo.AddProviderAccountAsync(provider); // No notification is made. This is handled in the frontend when // they select a training center and click 'request approval' // They have no role, so set them as unapproved await auth0.AddRoleAsync(authUser[0].UserId, authRoles.First(r => r.Name == Auth0Helper.UnapprovedProviderRole).Id); } // Db was modified either way, save changes await _repo.SaveAsync(); // Get their id id = await _repo.GetProviderIdByEmailAsync(auth0.Email); } // Update the app_metadata if it doesnt contain the correct id await auth0.UpdateMetadataWithIdAsync(authUser[0].UserId, id); return(Ok(id)); } catch (Exception e) { _logger.LogError(e, "Error occurred in token setup"); return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }