예제 #1
0
        public ActionResult Register(LogOnModel model)
        {
            if (ModelState.IsValid)
            {
                //Attempt to register the user
                _context.Users.Add(model);
                _context.SaveChanges();
                FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
                return RedirectToAction("Index", "Home");
            }

            //If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #2
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (_context.Users.Any(i => i.UserName == model.UserName))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "The user name is unknown, please register.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }