public async Task <IdentityResponse> HasClaimAsync(ApplicationUser user, Claim claim) { var claims = await _userManager.GetClaimsAsync(user); return(claims.Any(x => x.Type == claim.Type && x.Value == claim.Value) ? IdentityResponse.Success("Claim Exists") : IdentityResponse.Fail("Claim does not exist")); }
public async Task <IdentityResponse> RemoveFromRoleAsync(ApplicationUser user, string roleName) { if (roleName == DefaultApplicationRoles.SuperAdmin) { return(IdentityResponse.Fail("Can not to delete superAdmin role")); } var rs = await _userManager.RemoveFromRoleAsync(user, roleName); return(rs.ToIdentityResponse()); }
public async Task <IdentityResponse> RegisterUserAsync(ApplicationUser user) { if (user.Email != null && await _userManager.FindByEmailAsync(user.Email) != null) { return(IdentityResponse.Fail("Email already exists! Please try a different one!")); } user.UserName ??= user.Email; if (user.UserName != null && await _userManager.FindByNameAsync(user.UserName) != null) { return(IdentityResponse.Fail("User Name already exists! Please try a different one")); } var rs = await _userManager.CreateAsync(user); return(rs.ToIdentityResponse()); }
public async Task <IdentityResponse> PasswordSignInAsync(ApplicationUser user, string password, bool isPersistent, bool lockoutOnFailure) { var rs = await _signInManager.PasswordSignInAsync(user, password, isPersistent, lockoutOnFailure); return(rs.Succeeded ? IdentityResponse.Success(rs.ToString()) : IdentityResponse.Fail(rs.ToString())); }
public static IdentityResponse ToIdentityResponse(this IdentityResult identityResult) { return(identityResult.Succeeded ? IdentityResponse.Success(identityResult.ToString()) : IdentityResponse.Fail(identityResult.ToString())); }