Exemplo n.º 1
0
        public async Task <TUser> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            int.TryParse(userId, out var id);

            if (id > 0)
            {
                return(await userRepository.GetById(id, session, true));
            }

            return(null);
        }
Exemplo n.º 2
0
        public async Task <TUser> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();

            Guid.TryParse(userId, out var id);

            if (!string.IsNullOrEmpty(id.ToString()))
            {
                return(await userRepository.GetById(id, session));
            }

            return(null);
        }
Exemplo n.º 3
0
        public async Task GetProfileDataAsync(ProfileDataRequestContext context)
        {
            var claims = new List <Claim>();

            claims.AddRange(context.Subject.Claims);
            string tenantId = "";

            context.Client.Properties.TryGetValue(SecurityInfraClaimTypes.TenantId, out tenantId);
            var userId = context.Subject.Identity.GetSubjectId();
            var user   = await _identityUserRepository.GetById(userId);

            if (user != null && user.State == IdentityUserState.VALID)
            {
                var roles = user.GetCurrentRoles()
                            .Where(x => x.TenantId == tenantId &&
                                   x.State == IdentityUserRoleState.VALID);
                foreach (var role in roles)
                {
                    claims.Add(new Claim(JwtClaimTypes.Role, role.Role));
                    if (!string.IsNullOrEmpty(role.DepartmentType) ||
                        !string.IsNullOrEmpty(role.Rule))
                    {
                        dynamic roleExt = new JObject();
                        roleExt.name = role.Role;
                        if (!string.IsNullOrEmpty(role.DepartmentType))
                        {
                            roleExt.department_type  = role.DepartmentType;
                            roleExt.department_value = role.DepartmentValue;
                        }
                        if (!string.IsNullOrEmpty(role.Rule))
                        {
                            roleExt.rule = role.Rule;
                        }
                        claims.Add(new Claim("role_ext", roleExt.ToString()));
                    }
                }
            }
            claims.Add(new Claim(SecurityInfraClaimTypes.TenantId, tenantId));
            context.IssuedClaims = claims;
            await Task.CompletedTask;
        }
Exemplo n.º 4
0
        public ActionConfirmation Delete(string userId)
        {
            var user = _userRepository.GetById(userId);

            if (user != null)
            {
                try
                {
                    _userRepository.Delete(user);
                    _userRepository.DbContext.CommitChanges();

                    return(ActionConfirmation.CreateSuccess("user deleted"));
                }
                catch (Exception exception)
                {
                    return(ActionConfirmation.CreateFailure("error > " + exception.Message));
                }
            }
            else
            {
                return(ActionConfirmation.CreateFailure("user does not exist"));
            }
        }
        public async Task <TApplicationUser> FindByIdAsync(int userId)
        {
            var baseUser = await userRepository.GetById(userId, session, true);

            return(baseUser.MapTo <TApplicationUser>());
        }