/// <summary> /// Saves/Updates a <see cref="SmartUser"/> the user. /// </summary> /// <remarks> /// If this method is passed a SmartUser with a non-zero SmartUser.UserId, it will update the corresponding SmartUser in the repo. If this method is passed a SmartUser with a SmartUser.UserId = 0, then it will create a new SmartUser in the repo. /// </remarks> /// <param name="user">The <see cref="SmartUser"/> to be added/updated.</param> public void SaveUser(SmartUser user) { if (user.UserId == 0) { context.Users.Add(user); } else { SmartUser dbUser = context.Users.FirstOrDefault(u => u.UserId == user.UserId); if (dbUser != null) { dbUser.DisplayName = user.DisplayName; } } context.SaveChanges(); }
public async Task <ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal) { var identity = principal.Identities.FirstOrDefault(x => x.IsAuthenticated); if (identity == null) { return(principal); } var user = identity.Name; // Is this the Windows Logon name? if (user == null) { return(principal); } if (principal.Identity is ClaimsIdentity) { string logonName = user.Split('\\')[1]; logonName = logonName.ToLower(); // pull user roles SmartUser dbUser = _repository.GetUserByLogonName(logonName); if (dbUser != null) { var ci = (ClaimsIdentity)principal.Identity; if (logonName == "jcs30" || logonName == "jcsmith1") { ci.AddClaim(new Claim(ci.RoleClaimType, "Administrator")); } ci.AddClaim(new Claim(ci.RoleClaimType, "User")); ci.AddClaim(new Claim("DisplayName", dbUser.DisplayName)); ci.AddClaim(new Claim("UserId", dbUser.UserId.ToString(), ClaimValueTypes.Integer32)); ci.AddClaim(new Claim("BlueDeckId", dbUser.BlueDeckId.ToString(), ClaimValueTypes.Integer32)); ci.AddClaim(new Claim("LDAPName", logonName)); } else { var ci = (ClaimsIdentity)principal.Identity; ci.AddClaim(new Claim("DisplayName", "Guest")); ci.AddClaim(new Claim("LDAPName", logonName)); } } return(principal); }
/// <summary> /// Removes a <see cref="SmartUser"/>. /// </summary> /// <param name="user">The <see cref="SmartUser"/> to remove.</param> public void RemoveUser(SmartUser user) { context.Users.Remove(user); context.SaveChanges(); }