当前位置: 首页>>代码示例>>C#>>正文


C# NuGetGallery.ReportAbuseViewModel类代码示例

本文整理汇总了C#中NuGetGallery.ReportAbuseViewModel的典型用法代码示例。如果您正苦于以下问题:C# ReportAbuseViewModel类的具体用法?C# ReportAbuseViewModel怎么用?C# ReportAbuseViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ReportAbuseViewModel类属于NuGetGallery命名空间,在下文中一共展示了ReportAbuseViewModel类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReportMyPackage

        public virtual ActionResult ReportMyPackage(string id, string version)
        {
            var user = _userService.FindByUsername(HttpContext.User.Identity.Name);

            var package = _packageService.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return HttpNotFound();
            }

            // If user hit this url by constructing it manually but is not the owner, redirect them to ReportAbuse
            if (!(HttpContext.User.IsInRole(Constants.AdminRoleName) || package.IsOwner(user)))
            {
                return RedirectToAction(ActionNames.ReportAbuse, new { id, version });
            }

            var model = new ReportAbuseViewModel
            {
                ReasonChoices = ReportMyPackageReasons,
                ConfirmedUser = user.Confirmed,
                PackageId = id,
                PackageVersion = package.Version,
            };

            return View(model);
        }
开发者ID:ryanhartley84332,项目名称:NuGetGallery,代码行数:27,代码来源:PackagesController.cs

示例2: ReportMyPackage

        public virtual ActionResult ReportMyPackage(string id, string version, ReportAbuseViewModel reportForm)
        {
            // Html Encode the message
            reportForm.Message = System.Web.HttpUtility.HtmlEncode(reportForm.Message);

            if (!ModelState.IsValid)
            {
                return ReportMyPackage(id, version);
            }

            var package = _packageService.FindPackageByIdAndVersion(id, version);
            if (package == null)
            {
                return HttpNotFound();
            }

            var user = GetCurrentUser();
            MailAddress from = user.ToMailAddress();

            _messageService.ReportMyPackage(
                new ReportPackageRequest
                {
                    FromAddress = from,
                    Message = reportForm.Message,
                    Package = package,
                    Reason = EnumHelper.GetDescription(reportForm.Reason.Value),
                    RequestingUser = user,
                    Url = Url,
                    CopySender = reportForm.CopySender
                });

            TempData["Message"] = "Your support request has been sent to the gallery operators.";
            return Redirect(Url.Package(id, version));
        }
开发者ID:rodwin,项目名称:NuGetGallery,代码行数:34,代码来源:PackagesController.cs

示例3: ReportAbuse

        public virtual ActionResult ReportAbuse(string id, string version)
        {
            var package = _packageService.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return HttpNotFound();
            }

            var model = new ReportAbuseViewModel
            {
                ReasonChoices = ReportOtherPackageReasons,
                PackageId = id,
                PackageVersion = package.Version,
            };

            if (Request.IsAuthenticated)
            {
                var user = _userService.FindByUsername(HttpContext.User.Identity.Name);

                // If user logged on in as owner a different tab, then clicked the link, we can redirect them to ReportMyPackage
                if (package.IsOwner(user))
                {
                    return RedirectToAction(ActionNames.ReportMyPackage, new {id, version});
                }

                if (user.Confirmed)
                {
                    model.ConfirmedUser = true;
                }
            }

            ViewData[Constants.ReturnUrlViewDataKey] = Url.Action(ActionNames.ReportMyPackage, new {id, version});
            return View(model);
        }
开发者ID:ryanhartley84332,项目名称:NuGetGallery,代码行数:35,代码来源:PackagesController.cs

