Ejemplo n.º 1
0
        public ActionResult EditSection(long?sectionId = null)
        {
            pageResourceManager.InsertTitlePart("帖吧设置");
            if (sectionId.HasValue)
            {
                BarSection section = barSectionService.Get(sectionId ?? 0);
                if (section == null)
                {
                    return(HttpNotFound());
                }
                ViewData["UserId"]         = section.UserId;
                ViewData["ManagerUserIds"] = barSectionService.GetSectionManagers(sectionId ?? 0).Select(n => n.UserId);
                IBarSettingsManager manager  = DIContainer.Resolve <IBarSettingsManager>();
                BarSettings         settings = manager.Get();
                ViewData["SectionManagerMaxCount"] = settings.SectionManagerMaxCount;

                BarSectionEditModel    model      = section.AsEditModel();
                IEnumerable <Category> categories = categoryService.GetCategoriesOfItem(section.SectionId, 0, TenantTypeIds.Instance().BarSection());
                if (categories != null && categories.Count() > 0)
                {
                    model.CategoryId = categories.ElementAt(0).CategoryId;
                }

                return(View(model));
            }
            else
            {
                ViewData["UserId"] = UserContext.CurrentUser.UserId;
            }
            return(View(new BarSectionEditModel()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 是否具有创建BarSection的权限
        /// </summary>
        /// <returns></returns>
        public static bool BarSection_Create(this Authorizer authorizer)
        {
            IUser currentUser = UserContext.CurrentUser;

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

            if (authorizer.IsAdministrator(BarConfig.Instance().ApplicationId))
            {
                return(true);
            }

            IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
            BarSettings         barSetting         = barSettingsManager.Get();

            if (!barSetting.EnableUserCreateSection)
            {
                return(false);
            }
            if (currentUser.Rank < barSetting.UserRankOfCreateSection)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        public ActionResult SectionSettings(SectionSettingsEditModel model)
        {
            IBarSettingsManager manager = DIContainer.Resolve <IBarSettingsManager>();

            manager.Save(model.AsBarSettings());

            TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "保存设置成功");

            return(Redirect(SiteUrls.Instance().SectionSettings()));
        }
Ejemplo n.º 4
0
        public ActionResult SectionSettings()
        {
            IEnumerable <PointCategory> pointCategories = pointService.GetPointCategories();

            ViewData["prePoint"] = pointCategories.FirstOrDefault(n => n.CategoryKey.Equals("ReputationPoints")).CategoryName;

            IBarSettingsManager manager  = DIContainer.Resolve <IBarSettingsManager>();
            BarSettings         settings = manager.Get();

            return(View(settings.AsEditModel()));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 是否具有评分的权限
        /// </summary>
        /// <returns></returns>
        public static bool BarRating(this Authorizer authorizer, BarThread thread, out string errorMessage)
        {
            BarSettings barSettings = DIContainer.Resolve <IBarSettingsManager>().Get();

            errorMessage = "没有找到对应的帖子";
            if (thread == null)
            {
                return(false);
            }
            errorMessage = "您还没有登录";
            IUser currentUser = UserContext.CurrentUser;

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

            if (thread.UserId == currentUser.UserId)
            {
                errorMessage = "您不可以给自己的帖子评分哦";
                return(false);
            }

            BarRatingService barRatingService = new BarRatingService();

            //是否已经评过分
            errorMessage = "您已经评论过此贴";
            if (barRatingService.IsRated(currentUser.UserId, thread.ThreadId))
            {
                return(false);
            }
            errorMessage = "您的剩余积分不够了哦";
            if (barRatingService.GetUserTodayRatingSum(UserContext.CurrentUser.UserId) + barSettings.ReputationPointsMinValue > barSettings.UserReputationPointsPerDay)
            {
                return(false);
            }

            IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
            BarSettings         barSetting         = barSettingsManager.Get();
            BarSectionService   barSectionService  = new BarSectionService();
            var barSection = barSectionService.Get(thread.SectionId);

            if (barSection == null)
            {
                return(false);
            }
            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                errorMessage = "此帖吧仅允许关注的用户评分哦";
                if (barSetting.OnlyFollowerCreatePost)
                {
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    return(subscribeService.IsSubscribed(thread.SectionId, currentUser.UserId));
                }
            }
            else
            {
                if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId))
                {
                    return(true);
                }
            }

            errorMessage = "站点没有开启帖子评分";
            if (!barSetting.EnableRating)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 是否具有创建BarPost的权限
        /// </summary>
        /// <param name="sectionId">所属帖吧Id</param>
        /// <returns></returns>
        public static bool BarPost_Create(this Authorizer authorizer, long sectionId, out string errorMessage)
        {
            IUser currentUser = UserContext.CurrentUser;

            errorMessage = "没有权限回帖";
            BarSectionService barSectionService = new BarSectionService();
            var barSection = barSectionService.Get(sectionId);

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

            if (barSection.AuditStatus != AuditStatus.Success)
            {
                errorMessage = "由于贴吧未经过审核,所以不允许发帖";
                return(false);
            }

            if (!authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Bar_CreatePost()))
            {
                if (currentUser != null && currentUser.IsModerated)
                {
                    errorMessage = Resources.Resource.Description_ModeratedUser_CreateBarPostDenied;
                }
                return(false);
            }

            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                //检查是否需要是关注用户才能发帖
                IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
                BarSettings         barSetting         = barSettingsManager.Get();
                if (barSetting.OnlyFollowerCreatePost)
                {
                    if (currentUser == null)
                    {
                        errorMessage = "您需要先登录并关注此帖吧,才能回帖";
                        return(false);
                    }
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    bool             isSubscribed     = subscribeService.IsSubscribed(sectionId, currentUser.UserId);
                    if (!isSubscribed)
                    {
                        errorMessage = "您需要先关注此帖吧,才能回帖";
                    }
                    return(isSubscribed);
                }
            }
            else
            {
                if (authorizer.BarSection_Manage(barSection))
                {
                    return(true);
                }
                bool isTenantMember = authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId);
                if (!isTenantMember)
                {
                    errorMessage = "您需要先加入,才能回帖";
                }
                return(isTenantMember);
            }

            //站点设置是否启用了匿名发帖
            ISiteSettingsManager siteSettingsManager = DIContainer.Resolve <ISiteSettingsManager>();
            SiteSettings         siteSettings        = siteSettingsManager.Get();

            if (siteSettings.EnableAnonymousPosting)
            {
                return(true);
            }

            if (currentUser == null)
            {
                errorMessage = "您必须先登录,才能回帖";
                return(false);
            }
            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 是否具有创建BarThread的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="sectionId">所属帖吧Id</param>
        /// <param name="errorMessage">无权信息提示</param>
        /// <returns></returns>
        public static bool BarThread_Create(this Authorizer authorizer, long sectionId, out string errorMessage)
        {
            errorMessage = string.Empty;
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                errorMessage = "您需要先登录,才能发帖";
                return(false);
            }
            BarSectionService barSectionService = new BarSectionService();
            var barSection = barSectionService.Get(sectionId);

            if (barSection == null)
            {
                errorMessage = "贴吧不存在";
                return(false);
            }

            if (authorizer.BarSection_Manage(barSection))
            {
                return(true);
            }

            if (!authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Bar_CreateThread()))
            {
                if (currentUser.IsModerated)
                {
                    errorMessage = Resources.Resource.Description_ModeratedUser_CreateBarThreadDenied;
                }
                return(false);
            }
            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
                BarSettings         barSetting         = barSettingsManager.Get();
                if (barSetting.OnlyFollowerCreateThread)
                {
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    if (subscribeService.IsSubscribed(sectionId, currentUser.UserId))
                    {
                        return(true);
                    }
                    else
                    {
                        errorMessage = "您需要先关注此帖吧,才能发帖";
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId))
                {
                    return(true);
                }
                else
                {
                    TenantType tenantType = new TenantTypeService().Get(barSection.TenantTypeId);
                    errorMessage = string.Format("只有加入{0}才能发帖", tenantType.Name);
                    return(false);
                }
            }
        }
