public override Task <IdentityResult> CreateAsync(AppIdentityUser identityUser, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (identityUser == null) { throw new ArgumentNullException(nameof(identityUser)); } var newUser = new UserDTO(); Map(identityUser, newUser); newUser.Id = _userManager.Create(newUser); Mapper.Map(newUser, identityUser); var claim = new AppIdentityUserClaim(identityUser, RoleConstants.Role.User).ToClaim(); AddClaimsAsync(identityUser, new[] { claim }, cancellationToken); var savedClaims = _userClaimRepository.GetSpecificClaimByUserId(identityUser.Id, claim.Type, claim.Value); identityUser.UserClaims = Mapper.Map <IList <AppIdentityUserClaim> >(savedClaims); UpdateAsync(identityUser, cancellationToken); return(Task.FromResult(IdentityResult.Success)); }
public override Task AddClaimsAsync(AppIdentityUser identityUser, IEnumerable <Claim> claims, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (identityUser == null) { throw new ArgumentNullException(nameof(identityUser)); } if (claims == null) { throw new ArgumentNullException(nameof(claims)); } var user = _userRepository.Get(identityUser.Id); if (user == null) { return(Task.FromResult(IdentityResult.Failed( new IdentityError { Code = "UserNotFound", Description = $"User with id {user.Id} not found" }))); } foreach (var claim in claims) { var newClaim = CreateUserClaim(identityUser, claim); var userClaim = Mapper.Map <UserClaimDTO>(newClaim); userClaim.User = user; _userClaimManager.Create(userClaim); } return(Task.FromResult(IdentityResult.Success)); }
public override Task RemoveClaimsAsync(AppIdentityUser identityUser, IEnumerable <Claim> claims, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (identityUser == null) { throw new ArgumentNullException(nameof(identityUser)); } if (claims == null) { throw new ArgumentNullException(nameof(claims)); } foreach (var claim in claims) { var userClaims = _userClaimRepository.GetSpecificClaimByUserId(identityUser.Id, claim.Type, claim.Value); foreach (var userClaim in userClaims) { _userClaimManager.Delete(userClaim); } } return(Task.FromResult(IdentityResult.Success)); }
public override Task ReplaceClaimAsync(AppIdentityUser identityUser, Claim claim, Claim newClaim, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (identityUser == null) { throw new ArgumentNullException(nameof(identityUser)); } if (claim == null) { throw new ArgumentNullException(nameof(claim)); } if (newClaim == null) { throw new ArgumentNullException(nameof(newClaim)); } var matchedClaims = _userClaimRepository.GetSpecificClaimByUserId(identityUser.Id, claim.Type, claim.Value); foreach (var matchedClaim in matchedClaims) { matchedClaim.ClaimType = newClaim.Type; matchedClaim.ClaimValue = newClaim.Value; _userClaimManager.Save(matchedClaim); } return(Task.FromResult(IdentityResult.Success)); }
public override Task SetPasswordHashAsync(AppIdentityUser identityUser, string passwordHash, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (identityUser == null) { throw new ArgumentNullException(nameof(identityUser)); } return(Task.FromResult(identityUser.PasswordHash = passwordHash)); }
public override Task <bool> HasPasswordAsync(AppIdentityUser identityUser, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (identityUser == null) { throw new ArgumentNullException(nameof(identityUser)); } return(Task.FromResult(!string.IsNullOrEmpty(identityUser.PasswordHash) && string.IsNullOrWhiteSpace(identityUser.PasswordHash) && identityUser.PasswordHash.Length > 0)); }
public override Task SetUserNameAsync(AppIdentityUser identityUser, string userName, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (identityUser == null) { throw new ArgumentNullException(nameof(identityUser)); } return(Task.FromResult(identityUser.UserName = userName)); }
public override Task <string> GetUserIdAsync(AppIdentityUser identityUser, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (identityUser == null) { throw new ArgumentNullException(nameof(identityUser)); } return(Task.FromResult(identityUser.Id.ToString())); }
public override Task <IdentityResult> DeleteAsync(AppIdentityUser identityUser, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (identityUser == null) { throw new ArgumentNullException(nameof(identityUser)); } var user = Mapper.Map <UserDTO>(identityUser); _userManager.Delete(user); return(Task.FromResult(IdentityResult.Success)); }
public override Task <IList <Claim> > GetClaimsAsync(AppIdentityUser identityUser, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); if (identityUser == null) { throw new ArgumentNullException(nameof(identityUser)); } var claims = _userClaimRepository.GetByUserId(identityUser.Id) .Select(Mapper.Map <AppIdentityUserClaim>) .Select(x => x.ToClaim()) .ToList() as IList <Claim>; return(Task.FromResult(claims)); }
public AppIdentityUserClaim(AppIdentityUser identityUser, RoleConstants.Role role) { UserId = identityUser.Id; ClaimType = ClaimTypes.Role; ClaimValue = role.ToString(); }
protected override Task <IdentityUserToken <int> > FindTokenAsync(AppIdentityUser user, string loginProvider, string name, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public override Task <IList <UserLoginInfo> > GetLoginsAsync(AppIdentityUser user, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); }
public override Task RemoveLoginAsync(AppIdentityUser user, string loginProvider, string providerKey, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); }
public override Task AddLoginAsync(AppIdentityUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken)) { throw new NotImplementedException(); }
private void Map(AppIdentityUser identityUser, UserDTO user) { Mapper.Map(identityUser, user); }