public IActionResult ChangeName([Bind(Prefix = "Name")] UserNameModel model) { if (!ModelState.IsValid) { return(CorrectErrors(BuildUserProfileModel(model), "name")); } var user = _userAccountService.GetByID(User.GetId()); _userAccountService.RemoveClaims(user.ID, new UserClaimCollection(user.Claims.Where(claim => claim.Type == "given_name" || claim.Type == "family_name" || claim.Type == "name"))); var claims = new UserClaimCollection(); claims.Add("given_name", model.GivenName); claims.Add("family_name", model.FamilyName); claims.Add("name", string.Join(" ", new string[] { model.GivenName, model.FamilyName } .Where(name => !string.IsNullOrWhiteSpace(name)))); _userAccountService.AddClaims(user.ID, claims); return(RedirectToAction("Edit", new { changed = true })); }
public IActionResult Save(UserProfileModel profile) { Guid userGuid; if (!Guid.TryParse(profile.UserId, out userGuid)) { return(HttpBadRequest("Failed to parse userId.")); } if (ModelState.IsValid) { var user = _userAccountService.GetByID(userGuid); _userAccountService.RemoveClaims(userGuid, new UserClaimCollection(user.Claims.Where(claim => claim.Type == "given_name" || claim.Type == "family_name" || claim.Type == "name" || claim.Type == "fsw:organization" || claim.Type == "fsw:department"))); var claims = new UserClaimCollection(); claims.Add("given_name", profile.GivenName); claims.Add("family_name", profile.FamilyName); claims.Add("name", string.Join(" ", new string[] { profile.GivenName, profile.FamilyName } .Where(name => !string.IsNullOrWhiteSpace(name)))); if (!string.IsNullOrWhiteSpace(profile.Organization)) { claims.Add("fsw:organization", profile.Organization); } if (!string.IsNullOrWhiteSpace(profile.Department)) { claims.Add("fsw:department", profile.Department); } _userAccountService.AddClaims(userGuid, claims); return(RedirectToAction("Edit", new { userId = profile.UserId, changed = true })); } return(View("Edit", profile)); }
public ActionResult Index(RegisterInputModel model) { if (ModelState.IsValid) { try { model.Email = model.Email.ToLowerInvariant().Trim(); var account = this._userAccountService.CreateAccount(model.Username, model.Password, model.Email); ViewData["RequireAccountVerification"] = this._userAccountService.Configuration.RequireAccountVerification; UserClaimCollection claims = new UserClaimCollection { new UserClaim("given_name", model.GivenName), new UserClaim("family_name", model.FamilyName), new UserClaim("name", string.Join(" ", new string[] { model.GivenName, model.FamilyName } .Where(name => !string.IsNullOrWhiteSpace(name)) )) }; if (model.Email.EndsWith("@foodservicewarehouse.com") || model.Email.EndsWith("@fsw.com")) { claims.Add(new UserClaim("fsw:organization", "FSW")); } else { string emailDomain = model.Email.Split('@')[1]; claims.Add(new UserClaim("fsw:organization", emailDomain)); } _userAccountService.AddClaims(account.ID, claims); return(View("Success", model)); } catch (ValidationException ex) { ModelState.AddModelError("", ex.Message); } } return(View(model)); }
private void AddClaims(Guid accountId, CreateAccountInputModel model) { model.Email = model.Email.ToLowerInvariant().Trim(); UserClaimCollection claims = new UserClaimCollection { new UserClaim("given_name", model.GivenName), new UserClaim("family_name", model.FamilyName), new UserClaim("name", string.Join(" ", new string[] { model.GivenName, model.FamilyName } .Where(name => !string.IsNullOrWhiteSpace(name)) )) }; if (model.IsAuthCentralAdmin) { claims.Add(new UserClaim("fsw:authcentral:admin", "true")); } if (!string.IsNullOrWhiteSpace(model.Organization)) { claims.Add(new UserClaim("fsw:organization", model.Organization)); } else if (model.Email.EndsWith("@foodservicewarehouse.com") || model.Email.EndsWith("@fsw.com")) { claims.Add(new UserClaim("fsw:organization", "FSW")); } else { string emailDomain = model.Email.Split('@')[1]; claims.Add(new UserClaim("fsw:organization", emailDomain)); } if (!string.IsNullOrWhiteSpace(model.Department)) { claims.Add(new UserClaim("fsw:department", model.Department)); } _userAccountService.AddClaims(accountId, claims); }
/// <summary> /// Imposta le mappature necessarie alla libreria Caravan.WebApi. /// </summary> public CaravanWebApiMapperConfig() { CreateMap<LogEntryBulkDTO, LogEntry>(); CreateMap<SecApp, LinkedSecApp>(); CreateMap<IEnumerable<Tuple<string, string>>, UserClaimCollection>() .ConvertUsing(tuples => { var uc = new UserClaimCollection(); foreach (var t in tuples) { uc.Add(t.Item1, t.Item2); } return uc; }); }