protected List <AppUserClaim> GetUserClaims(AppUser authUser) { List <AppUserClaim> list = new List <AppUserClaim>(); try { var Userclaims = _repo.GetUserClaims(authUser.UserName); foreach (var cl in Userclaims.Result) { AppUserClaim usrcl = new AppUserClaim(); usrcl.ClaimId = new Guid(); usrcl.UserId = new Guid(authUser.Id); usrcl.ClaimType = cl.Type; usrcl.ClaimValue = cl.Value; list.Add(usrcl); } } catch (Exception ex) { throw new Exception( "Exception trying to retrieve user claims.", ex); } return(list); }
public void RemoveClaimAsync(ApplicationUser user, Claim claim) { AppUserClaim c = new AppUserClaim { UserId = user.Id }; DeleteWhere(c, "UserId=@UserId"); }
public void AddClaimAsync(ApplicationUser user, Claim claim) { AppUserClaim c = new AppUserClaim { UserId = user.Id, ClaimType = claim.Type, ClaimValue = claim.Value }; Insert(c); }
public IList <Claim> GetClaimsAsync(ApplicationUser user) { AppUserClaim c = new AppUserClaim { UserId = user.Id }; DataTable table = ExecuteTableWhere(c, "UserId=@UserId"); List <Claim> list = new List <Claim>(); foreach (DataRow row in table.Rows) { list.Add(TransToClaim(row)); } return(list); }
public static AppUserClaim Create(UserClaim userClaim) { if (userClaim == null) { return(null); } var appUserClaim = new AppUserClaim { Id = userClaim.Id, UserId = userClaim.UserId, ClaimType = userClaim.ClaimType, ClaimValue = userClaim.ClaimValue }; return(appUserClaim); }
public static UserClaim Create(AppUserClaim appUserClaim) { if (appUserClaim == null) { return(null); } var userClaim = new UserClaim { Id = appUserClaim.Id, UserId = appUserClaim.UserId, ClaimType = appUserClaim.ClaimType, ClaimValue = appUserClaim.ClaimValue }; return(userClaim); }
public IActionResult Post([FromBody] AppUser user) { AppUserAuth returnData = new AppUserAuth(); var a = schoolContext.AspNetUsers.FirstOrDefault(); returnData.UserName = "******"; returnData.IsAuthenticated = true; returnData.BearerToken = "eyJhbGciOiJIUzI1NiIs"; returnData.Claims = new List <AppUserClaim>(); AppUserClaim cliam = new AppUserClaim(); cliam.ClaimId = new Guid(); cliam.ClaimType = "CanAccessProducts"; cliam.ClaimValue = "true"; returnData.Claims.Add(cliam); return(StatusCode(StatusCodes.Status200OK, returnData)); }
public AppUserAuth GetNewUserClaims(AppUser user) { AppUserAuth ret = new AppUserAuth(); AppUser authUser = null; try { using (var db = new PtcDbContext()) { if (user != null) { db.Users.Add(user); db.SaveChanges(); authUser = db.Users.Where( u => u.UserName.ToLower() == user.UserName.ToLower() && u.Password == user.Password).FirstOrDefault(); AppUserClaim userClaim = new AppUserClaim(); userClaim.UserId = authUser.UserId; userClaim.ClaimType = "CanAccessMenu"; userClaim.ClaimValue = "true"; db.Claims.Add(userClaim); db.SaveChanges(); if (authUser != null) { //build usersecurity object ret = BuildUserAuthObject(authUser); } } } } catch (Exception ex) { throw new Exception( "Exception trying to create new user.", ex); } return(ret); }