コード例 #1
0
        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"));
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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()));
        }
コード例 #5
0
 public static IdentityResponse ToIdentityResponse(this IdentityResult identityResult)
 {
     return(identityResult.Succeeded
         ? IdentityResponse.Success(identityResult.ToString())
         : IdentityResponse.Fail(identityResult.ToString()));
 }