public IActionResult Add(PostViewModel model) { int?userID = HttpContext.Session.GetInt32("userID"); if (userID != null) { if (ModelState.IsValid) { Post newSession = new Post { postContent = model.postContent, created_at = DateTime.UtcNow, updated_at = DateTime.UtcNow, // deleted = 0, userID = (int)HttpContext.Session.GetInt32("userID") }; _context.posts.Add(newSession); _context.SaveChanges(); // return Content("this is borked"); return(RedirectToAction("Splash", "Post")); } else { return(Content("THIS IS THE ERORR")); } } else { return(RedirectToAction("Index", "User")); } }
public IActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { User oldUser = _context.users.SingleOrDefault(user => user.email == model.email); if (oldUser != null) { ViewBag.errorMsg = "This email is already registered! Please go back and log in instead!"; return(View("Create", model)); } PasswordHasher <User> Hasher = new PasswordHasher <User>(); User newUser = new User { alias = model.alias, name = model.name, email = model.email, password = model.password, created_at = DateTime.UtcNow, updated_at = DateTime.UtcNow }; newUser.password = Hasher.HashPassword(newUser, newUser.password); _context.Add(newUser); _context.SaveChanges(); newUser = _context.users.SingleOrDefault(user => user.email == newUser.email); HttpContext.Session.SetInt32("userID", newUser.userID); //need to add confirmation for matching passwords TempData["String"] = "Valid Registration"; return(RedirectToAction("Splash", "Post"));//, "Activity"); // return Content("Plaeholder for registration"); } else { return(View("Index")); } }