示例4: SendsMessageToGalleryOwnerWithUserInfoWhenAuthenticated

            public void SendsMessageToGalleryOwnerWithUserInfoWhenAuthenticated()
            {
                var messageService = new Mock<IMessageService>();
                messageService.Setup(
                    s => s.ReportAbuse(It.Is<ReportPackageRequest>(r => r.Message == "Mordor took my finger")));
                var package = new Package
                    {
                        PackageRegistration = new PackageRegistration { Id = "mordor" },
                        Version = "2.0.1"
                    };
                var packageService = new Mock<IPackageService>();
                packageService.Setup(p => p.FindPackageByIdAndVersion("mordor", It.IsAny<string>(), true)).Returns(package);
                var httpContext = new Mock<HttpContextBase>();
                httpContext.Setup(h => h.Request.IsAuthenticated).Returns(true);
                httpContext.Setup(h => h.User.Identity.Name).Returns("Frodo");
                var userService = new Mock<IUserService>();
                userService.Setup(u => u.FindByUsername("Frodo")).Returns(new User { EmailAddress = "[email protected]", Username = "Frodo", Key = 1 });
                var controller = CreateController(
                    packageService: packageService,
                    messageService: messageService,
                    userService: userService,
                    httpContext: httpContext);
                var model = new ReportAbuseViewModel
                    {
                        Message = "Mordor took my finger",
                        Reason = ReportPackageReason.IsFraudulent,
                    };

                TestUtility.SetupUrlHelper(controller, httpContext);
                ActionResult result = controller.ReportAbuse("mordor", "2.0.1", model) as RedirectResult;

                Assert.NotNull(result);
                userService.VerifyAll();
                messageService.Verify(
                    s => s.ReportAbuse(
                        It.Is<ReportPackageRequest>(
                            r => r.Message == "Mordor took my finger"
                                 && r.FromAddress.Address == "[email protected]"
                                 && r.FromAddress.DisplayName == "Frodo"
                                 && r.Reason == EnumHelper.GetDescription(ReportPackageReason.IsFraudulent))));
            }
开发者ID:projectkudu,项目名称:NuGetGallery,代码行数:41,代码来源:PackagesControllerFacts.cs

示例5: ReportAbuse

        public virtual ActionResult ReportAbuse(string id, string version, ReportAbuseViewModel reportForm)
        {
            // Html Encode the message
            reportForm.Message = System.Web.HttpUtility.HtmlEncode(reportForm.Message);

            if (!ModelState.IsValid)
            {
                return ReportAbuse(id, version);
            }

            var package = _packageService.FindPackageByIdAndVersion(id, version);
            if (package == null)
            {
                return HttpNotFound();
            }

            User user = null;
            MailAddress from;
            if (Request.IsAuthenticated)
            {
                user = GetCurrentUser();
                from = user.ToMailAddress();
            }
            else
            {
                from = new MailAddress(reportForm.Email);
            }

            var request = new ReportPackageRequest
            {
                AlreadyContactedOwners = reportForm.AlreadyContactedOwner,
                FromAddress = from,
                Message = reportForm.Message,
                Package = package,
                Reason = EnumHelper.GetDescription(reportForm.Reason.Value),
                RequestingUser = user,
                Url = Url,
                CopySender = reportForm.CopySender,
                Signature = reportForm.Signature
            };
            _messageService.ReportAbuse(request);

            TempData["Message"] = "Your abuse report has been sent to the gallery operators.";
            return Redirect(Url.Package(id, version));
        }
开发者ID:rodwin,项目名称:NuGetGallery,代码行数:45,代码来源:PackagesController.cs

示例6: ReportMyPackage

        public virtual async Task<ActionResult> ReportMyPackage(string id, string version, ReportAbuseViewModel reportForm)
        {
            // Html Encode the message
            reportForm.Message = System.Web.HttpUtility.HtmlEncode(reportForm.Message);

            if (!ModelState.IsValid)
            {
                return ReportMyPackage(id, version);
            }

            var package = _packageService.FindPackageByIdAndVersion(id, version);
            if (package == null)
            {
                return HttpNotFound();
            }

            var user = GetCurrentUser();
            MailAddress from = user.ToMailAddress();

            var request = new ReportPackageRequest
            {
                FromAddress = from,
                Message = reportForm.Message,
                Package = package,
                Reason = EnumHelper.GetDescription(reportForm.Reason.Value),
                RequestingUser = user,
                Url = Url,
                CopySender = reportForm.CopySender
            };

            var subject = $"Owner Support Request for '{package.PackageRegistration.Id}' version {package.Version}";
            var requestorEmailAddress = user != null ? user.EmailAddress : reportForm.Email;
            var reason = EnumHelper.GetDescription(reportForm.Reason.Value);

            await _supportRequestService.AddNewSupportRequestAsync(subject, reportForm.Message, requestorEmailAddress, reason, user, package);

            _messageService.ReportMyPackage(request);

            TempData["Message"] = "Your support request has been sent to the gallery operators.";
            return Redirect(Url.Package(id, version));
        }
