Example #1
0
        /// <summary>
        /// 删除实体信息信息
        /// </summary>
        /// <param name="ids">要删除的实体信息编号</param>
        /// <returns>业务操作结果</returns>
        public Task <OperationResult> DeleteUserLogins(params Guid[] ids)
        {
            return(UserLoginRepository.DeleteAsync(ids,
                                                   entity =>
            {
                int userId = CurrentUser.Identity.GetUserId <int>();
                if (entity.UserId != userId)
                {
                    throw new OsharpException("要解除的第三方登录绑定不属于当前用户");
                }

                var user = UserManager.Users.Where(m => m.Id == userId).Select(m => new { m.PasswordHash, m.NormalizeEmail }).First();
                if ((string.IsNullOrEmpty(user.PasswordHash) || string.IsNullOrEmpty(user.NormalizeEmail)) &&
                    UserLoginRepository.QueryAsNoTracking(m => m.UserId == entity.UserId).Count() == 1)
                {
                    throw new OsharpException("当前用户未设置登录密码,并且要解除的第三方登录是唯一登录方式,无法解除");
                }
                return Task.FromResult(0);
            }));
        }