コード例 #1
0
        public override async Task <IList <MangoUser> > GetUsersInRoleAsync(string roleName, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (roleName == null)
            {
                throw new ArgumentNullException(nameof(roleName));
            }
            IList <MangoUser> mangoUsers = new List <MangoUser>();
            var userEntities             = await _userDbContext.MangoUsers.Join(_userDbContext.User2Roles, ue => ue.Id, u2r => u2r.UserId, (ue, u2r) => new UserEntity
            {
                Id            = ue.Id,
                Email         = ue.Email,
                LoginName     = ue.LoginName,
                UserName      = ue.UserName,
                CreateDate    = ue.CreateDate,
                LastLoginDate = ue.LastLoginDate,
                Password      = ue.Password
            }).ToListAsync();

            foreach (UserEntity userEntity in userEntities)
            {
                mangoUsers.Add(MEConversion.UserE2M(userEntity));
            }

            return(mangoUsers);
        }
コード例 #2
0
        public override async Task <MangoUser> FindByLoginAsync(string loginProvider, string providerKey, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (loginProvider == null)
            {
                throw new ArgumentNullException(nameof(loginProvider));
            }
            if (providerKey == null)
            {
                throw new ArgumentNullException(nameof(providerKey));
            }

            ExternalLoginEntity exl = await _userDbContext.ExternalLogins.FirstOrDefaultAsync(ex => ex.LoginProvider == loginProvider && ex.ProviderKey == providerKey);

            if (exl == null)
            {
                return(null);
            }
            UserEntity userEntity = await _userDbContext.MangoUsers.FirstOrDefaultAsync(ex => ex.Id == exl.UserId);

            if (userEntity == null)
            {
                throw new UserNotFoundException($"method:{nameof(FindByLoginAsync)},没有找到id为:{exl.UserId}的用户");
            }
            return(MEConversion.UserE2M(userEntity));
        }
コード例 #3
0
        /// <summary>
        /// 输入参数的username经过UserManger的格式化处理
        /// </summary>
        /// <param name="loginName">用户名</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override async Task <MangoUser> FindByNameAsync(string username, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            UserEntity userEntity = await _userDbContext.MangoUsers.FirstOrDefaultAsync(u => u.LoginName == username);

            if (userEntity == null)
            {
                return(null);
            }
            return(MEConversion.UserE2M(userEntity));
        }
コード例 #4
0
        public override async Task <MangoUser> FindByIdAsync(int userId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            UserEntity userEntity = await _userDbContext.MangoUsers.FirstOrDefaultAsync(u => u.Id == userId);

            if (userEntity == null)
            {
                return(null);
            }
            return(MEConversion.UserE2M(userEntity));
        }
コード例 #5
0
        public override async Task <MangoUser> FindByEmailAsync(string normalizedEmail, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (normalizedEmail == null)
            {
                throw new ArgumentNullException(nameof(normalizedEmail));
            }

            UserEntity userEntity = await _userDbContext.MangoUsers.FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail);

            if (userEntity == null)
            {
                return(null);
            }
            return(MEConversion.UserE2M(userEntity));
        }