Ejemplo n.º 8
0
        public ActionResult EditSection(BarSectionEditModel model)
        {
            HttpPostedFileBase logoImage         = Request.Files["LogoImage"];
            string             logoImageFileName = string.Empty;
            Stream             stream            = null;

            if (logoImage != null && !string.IsNullOrEmpty(logoImage.FileName))
            {
                TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().BarSection());
                if (!tenantLogoSettings.ValidateFileLength(logoImage.ContentLength))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("Logo文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024)));
                    return(View(model));
                }

                LogoSettings logoSettings = DIContainer.Resolve <ILogoSettingsManager>().Get();
                if (!logoSettings.ValidateFileExtensions(logoImage.FileName))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "Logo文件是不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions);
                    return(View(model));
                }
                stream            = logoImage.InputStream;
                logoImageFileName = logoImage.FileName;
            }


            IEnumerable <long> managerUserIds = Request.Form.Gets <long>("ManagerUserIds");

            if (model.SectionId == 0)
            {
                BarSection section = model.AsBarSection();

                //long userId = Request.QueryString.Gets<long>(model.UserId, new List<long>()).FirstOrDefault();


                section.UserId = Request.Form.Gets <long>("UserId", new List <long>()).FirstOrDefault();
                if (section.UserId == 0)
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "请输入吧主信息");
                    return(View(model));
                }
                section.LogoImage    = logoImageFileName;
                section.DisplayOrder = model.DisplayOrder ?? 100;
                if (managerUserIds != null && managerUserIds.Count() > 0)
                {
                    managerUserIds = managerUserIds.Where(n => n != section.UserId);
                }

                bool isCreated = barSectionService.Create(section, UserContext.CurrentUser.UserId, managerUserIds, stream);

                categoryService.AddItemsToCategory(new List <long> {
                    section.SectionId
                }, model.CategoryId, 0);

                if (isCreated)
                {
                    TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "创建成功");
                    return(Redirect(SiteUrls.Instance().EditSection(section.SectionId)));
                }
                ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "创建失败");
                return(View(model));
            }
            else
            {
                BarSection section = model.AsBarSection();



                long userId = Request.Form.Gets <long>("UserId", new List <long>()).FirstOrDefault();
                if (userId == 0)
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "必须输入吧主信息");
                    ViewData["ManagerUserIds"]    = barSectionService.GetSectionManagers(section.SectionId).Select(n => n.UserId);
                    IBarSettingsManager manager  = DIContainer.Resolve <IBarSettingsManager>();
                    BarSettings         settings = manager.Get();
                    ViewData["SectionManagerMaxCount"] = settings.SectionManagerMaxCount;
                    return(View(model));
                }
                section.UserId = userId;
                if (!string.IsNullOrEmpty(logoImageFileName))
                {
                    section.LogoImage = logoImageFileName;
                }
                section.DisplayOrder = model.DisplayOrder ?? 100;
                barSectionService.Update(section, UserContext.CurrentUser.UserId, managerUserIds, stream);
                categoryService.ClearCategoriesFromItem(section.SectionId, 0, TenantTypeIds.Instance().BarSection());
                categoryService.AddItemsToCategory(new List <long> {
                    section.SectionId
                }, model.CategoryId, 0);

                TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功");
                return(Redirect(SiteUrls.Instance().EditSection(model.SectionId)));
            }
        }