public async Task <IActionResult> Register(RegisterInputModel model, string button) { var returnUrl = Url.Content("~/"); if (button != "register") { // Todo add some special page. return(LocalRedirect(returnUrl)); } if (ModelState.IsValid) { var user = new IdUser { UserName = model.Username }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { // _logger.LogInformation("User created a new account with password."); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // something went wrong. return(View(new RegisterViewModel(model))); }
public override int GetHashCode() { int hashCode = 13; hashCode = (hashCode * 7) + IdUser.GetHashCode(); hashCode = (hashCode * 7) + IdProcess.GetHashCode(); return(hashCode); }
public bool IsValid() { if (string.IsNullOrEmpty(IdUser.ToString()) || string.IsNullOrEmpty(IdUserInvite.ToString())) { return(false); } return(true); }
protected void Page_Load(object sender, EventArgs e) { this.EnableViewState = false; try { CreateReport(); } catch (Exception ex) { HttpContext.Current.Session["LastReportDefinitionError"] = ex; ShowError(); } // for treeview on save report option string path = Path.Combine( HttpContext.Current.Request.PhysicalApplicationPath, "Fileadmin", "SavedReports", Global.Core.ClientName //, IdUser.ToString() ); string userPath = path + "/" + IdUser.ToString(); //if (!Directory.Exists(path + "/" + IdUser.ToString())) //{ // Directory.CreateDirectory(path + "/" + IdUser.ToString()); //} DirectoryInfo rootInfo = new DirectoryInfo(path); TreeView1.Nodes.Clear(); this.PopulateTreeView(rootInfo, null, userPath); boxSettings.Visible = true; boxFilterDefinition.Visible = true; boxFilterSearch.Visible = true; boxSave.Visible = true; boxCombineCategoires.Visible = true; cogSrchApi.Value = "false"; if (ConfigurationManager.AppSettings["cogSrchApi"] != null) { ConfigurationManager.AppSettings["cogSrchApi"].ToString(); } }
protected TUser ToMutable(IdUser idUser) { return(new TUser { Id = idUser.Id, UserName = idUser.UserName, UserNameNormalized = idUser.UserNameNormalized, Email = idUser.Email, EmailNormalized = idUser.EmailNormalized, Phone = idUser.Phone, EmailConfirmed = idUser.EmailConfirmed, PhoneConfirmed = idUser.PhoneConfirmed, PasswordHash = idUser.PasswordHash, SecurityStamp = idUser.SecurityStamp, ConcurrencyStamp = idUser.ConcurrencyStamp, TwoFactorEnabled = idUser.TwoFactorEnabled, AccessFailedCount = idUser.AccessFailedCount, LockoutEnabled = idUser.LockoutEnabled, LockoutEnd = idUser.LockoutEnd, Claims = idUser.Claims.ToList(), Logins = ToMutable(idUser.Logins).ToList() }); }
public async Task <ActionResult <UserDtoOut> > Register([FromBody] UserDtoIn userDtoIn) { if (string.IsNullOrWhiteSpace(userDtoIn.EMail)) { return(BadRequest(new { message = "Invalid Email Address" })); } if (string.IsNullOrWhiteSpace(userDtoIn.Password)) { return(BadRequest(new { message = "Invalid password" })); } if (string.IsNullOrWhiteSpace(userDtoIn.UserName)) { userDtoIn.UserName = userDtoIn.EMail; } IdUser user = new IdUser { UserName = userDtoIn.UserName, Email = userDtoIn.EMail, }; var result = await _userManager.CreateAsync(user, userDtoIn.Password); var userDtoOut = new UserDtoOut(); string name = ""; if (result.Succeeded) { var claims = new List <Claim>(); if (!string.IsNullOrWhiteSpace(userDtoIn.FirstName)) { claims.Add(new Claim(JwtClaimTypes.GivenName, userDtoIn.FirstName)); userDtoOut.FirstName = userDtoIn.FirstName; name += userDtoIn.FirstName; } if (!string.IsNullOrWhiteSpace(userDtoIn.LastName)) { claims.Add(new Claim(JwtClaimTypes.FamilyName, userDtoIn.LastName)); userDtoOut.LastName = userDtoIn.LastName; if (name.Count() > 0) { name += " " + userDtoOut.LastName; } else { name += userDtoIn.LastName; } } if (!string.IsNullOrWhiteSpace(userDtoIn.DateOfBirth)) { claims.Add(new Claim(JwtClaimTypes.BirthDate, userDtoIn.DateOfBirth)); userDtoOut.DateOfBirth = userDtoIn.DateOfBirth; } if (!string.IsNullOrWhiteSpace(userDtoIn.Role)) { claims.Add(new Claim(JwtClaimTypes.Role, userDtoIn.Role)); userDtoOut.Role = userDtoIn.Role; } if (!string.IsNullOrWhiteSpace(userDtoIn.UserNumber)) { claims.Add(new Claim(CustomClaims.UserNumber, userDtoIn.UserNumber)); userDtoOut.UserNumber = userDtoIn.UserNumber; } // Add claim to access to IdApi1 and IdUserApi for all users per default. claims.Add(new Claim(CustomClaims.ApiAccess, "IdApi1")); claims.Add(new Claim(CustomClaims.ApiAccess, "IdUserApi")); if (userDtoIn.UserName != userDtoIn.EMail) { name = userDtoIn.UserName; } if (name.Count() == 0) { name = user.Id; } claims.Add(new Claim(JwtClaimTypes.Name, name)); result = await _userManager.AddClaimsAsync(user, claims); await _identityDbContext.SaveChangesAsync(); } if (result.Succeeded) { userDtoOut.Id = user.Id; userDtoOut.UserName = user.UserName; userDtoOut.EMail = user.Email; return(StatusCode(201, userDtoOut)); } return(handleIdentityError(result.Errors, user)); }
private ActionResult <UserDtoOut> handleIdentityError(IEnumerable <IdentityError> errors, IdUser user) { if (errors.Count() == 0) { return(BadRequest(new { message = "Unknown Error" })); } foreach (var error in errors) { if (error.Code == new IdentityErrorDescriber().DuplicateUserName(user.UserName).Code) { return(Conflict(new { message = $"The username {user.UserName} is already in use" })); } } return(BadRequest(new { message = errors.First().Description })); }
private async Task <IdUser> IntegrateExternalUser(string provider, string providerUserId, IEnumerable <Claim> claims, IdUser user = null) { if (user == null) { user = new IdUser(); _idUserDbContext.Add(user); await _userManager.UpdateSecurityStampAsync(user); } var claimsToRemove = _idUserDbContext.UserClaims.Where(claim => claim.UserId == user.Id && claim.Issuer == provider); _idUserDbContext.UserClaims.RemoveRange(claimsToRemove); await _idUserDbContext.SaveChangesAsync(); var claimsToUse = new List <IdUserClaim>(); foreach (var claim in claims) { if (claim.Type == ClaimTypes.Name) { claimsToUse.Add(new IdUserClaim { ClaimType = JwtClaimTypes.Name, ClaimValue = claim.Value, UserId = user.Id, Issuer = provider }); } else if (JwtSecurityTokenHandler.DefaultOutboundClaimTypeMap.ContainsKey(claim.Type)) { claimsToUse.Add(new IdUserClaim { ClaimType = JwtSecurityTokenHandler.DefaultOutboundClaimTypeMap[claim.Type], ClaimValue = claim.Value, UserId = user.Id, Issuer = provider }); } else { claimsToUse.Add(new IdUserClaim { ClaimType = claim.Type, ClaimValue = claim.Value, UserId = user.Id, Issuer = provider }); } } // if no display name was provided, try to construct by first and/or last name if (!claimsToUse.Any(claim => claim.ClaimType == JwtClaimTypes.Name)) { var first = claimsToUse.FirstOrDefault(x => x.ClaimType == JwtClaimTypes.GivenName)?.ClaimValue; var last = claimsToUse.FirstOrDefault(x => x.ClaimType == JwtClaimTypes.FamilyName)?.ClaimValue; if (first != null && last != null) { claimsToUse.Add(new IdUserClaim { ClaimType = JwtClaimTypes.Name, ClaimValue = first + " " + last, UserId = user.Id, Issuer = provider }); } else if (first != null) { claimsToUse.Add(new IdUserClaim { ClaimType = JwtClaimTypes.Name, ClaimValue = first, UserId = user.Id, Issuer = provider }); } else if (last != null) { claimsToUse.Add(new IdUserClaim { ClaimType = JwtClaimTypes.Name, ClaimValue = last, UserId = user.Id, Issuer = provider }); } } claimsToUse.Add(new IdUserClaim { ClaimType = "ApiAccess", ClaimValue = "IdApi1", UserId = user.Id, Issuer = "local" }); claimsToUse.Add(new IdUserClaim { ClaimType = "ApiAccess", ClaimValue = "IdUserApi", UserId = user.Id, Issuer = "local" }); user.UserName = claimsToUse.FirstOrDefault(c => c.ClaimType == JwtClaimTypes.Name)?.ClaimValue ?? user.Id; user.NormalizedUserName = user.UserName; _idUserDbContext.AddRange(claimsToUse); var externalLogins = await _userManager.GetLoginsAsync(user); if (externalLogins == null || externalLogins.Count == 0) { await _userManager.AddLoginAsync(user, new UserLoginInfo(provider, providerUserId, user.UserName)); } await _idUserDbContext.SaveChangesAsync(); return(user); }
private void PopulateTreeView(DirectoryInfo dirInfo, TreeNode treeNode, string userPath) { TreeView1.NodeStyle.CssClass = "FileExplorerItem Color1"; TreeView1.SelectedNodeStyle.CssClass = "FileExplorerItem_Active Color2"; if (!Directory.Exists(userPath)) { TreeNode directoryNode = new TreeNode { Text = "my saved reports", Value = userPath }; directoryNode.NavigateUrl = "javascript: ManualSaveReportFolderSelect(this,'" + directoryNode.Value.Replace("\\", "/") + "'); "; TreeView1.Nodes.Add(directoryNode); } else { foreach (DirectoryInfo directory in dirInfo.GetDirectories()) { //if (directory.FullName.IndexOf(IdUser.ToString()) == -1) // continue; Guid guidOutput = Guid.Empty; if (Guid.TryParse(directory.Name, out guidOutput)) { if (!(directory.Name == IdUser.ToString())) { continue; } } string Text = directory.Name; if (Text == IdUser.ToString()) { Text = "my saved reports"; } else { Text = directory.Name; } TreeNode directoryNode = new TreeNode { Text = Text, Value = directory.FullName }; directoryNode.NavigateUrl = "javascript: ManualSaveReportFolderSelect(this,'" + directoryNode.Value.Replace("\\", "/") + "'); "; if (treeNode == null) { //If Root Node, add to TreeView. TreeView1.Nodes.Add(directoryNode); } else { //If Child Node, add to Parent Node. treeNode.ChildNodes.Add(directoryNode); } //Get all files in the Directory. //foreach (FileInfo file in directory.GetFiles()) //{ // //Add each file as Child Node. // TreeNode fileNode = new TreeNode // { // Text = file.Name, // Value = file.FullName, // Target = "_blank", // NavigateUrl = (new Uri(Server.MapPath("~/"))).MakeRelativeUri(new Uri(file.FullName)).ToString() // }; // directoryNode.ChildNodes.Add(fileNode); //} PopulateTreeView(directory, directoryNode, userPath); } } }
private void CreateReport() { ReportDefinition reportDefinition; string fileName; string directoryName; if (this.Request.Params["SavedReport"] == null) { // Get the full path to the directory // where the saved report is saved. directoryName = Path.Combine( Request.PhysicalApplicationPath, "Fileadmin", "ReportDefinitions", Global.Core.ClientName, Global.User.Id.ToString() ); lblPageTitle.Text = Global.LanguageManager.GetText("Crosstabs"); if (HttpContext.Current.Session["ActiveSavedReport"] != null && Directory.Exists((string)HttpContext.Current.Session["ActiveSavedReport"])) { Directory.Delete((string)HttpContext.Current.Session["ActiveSavedReport"], true); } HttpContext.Current.Session["ActiveSavedReport"] = null; if (HttpContext.Current.Session["ReportDefinition"] != null && (new FileInfo(HttpContext.Current.Session["ReportDefinition"].ToString())).DirectoryName != directoryName) { HttpContext.Current.Session["ReportDefinition"] = null; } } else { Guid idUser = Guid.Parse(this.Request.Params["SavedReport"].Substring(0, 36)); Guid idReport = Guid.Parse(this.Request.Params["SavedReport"].Substring(36, 36)); directoryName = Path.Combine( Request.PhysicalApplicationPath, "Fileadmin", "Temp", "OpenSavedReports", HttpContext.Current.Session.SessionID, this.Request.Params["SavedReport"] ); if (HttpContext.Current.Session["ActiveSavedReport"] == null || Directory.Exists(directoryName) == false) { // Get the full path to the directory // where the user's reports are saved. string sourceDirectoryName = ""; if (HttpContext.Current.Session["ManualSaveReportFolderSelect"] != null) { sourceDirectoryName = HttpContext.Current.Session["ManualSaveReportFolderSelect"].ToString() + "/" + idReport.ToString(); } if (sourceDirectoryName == "") { sourceDirectoryName = Path.Combine( Request.PhysicalApplicationPath, "Fileadmin", "SavedReports", Global.Core.ClientName, idUser.ToString(), idReport.ToString() ); } if (HttpContext.Current.Session["LinkCloudSelectedReportUrl"] == null && HttpContext.Current.Session["ManualSaveReportFolderSelect"] != null) { HttpContext.Current.Session["LinkCloudSelectedReportUrl"] = HttpContext.Current.Session["ManualSaveReportFolderSelect"]; } if (HttpContext.Current.Session["LinkCloudSelectedReportUrl"] == null || !Directory.Exists(sourceDirectoryName)) { string[] paths = Directory.GetDirectories(Path.Combine(Request.PhysicalApplicationPath, "Fileadmin", "SavedReports", Global.Core.ClientName, idUser.ToString()), "*", SearchOption.AllDirectories); if (paths.Where(x => x.ToLower().IndexOf(idReport.ToString().ToLower()) > -1) != null) { HttpContext.Current.Session["LinkCloudSelectedReportUrl"] = paths.Where(x => x.ToLower().IndexOf(idReport.ToString().ToLower()) > -1).FirstOrDefault(); } } if (HttpContext.Current.Session["LinkCloudSelectedReportUrl"].ToString().IndexOf(idReport.ToString()) != -1) { sourceDirectoryName = HttpContext.Current.Session["LinkCloudSelectedReportUrl"].ToString(); } if (Directory.Exists(directoryName)) { Directory.Delete(directoryName, true); } Directory.CreateDirectory(directoryName); foreach (string file in Directory.GetFiles(sourceDirectoryName).OrderBy(d => new FileInfo(d).CreationTime)) { File.Copy(file, Path.Combine( directoryName, new FileInfo(file).Name )); File.SetCreationTime(Path.Combine( directoryName, new FileInfo(file).Name ), File.GetCreationTime(file)); } //foreach (string file in Directory.GetFiles(sourceDirectoryName)) //{ // File.Copy(file, Path.Combine( // directoryName, // new FileInfo(file).Name // )); //} } if (HttpContext.Current.Session["ActiveSavedReport"] == null) { HttpContext.Current.Session["ReportDefinition"] = null; } HttpContext.Current.Session["ActiveSavedReport"] = directoryName; if (HttpContext.Current.Session["ReportDefinition"] != null) { if (new FileInfo(HttpContext.Current.Session["ReportDefinition"].ToString()).DirectoryName != directoryName) { HttpContext.Current.Session["ReportDefinition"] = null; } } ReportDefinitionInfo savedReportInfo = new ReportDefinitionInfo(Path.Combine( directoryName, "Info.xml" )); lblPageTitle.Text = "<table style=\"display:inline-block\"><tbody style=\"display:inline-block\"><tr style=\"display:inline-block\"><td style=\"display:inline-block\"><img src=\"/Images/Icons/Back.png\" onclick=\"window.location='/Pages/LinkCloud.aspx'\" " + "onmouseover=\"this.src='/Images/Icons/Back_Hover.png'\" onmouseout=\"this.src='/Images/Icons/Back.png'\" style=\"cursor:pointer;\" />" + "</td><tr style=\"margin-top:-20px;display:inline-block \"><td style=\"display:inline-block\">" + savedReportInfo.Name + "</td></tr></tr></tbody></table>"; } if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } ReportDefinitionInfo info = new ReportDefinitionInfo(Path.Combine( directoryName, "Info.xml" )); info.LatestAccess = DateTime.Now; info.Save(); // Get all the reports of the user. List <string> reports = info.GetReports( Global.Core, Global.IdUser.Value ); if (HttpContext.Current.Session["ReportDefinition"] != null) { if (!reports.Contains(HttpContext.Current.Session["ReportDefinition"])) { HttpContext.Current.Session["ReportDefinition"] = null; } } if (HttpContext.Current.Session["ReportDefinition"] == null && info.ActiveReport.HasValue) { HttpContext.Current.Session["ReportDefinition"] = Path.Combine( directoryName, info.ActiveReport.Value + ".xml" ); } // Check if for the current session a report is selected. if (HttpContext.Current.Session["ReportDefinition"] == null || File.Exists(HttpContext.Current.Session["ReportDefinition"].ToString()) == false) { // Check if the user has reports defined. if (reports.Count == 0) { fileName = Path.Combine( directoryName, Guid.NewGuid().ToString() + ".xml" ); string fileNameWorkflow = Path.Combine( Request.PhysicalApplicationPath, "App_Data", "ReportingWorkflows", Global.Core.ClientName + ".xml" ); string fileNameWeighting = Path.Combine( Request.PhysicalApplicationPath, "App_Data", "WeightingDefaults", Global.Core.ClientName + ".xml" ); if (!File.Exists(fileNameWeighting)) { fileNameWeighting = null; } reportDefinition = new ReportDefinition( Global.Core, fileName, fileNameWorkflow, fileNameWeighting, Global.HierarchyFilters[fileName, false], Global.UserDefaults["ReportDefinitionSettings"] ); reportDefinition.XmlDocument.DocumentElement.SetAttribute("Name", GetUniqueReportName(string.Format(Global.LanguageManager.GetText("NewReport"), "").Trim(), directoryName)); reportDefinition.Save(); reports = info.GetReports( Global.Core, Global.IdUser.Value ); } else { // Select the first report as the selected report. fileName = reports[0]; } HttpContext.Current.Session["ReportDefinition"] = fileName; } else { // Get the full path to the currently selected report's definition file. fileName = HttpContext.Current.Session["ReportDefinition"].ToString(); } // Get the full path of the current session's report definition file. string directory = (new FileInfo(HttpContext.Current.Session["ReportDefinition"].ToString())).DirectoryName; // Run through all files of the directory. foreach (string file in Directory.GetFiles(directory).OrderBy(x => new FileInfo(x).CreationTime)) { if (Path.GetFileName(file) == "Info.xml") { continue; } csFilterDefinition.Source = file; EquationDefinition.Source = file; HierarchySelector.FileName = Path.Combine( HttpContext.Current.Request.PhysicalApplicationPath, "App_Data", "HierarchySelectors", Global.Core.ClientName + ".xml" ); HierarchySelector.Source = file; // Create a new report definition by the report definition file. reportDefinition = new ReportDefinition( Global.Core, file, Global.HierarchyFilters[file] ); bool hasNewCategories1 = reportDefinition.CheckForNewCategories(); if (hasNewCategories1) { reportDefinition.Save(); reportDefinition = new ReportDefinition( Global.Core, file, Global.HierarchyFilters[file] ); ReportCalculator calculator = new ReportCalculator( reportDefinition, Global.Core, HttpContext.Current.Session ); calculator.Aggregate((string)HttpContext.Current.Session["Version"]); } if (HierarchySelector.Exists) { HierarchySelector.Parse(); } reportDefinition.Save(); } csFilterDefinition.Source = fileName; EquationDefinition.Source = fileName; HierarchySelector.FileName = Path.Combine( HttpContext.Current.Request.PhysicalApplicationPath, "App_Data", "HierarchySelectors", Global.Core.ClientName + ".xml" ); HierarchySelector.Source = fileName; // Create a new report definition by the report definition file. reportDefinition = new ReportDefinition( Global.Core, fileName, Global.HierarchyFilters[fileName] ); bool hasNewCategories = reportDefinition.CheckForNewCategories(); if (hasNewCategories) { reportDefinition.Save(); reportDefinition = new ReportDefinition( Global.Core, fileName, Global.HierarchyFilters[fileName] ); ReportCalculator calculator = new ReportCalculator( reportDefinition, Global.Core, HttpContext.Current.Session ); calculator.Aggregate((string)HttpContext.Current.Session["Version"]); } if (HierarchySelector.Exists) { HierarchySelector.Parse(); int optionCount = 0; foreach (Classes.Controls.HierarchySelectorSection section in HierarchySelector.Sections.Values) { optionCount += section.OptionCount; } if (optionCount <= 1) { pnlRightPanelHierarchy.Visible = false; } else { pnlRightPanelHierarchy.Attributes.Add("onclick", string.Format( "InitDragBox('boxHierarchySelectorControl');LoadHierarchySelectedItems('{0}');", HttpUtility.UrlEncode(fileName.Replace("\\", "/")) )); if (reportDefinition.XmlDocument.DocumentElement.SelectSingleNode("HierarchyFilter") == null) { Page.ClientScript.RegisterStartupScript( this.GetType(), "ShowHierarchySelector", string.Format("InitDragBox('boxHierarchySelectorControl');LoadHierarchySelectedItems('{0}');", HttpUtility.UrlEncode(fileName.Replace("\\", "/"))), true ); } } } else { pnlRightPanelHierarchy.Visible = false; } if (base.ContentWidth != 0) { reportDefinition.Settings.TableWidth = base.ContentWidth; } if (base.ContentHeight != 0) { reportDefinition.Settings.TableHeight = base.ContentHeight; } reportDefinition.Save(); Crosstables.Classes.Crosstable crosstable = new Crosstables.Classes.Crosstable( Global.Core, fileName ); //crosstable.FilterClickAction = "ctl00$cphContent$btnDisplayFilters"; pnl.Controls.Add(crosstable); BindSettings(reportDefinition); BindFilteredCategories(reportDefinition); BindWeightingDefinition(reportDefinition); BindReports(reports); if (reportDefinition.Workflow.Selections.Count > 0) { if (bool.Parse(Global.UserDefaults["BottomBarPinned", "false"])) { pnlWorkflowContainer.CssClass = "WorkflowPinned BorderColor1"; } pnlWorkflow.Controls.Add(reportDefinition.Workflow); } else { pnlWorkflowContainer.Visible = false; } if ((fileName.IndexOf(IdUser.ToString()) == -1) && (Convert.ToBoolean(HttpContext.Current.Session["RenderValues"]) == true)) { HttpContext.Current.Session["RenderValues"] = false; ScriptManager.RegisterClientScriptBlock(this, GetType(), "Javascript", "RenderValues();", true); } }