예제 #1
0
        public bool HasRole(int userId, string roleName)
        {
            TeamTasksUser user = userManager.FindByIdAsync(userId.ToString()).Result;

            if (user == null)
            {
                return(false);
            }

            return(userManager.IsInRoleAsync(user, roleName).Result);
        }
예제 #2
0
        public bool UserExists(int userId)
        {
            TeamTasksUser user = userManager.FindByIdAsync(userId.ToString()).Result;

            if (user == null)
            {
                return(false);
            }

            return(true);
        }
예제 #3
0
        public async Task <bool> AreUserCredentialsValidAsync(string username, string password)
        {
            TeamTasksUser user = await _userManager.FindByNameAsync(username);

            if (user == null)
            {
                return(false);
            }

            return(await _userManager.CheckPasswordAsync(user, password));
        }
예제 #4
0
        public static async Task <AuthenticatedInfo> ResolveAuthenticatedEntitiesAsync(this Controller controller, TeamTasksDbContext context,
                                                                                       UserManager <TeamTasksUser> userManager)
        {
            string        username = controller.Request.HttpContext.User?.Identity?.Name ?? "";
            TeamTasksUser user     = await userManager.FindByNameAsync(username);

            int userId = user?.Id ?? 0;

            return(new AuthenticatedInfo
            {
                UserId = userId
            });
        }
예제 #5
0
        public static async Task <bool> IsUserAdminAsync(this Controller controller, UserManager <TeamTasksUser> UM)
        {
            if (String.IsNullOrEmpty(controller.User.Identity.Name))
            {
                return(false);
            }

            TeamTasksUser user = await UM.FindByNameAsync(controller.User.Identity.Name);

            if (user == null)
            {
                return(false);
            }

            return(await UM.IsInRoleAsync(user, RoleNames.Administrator));
        }
예제 #6
0
        public List <KeyValuePair <string, string> > GetAdditionalUserClaims(string username)
        {
            TeamTasksUser user = userManager.FindByNameAsync(username).Result;

            if (user != null)
            {
                IList <string> roles = userManager.GetRolesAsync(user).Result;

                List <KeyValuePair <string, string> > claims = new List <KeyValuePair <string, string> >();

                // Add roles first
                foreach (string role in roles)
                {
                    claims.Add(new KeyValuePair <string, string>(ClaimTypes.Role, role));
                }

                return(claims);
            }

            return(null);
        }
예제 #7
0
        protected override void SetOtherAuthServerResponseProperties(AuthServerRequest authRequest, TeamTasksAuthServerResponse authServerResponse)
        {
            TeamTasksUser user = um.FindByNameAsync(authRequest.Username).Result;

            authServerResponse.Roles = um.GetRolesAsync(user).Result.ToList();
        }