コード例 #1
0
        public IActionResult Index()
        {
            ViewBag.Title       = "Pastebin";
            ViewBag.Description = "Paste your code or text easily and securely.  Set an expiration, set a password, or leave it open for the world to see.";
            PasteCreateViewModel model = new PasteCreateViewModel();

            return(View(model));
        }
コード例 #2
0
        public IActionResult Paste([Bind("Content, Title, Syntax, ExpireLength, ExpireUnit, Password")] PasteCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (_config.PasteConfig.Enabled)
                {
                    try
                    {
                        Models.Paste paste = PasteHelper.CreatePaste(_config, _dbContext, model.Content, model.Title, model.Syntax, model.ExpireUnit, model.ExpireLength ?? 1, model.Password);

                        if (model.ExpireUnit == ExpirationUnit.Views)
                        {
                            paste.Views = -1;
                        }

                        if (User.Identity.IsAuthenticated)
                        {
                            Users.Models.User user = UserHelper.GetUser(_dbContext, User.Identity.Name);
                            if (user != null)
                            {
                                paste.UserId = user.UserId;
                            }
                        }

                        _dbContext.Pastes.Add(paste);
                        _dbContext.SaveChanges();

                        // Cache the password
                        CachePassword(paste.Url, model.Password);

                        return(Redirect(Url.SubRouteUrl("p", "Paste.View", new { type = "Full", url = paste.Url })));
                    }
                    catch (Exception ex)
                    {
                        return(Redirect(Url.SubRouteUrl("error", "Error.500", new { exception = ex })));
                    }
                }
                return(new StatusCodeResult(StatusCodes.Status403Forbidden));
            }
            return(View("~/Areas/Paste/Views/Paste/Index.cshtml", model));
        }