开发者ID:rhysawilliams2010,项目名称:NuGetGallery,代码行数:41,代码来源:PackagesController.cs

示例7: SendsMessageToGalleryOwnerWithEmailOnlyWhenUnauthenticated

            public void SendsMessageToGalleryOwnerWithEmailOnlyWhenUnauthenticated()
            {
                var messageService = new Mock<IMessageService>();
                messageService.Setup(
                    s => s.ReportAbuse(It.Is<ReportPackageRequest>(r => r.Message == "Mordor took my finger")));
                var package = new Package
                    {
                        PackageRegistration = new PackageRegistration { Id = "mordor" },
                        Version = "2.0.1"
                    };
                var packageService = new Mock<IPackageService>();
                packageService.Setup(p => p.FindPackageByIdAndVersion("mordor", "2.0.1", true)).Returns(package);
                var httpContext = new Mock<HttpContextBase>();
                httpContext.Setup(h => h.Request.IsAuthenticated).Returns(false);
                var controller = CreateController(
                    packageService: packageService,
                    messageService: messageService,
                    httpContext: httpContext);
                var model = new ReportAbuseViewModel
                    {
                        Email = "[email protected]",
                        Message = "Mordor took my finger.",
                        Reason = ReportPackageReason.IsFraudulent,
                        AlreadyContactedOwner = true,
                    };

                TestUtility.SetupUrlHelper(controller, httpContext);
                var result = controller.ReportAbuse("mordor", "2.0.1", model) as RedirectResult;

                Assert.NotNull(result);
                messageService.Verify(
                    s => s.ReportAbuse(
                        It.Is<ReportPackageRequest>(
                            r => r.FromAddress.Address == "[email protected]"
                                 && r.Package == package
                                 && r.Reason == EnumHelper.GetDescription(ReportPackageReason.IsFraudulent)
                                 && r.Message == "Mordor took my finger."
                                 && r.AlreadyContactedOwners)));
            }
开发者ID:projectkudu,项目名称:NuGetGallery,代码行数:39,代码来源:PackagesControllerFacts.cs

示例8: ContactAdmins

        public virtual ActionResult ContactAdmins(string id, string version, ReportAbuseViewModel reportForm)
        {
            if (!ModelState.IsValid) return ContactAdmins(id, version);

            var package = packageSvc.FindPackageByIdAndVersion(id, version);
            if (package == null) return PackageNotFound(id, version);

            MailAddress from = null;
            if (Request.IsAuthenticated)
            {
                var user = userSvc.FindByUsername(HttpContext.User.Identity.Name);
                from = user.ToMailAddress();
            } else from = new MailAddress(reportForm.Email);

            var packageUrl = EnsureTrailingSlash(Configuration.GetSiteRoot(useHttps: false)) + RemoveStartingSlash(Url.Package(package));

            messageService.ContactSiteAdmins(from, package, reportForm.Message, packageUrl, reportForm.CopySender);

            TempData["Message"] = "Your message has been sent to the site admins.";
            return RedirectToAction(MVC.Packages.DisplayPackage(id, version));
        }
开发者ID:rhillaardvark,项目名称:chocolatey.org,代码行数:21,代码来源:PackagesController.cs

