public IActionResult register(RegisterViewModel registerVM) { if (ModelState.IsValid) { User user = new User { Name = registerVM.Name, Alias = registerVM.Alias, Email = registerVM.Email, Password = registerVM.Password, }; //Hashed Password PasswordHasher <User> Hasher = new PasswordHasher <User>(); user.Password = Hasher.HashPassword(user, user.Password); //Save to DB _context.Add(user); _context.SaveChanges(); //set userid into session HttpContext.Session.SetInt32("user_id", user.UserId); return(RedirectToAction("Home")); } return(View("Index")); }
public IActionResult Register(PersonViewModel model) { if (ModelState.IsValid) { Person newUser = new Person { firstName = model.firstName, lastName = model.lastName, userName = model.userName, created_at = DateTime.Now, updated_at = DateTime.Now, wallet = 1000 }; PasswordHasher <Person> hasher = new PasswordHasher <Person>(); newUser.password = hasher.HashPassword(newUser, model.password); context.Add(newUser); context.SaveChanges(); HttpContext.Session.SetInt32("currentUserId", newUser.id); HttpContext.Session.SetString("currentUserName", newUser.firstName); return(RedirectToAction("Dash")); } else { return(View(model)); } }
public IActionResult AddItem(AuctionItem model) { if (HttpContext.Session.GetInt32("UserId") == null) { return(RedirectToAction("Index", "User")); } User CurrentUser = _context.Users.SingleOrDefault(user => user.UserId == HttpContext.Session.GetInt32("UserId")); if (model.EndDate < DateTime.Now) { ModelState.AddModelError("EndDate", "Must be in the future"); } if (model.StartingBid <= 0) { ModelState.AddModelError("StartingBid", "Starting Bid must be greater than 0"); } if (ModelState.IsValid) { model.User = CurrentUser; _context.Add(model); _context.SaveChanges(); return(RedirectToAction("Dashboard")); } ViewBag.UserId = HttpContext.Session.GetInt32("UserId"); return(View("NewAuction")); }
public IActionResult Register(RegValidator model) { if (ModelState.IsValid) { List <User> users = _context.Users.ToList(); User existing = users.SingleOrDefault(u => u.username == model.username); if (existing == null) { PasswordHasher <User> hasher = new PasswordHasher <User>(); User newUser = new User { first_name = model.first_name, last_name = model.last_name, username = model.username, wallet = 1000 }; newUser.password = hasher.HashPassword(newUser, model.password); _context.Add(newUser); _context.SaveChanges(); users = _context.Users.ToList(); User justCreated = users.Single(u => u.username == newUser.username); HttpContext.Session.SetInt32("id", justCreated.id); HttpContext.Session.SetString("name", justCreated.first_name); return(RedirectToAction("Main")); } ModelState.AddModelError("username", "This username is already in use."); } return(View("Index")); }
public IActionResult register(IndexViewModel user) { User regUser = user.NewRegUser; // Check initial ModelState if (ModelState.IsValid) { // If a User exists with provided Username if (dbContext.Users.Any(u => u.Username == regUser.Username)) { ModelState.AddModelError("NewRegUser.Username", "Username already registered!"); return(RedirectToAction("Index")); } else { PasswordHasher <User> Hasher = new PasswordHasher <User>(); regUser.Password = Hasher.HashPassword(regUser, regUser.Password); regUser.Wallet = 1000; // Add the user to database here dbContext.Add(regUser); dbContext.SaveChanges(); HttpContext.Session.SetString("UserName", regUser.Username); return(RedirectToAction("Dashboard")); } } else { return(View("Index")); } }
public async Task <IActionResult> Create(CreateOrEditUserViewModel viewModel) { if (ModelState.IsValid) { var user = viewModel.User; var dbUser = new User { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Phone = user.Phone, Password = user.Password, AutoBidAmt = user.AutoBidAmt }; _context.Add(dbUser); await _context.SaveChangesAsync(); TempData["SuccessMessage"] = $"Successfully created user #{user.UserId.ToString()}."; return(RedirectToAction("Index")); } return(await CreateOrEdit(viewModel)); }
public IActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { if (_context.users.SingleOrDefault(user => user.UserName == model.UserName) == null) { User NewUser = new User { FirstName = model.FirstName, LastName = model.LastName, UserName = model.UserName, Password = model.Password }; PasswordHasher <User> Hasher = new PasswordHasher <User>(); NewUser.Password = Hasher.HashPassword(NewUser, NewUser.Password); _context.Add(NewUser); _context.SaveChanges(); User CurrentUser = _context.users.SingleOrDefault(user => user.UserName == NewUser.UserName); HttpContext.Session.SetString("loggedin", "yes"); HttpContext.Session.SetString("username", NewUser.UserName); return(RedirectToAction("Home")); } else { ViewBag.error = "UserName Already in use"; return(View("Index")); } } else { return(View("Index")); } }
public IActionResult Register(User model) { User CheckUsername = _context.Users.SingleOrDefault(user => user.Username == model.Username); if (CheckUsername != null) { ViewBag.errors = "Username already registered to an account"; return(View("Index")); } if (ModelState.IsValid) { _context.Add(model); PasswordHasher <User> Hasher = new PasswordHasher <User>(); model.Wallet = 1000; model.Password = Hasher.HashPassword(model, model.Password); model.ConfirmPW = Hasher.HashPassword(model, model.ConfirmPW); _context.SaveChanges(); ViewBag.errors = "Successfully Registered! You may now login!"; return(View("Index")); } else { return(View("Index")); } }
public async Task <IActionResult> Create([Bind("RoleID,ShortDescription,UserRole")] Role role) { if (ModelState.IsValid) { _context.Add(role); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(role)); }
public async Task <IActionResult> Create([Bind("MediaTypeID,MediaDescription")] MediaType mediaType) { if (ModelState.IsValid) { _context.Add(mediaType); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(mediaType)); }
public async Task <IActionResult> Create([Bind("AuctionID,AuctionName,StartDate,EndDate")] Auction auction) //re-add eventId { if (ModelState.IsValid) { _context.Add(auction); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(auction)); }
public async Task <IActionResult> Create([Bind("ID,FwdDate,BankName,FwdRate,AmountBid,CouponAmount,Pips,BatchRef")] AuctionBid auctionBid) { if (ModelState.IsValid) { _context.Add(auctionBid); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(auctionBid)); }
public async Task <IActionResult> Create([Bind("CategoryId,Name,Description")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(category)); }
public async Task <IActionResult> Create([Bind("sponsorID,sponsorName,sponsorEmail")] Sponsor sponsor) { if (ModelState.IsValid) { _context.Add(sponsor); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(sponsor)); }
public async Task <IActionResult> Create([Bind("ID,FwdDate,BankName,AuctionBidID,FwdRate,AmountBid,CouponAmount,WinAmount")] WinResults winResults) { if (ModelState.IsValid) { _context.Add(winResults); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AuctionBidID"] = new SelectList(_context.AuctionBids, "ID", "ID", winResults.AuctionBidID); return(View(winResults)); }
public async Task <IActionResult> Create([Bind("ItemId,sponsorID,CategoryId,ItemName,ItemDescription,ItemValue,OpeningBid,BidIncrement,AuctionId")] Item item) { if (ModelState.IsValid) { _context.Add(item); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } // ViewData["AuctionId"] = new SelectList(_context.Auctions, "AuctionID", "AuctionID", item.AuctionId); return(View(item)); }
public IActionResult Index(UserModelView model) { if (ModelState.IsValid) { User newUser = new User { FirstName = model.FirstName, LastName = model.LastName, Wallet = 1000, Username = model.Username, CreatedAt = DateTime.Now }; PasswordHasher <User> hasher = new PasswordHasher <User>(); newUser.Password = hasher.HashPassword(newUser, model.Password); _context.Add(newUser); _context.SaveChanges(); HttpContext.Session.SetInt32("currentUserId", newUser.Id); HttpContext.Session.SetString("currentUserName", newUser.FirstName); return(RedirectToAction("Dashboard")); } return(View()); }
public async Task <IActionResult> Create([Bind("Id,SponsorId,CategoryId,Name,Description,Type,RetailPrice,MinimumBid,OfferExpires,Terms")] Item item) { if (ModelState.IsValid) { _context.Add(item); await _context.SaveChangesAsync(); return(RedirectToAction("Edit", new RouteValueDictionary(new { controller = "Items", action = "Edit", id = item.Id }))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", item.CategoryId); ViewData["SponsorId"] = new SelectList(_context.Sponsors, "Id", "Name", item.SponsorId); return(View(item)); }
public async Task <IActionResult> Create([Bind("BidderID,FirstName,LastName,PhoneNumber,EmailAddress,IsRegistered,Password,Security")] Bidder bidder) { if (!string.IsNullOrEmpty(bidder.EmailAddress) && !string.IsNullOrEmpty(bidder.Password)) { //Check if user already exists in table as a non-registered bidder. (Someone who bid without registering.) var UserExists = _context.Bidders.Any(b => b.EmailAddress == bidder.EmailAddress); Bidder MatchedUser; if (UserExists) { MatchedUser = _context.Bidders.First(b => b.EmailAddress == bidder.EmailAddress); } else { MatchedUser = null; } //If the person exists and is registered, return an "already exists" error. if (MatchedUser != null && MatchedUser.IsRegistered == true) { ModelState.AddModelError("EmailAddress", "This email address is already in use."); return(View()); } else if (MatchedUser != null && MatchedUser.IsRegistered == false) { ModelState.AddModelError("EmailAddress", "This email is already in use. Please contact support if this is an error."); // //Else if the person exists and is NOT registered, set them up as such. // // Don't ever do this in real life, please. // // This is a terrible thing to do, but works for this prototype's simplicity. // MatchedUser.IsRegistered = true; //Set to true. // MatchedUser.Password = bidder.Password; // MatchedUser.Security = bidder.Security; // //Update the model // _context.Update(MatchedUser); // await _context.SaveChangesAsync(); // //If we had an email provider, you could force someone to verify/prove ownership of their email address before setting the above values. But still not ideal. } else { //Next, handle a non-existant user. //The registration/creation page isn't taking everything in, so we need to setup a new object first. Bidder NewBidder = new Bidder() { FirstName = bidder.FirstName, LastName = bidder.LastName, PhoneNumber = bidder.PhoneNumber, EmailAddress = bidder.EmailAddress, IsRegistered = true, Role = _context.Roles.First(r => r.RoleID == 3), Password = bidder.Password, Security = bidder.Security }; _context.Add(NewBidder); await _context.SaveChangesAsync(); return(RedirectToAction("EmailConfirmation")); } } //Return view if errors occurred, etc. Default state. return(View(bidder)); }