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)); }
public IActionResult Paste(PasteAPIv1Model model) { try { if (model != null && model.code != null) { Paste.Models.Paste paste = PasteHelper.CreatePaste(_config, _dbContext, model.code, model.title, model.syntax, model.expireUnit, model.expireLength, model.password); // Associate this with the user if they are logged in if (User.Identity.IsAuthenticated) { User foundUser = UserHelper.GetUser(_dbContext, User.Identity.Name); if (foundUser != null) { paste.UserId = foundUser.UserId; } } _dbContext.Pastes.Add(paste); _dbContext.SaveChanges(); return(Json(new { result = new { id = paste.Url, url = Url.SubRouteUrl("p", "Paste.View", new { type = "Full", url = paste.Url, password = model.password }), title = paste.Title, syntax = paste.Syntax, expiration = paste.ExpireDate, password = model.password } })); } return(Json(new { error = new { message = "Invalid Paste Request" } })); } catch (Exception ex) { return(Json(new { error = new { message = "Exception: " + ex.Message } })); } }