示例9: HtmlEncodesMessageContent

            public async Task HtmlEncodesMessageContent()
            {
                var messageService = new Mock<IMessageService>();
                messageService.Setup(
                    s => s.ReportAbuse(It.Is<ReportPackageRequest>(r => r.Message == "Mordor took my finger")));
                var package = new Package
                {
                    PackageRegistration = new PackageRegistration { Id = "mordor" },
                    Version = "2.0.1"
                };
                var packageService = new Mock<IPackageService>();
                packageService.Setup(p => p.FindPackageByIdAndVersion("mordor", "2.0.1", true)).Returns(package);
                var httpContext = new Mock<HttpContextBase>();
                httpContext.Setup(h => h.Request.IsAuthenticated).Returns(false);
                var controller = CreateController(
                    packageService: packageService,
                    messageService: messageService,
                    httpContext: httpContext);
                var model = new ReportAbuseViewModel
                {
                    Email = "[email protected]",
                    Message = "I like the cut of your jib. It's <b>bold</b>.",
                    Reason = ReportPackageReason.IsFraudulent,
                    AlreadyContactedOwner = true,
                };

                TestUtility.SetupUrlHelper(controller, httpContext);
                await controller.ReportAbuse("mordor", "2.0.1", model);

                messageService.Verify(
                    s => s.ReportAbuse(
                        It.Is<ReportPackageRequest>(
                            r => r.FromAddress.Address == "[email protected]"
                                 && r.Package == package
                                 && r.Reason == EnumHelper.GetDescription(ReportPackageReason.IsFraudulent)
                                 && r.Message == "I like the cut of your jib. It&#39;s &lt;b&gt;bold&lt;/b&gt;."
                                 && r.AlreadyContactedOwners)));
            }
开发者ID:goitsk,项目名称:NuGetGallery,代码行数:38,代码来源:PackagesControllerFacts.cs

示例10: ReportMyPackage

        public virtual ActionResult ReportMyPackage(string id, string version)
        {
            var user = GetCurrentUser();

            var package = _packageService.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return HttpNotFound();
            }

            // If user hit this url by constructing it manually but is not the owner, redirect them to ReportAbuse
            if (!(User.IsInRole(Constants.AdminRoleName) || package.IsOwner(user)))
            {
                return RedirectToAction("ReportAbuse", new { id, version });
            }

            var model = new ReportAbuseViewModel
            {
                ReasonChoices = ReportMyPackageReasons,
                ConfirmedUser = user.Confirmed,
                PackageId = id,
                PackageVersion = package.Version,
                CopySender = true,
                Signature = user.Username
            };

            return View(model);
        }
开发者ID:atrevisan,项目名称:NuGetGallery,代码行数:29,代码来源:PackagesController.cs

示例11: SendsMessageToGalleryOwnerWithUserInfoWhenAuthenticated

            public void SendsMessageToGalleryOwnerWithUserInfoWhenAuthenticated()
            {
                var messageService = new Mock<IMessageService>();
                messageService.Setup(
                    s => s.ReportAbuse(
                        It.IsAny<MailAddress>(),
                        It.IsAny<Package>(),
                        "Mordor took my finger"));
                var package = new Package
                    {
                        PackageRegistration = new PackageRegistration { Id = "mordor" },
                        Version = "2.0.1"
                    };
                var packageSvc = new Mock<IPackageService>();
                packageSvc.Setup(p => p.FindPackageByIdAndVersion("mordor", It.IsAny<string>(), true)).Returns(package);
                var httpContext = new Mock<HttpContextBase>();
                httpContext.Setup(h => h.Request.IsAuthenticated).Returns(true);
                httpContext.Setup(h => h.User.Identity.Name).Returns("Frodo");
                var userSvc = new Mock<IUserService>();
                userSvc.Setup(u => u.FindByUsername("Frodo")).Returns(new User { EmailAddress = "[email protected]", Username = "Frodo" });
                var controller = CreateController(
                    packageSvc: packageSvc,
                    messageSvc: messageService,
                    userSvc: userSvc,
                    httpContext: httpContext);
                var model = new ReportAbuseViewModel
                    {
                        Message = "Mordor took my finger."
                    };

                var result = controller.ReportAbuse("mordor", "2.0.1", model) as RedirectToRouteResult;

                Assert.NotNull(result);
                userSvc.VerifyAll();
                messageService.Verify(
                    s => s.ReportAbuse(
                        It.Is<MailAddress>(
                            m => m.Address == "[email protected]"
                                 && m.DisplayName == "Frodo"),
                        package,
                        "Mordor took my finger."
                             ));
            }
