//receives input from user 
 public ActionResult Create(user userModel)
 {
     using (minesweeperWebEntities db = new minesweeperWebEntities())
     {
         //if username already exists in database, user is notified 
         if (db.users.Any(x => x.username == userModel.username))
         {
             userModel.RegisterFail = "Username already exists";
             return View("Create", userModel);
         }
         //otherwise, the new user is added into the database and saved
         db.users.Add(userModel);
         db.SaveChanges();
     }
     //clears the model state object and redirects user to a success view
     ModelState.Clear();
     Session["username"] = userModel.username;
     return RedirectToAction("Index", "RegisterSuccess");
 }
Exemplo n.º 2
0
 public ActionResult Authenticate(user userModel)
 {
     //using the database
     using (minesweeperWebEntities db = new minesweeperWebEntities())
     {
         //checks database table names users for username and password
         var userDetails = db.users.Where(x => x.username == userModel.username && x.password == userModel.password).FirstOrDefault();
         //error message is displayed if username/password was not found in database
         if (userDetails == null)
         {
             userModel.LoginErrorMessage = "Wrong username or password";
             return(View("Index", userModel));
         }
         //redirects user to login success page and displays username
         else
         {
             Session["userID"]   = userDetails.id;
             Session["username"] = userDetails.username;
             return(RedirectToAction("Index", "HomePage"));
         }
     }
 }