示例#1
0
        /// <summary>
        /// ApplicationUser Find By Name.
        /// </summary>
        /// <param name="userName">User Name</param>
        /// <returns>ApplicationUser</returns>
        public Task <ApplicationUser> FindByNameAsync(string userName)
        {
            UserInfoDomain user;

            try
            {
                IUserManagementApplicationService Service = Container.Resolve <IUserManagementApplicationService>();
                user = Service.GetUserInfo(userName);

                if (user == null)
                {
                    return(Task.FromResult <ApplicationUser>(null));
                }
                var result = new ApplicationUser()
                {
                    Id           = user.UserId.ToString(),
                    UserId       = user.UserId,
                    Name         = user.Name,
                    PasswordHash = user.Password,
                    UserName     = user.Name,
                };

                return(Task.FromResult(result));
            }
            catch (Exception ex)
            {
            }

            return(Task.FromResult(new ApplicationUser()));
        }
        public static void ClassInit(TestContext context)
        {
            var container = new UnityContainer();

            DomainUnityContainer.BuildUp(container);
            InfrastructureUnityContainer.BuildUp(container);
            UserAppService = container.Resolve <IUserManagementApplicationService>();
        }
示例#3
0
        /// <summary>
        /// Get Roles.
        /// </summary>
        /// <param name="user">ApplicationUser</param>
        /// <returns>Roles</returns>
        public Task <IList <string> > GetRolesAsync(ApplicationUser user)
        {
            IList <string> result;
            IUserManagementApplicationService Service = Container.Resolve <IUserManagementApplicationService>();

            result = Service.GetRoles(int.Parse(user.Id));

            return(Task.FromResult(result));
        }
示例#4
0
        /// <summary>
        /// Create Identity.
        /// </summary>
        /// <param name="user">ApplicationUser</param>
        /// <param name="authenticationType">AuthenticationType</param>
        /// <returns>Identity</returns>
        public override async Task <ClaimsIdentity> CreateIdentityAsync(ApplicationUser user, string authenticationType)
        {
            var identity = await base.CreateIdentityAsync(user, authenticationType);

            // Set UserAccount
            identity.AddClaim(new Claim(ClaimTypes.GivenName, user.Name));
            // Set Role Function
            IUserManagementApplicationService Service = Container.Resolve <IUserManagementApplicationService>();
            var functions = Service.GetRoleFunctions(int.Parse(user.Id));

            identity.AddClaims(functions.Select(f => new Claim("function", f.FunctionName)));
            return(identity);
        }