开发者ID:mteinum,项目名称:NuGetGallery,代码行数:43,代码来源:PackagesControllerFacts.cs

示例12: SendsMessageToGalleryOwnerWithEmailOnlyWhenUnauthenticated

            public void SendsMessageToGalleryOwnerWithEmailOnlyWhenUnauthenticated()
            {
                var messageService = new Mock<IMessageService>();
                messageService.Setup(
                    s => s.ReportAbuse(
                        It.IsAny<MailAddress>(),
                        It.IsAny<Package>(),
                        "Mordor took my finger"));
                var package = new Package
                    {
                        PackageRegistration = new PackageRegistration { Id = "mordor" },
                        Version = "2.0.1"
                    };
                var packageSvc = new Mock<IPackageService>();
                packageSvc.Setup(p => p.FindPackageByIdAndVersion("mordor", "2.0.1", true)).Returns(package);
                var httpContext = new Mock<HttpContextBase>();
                httpContext.Setup(h => h.Request.IsAuthenticated).Returns(false);
                var controller = CreateController(
                    packageSvc: packageSvc,
                    messageSvc: messageService,
                    httpContext: httpContext);
                var model = new ReportAbuseViewModel
                    {
                        Email = "[email protected]",
                        Message = "Mordor took my finger."
                    };

                var result = controller.ReportAbuse("mordor", "2.0.1", model) as RedirectToRouteResult;

                Assert.NotNull(result);
                messageService.Verify(
                    s => s.ReportAbuse(
                        It.Is<MailAddress>(m => m.Address == "[email protected]"),
                        package,
                        "Mordor took my finger."
                             ));
            }
开发者ID:mteinum,项目名称:NuGetGallery,代码行数:37,代码来源:PackagesControllerFacts.cs

示例13: ReportAbuse

        public virtual ActionResult ReportAbuse(string id, string version, ReportAbuseViewModel reportForm)
        {
            if (!ModelState.IsValid)
            {
                return ReportAbuse(id, version);
            }

            var package = packageSvc.FindPackageByIdAndVersion(id, version);
            if (package == null)
            {
                return PackageNotFound(id, version);
            }

            MailAddress from = null;
            if (Request.IsAuthenticated)
            {
                var user = userSvc.FindByUsername(HttpContext.User.Identity.Name);
                from = user.ToMailAddress();
            }
            else
            {
                from = new MailAddress(reportForm.Email);
            }

            messageService.ReportAbuse(from, package, reportForm.Message);

            TempData["Message"] = "Your abuse report has been sent to the gallery operators.";
            return RedirectToAction(MVC.Packages.DisplayPackage(id, version));
        }
开发者ID:jimitndiaye,项目名称:NuGetGallery,代码行数:29,代码来源:PackagesController.cs

示例14: ReportAbuse

        // NOTE: Intentionally NOT requiring authentication
        public virtual ActionResult ReportAbuse(string id, string version)
        {
            var package = _packageSvc.FindPackageByIdAndVersion(id, version);

            if (package == null)
            {
                return PackageNotFound(id, version);
            }

            var model = new ReportAbuseViewModel
                {
                    PackageId = id,
                    PackageVersion = package.Version,
                };

            if (Request.IsAuthenticated)
            {
                var user = _userSvc.FindByUsername(HttpContext.User.Identity.Name);
                if (user.Confirmed)
                {
                    model.ConfirmedUser = true;
                }
            }

            return View(model);
        }
开发者ID:mteinum,项目名称:NuGetGallery,代码行数:27,代码来源:PackagesController.cs


注:本文中的NuGetGallery.ReportAbuseViewModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。