Пример #1
0
 public ActionResult Index(LoginModel model, string returnUrl)
 {
     if (_userService.IsValidLogin(model.Username, model.Password))
     {
         FormsAuthentication.SetAuthCookie(model.Username, false);
         if (returnUrl != null)
         {
             return Redirect(returnUrl);
         }
         else
         {
             return RedirectToAction("Index", "Home");
         }
     }
     else
     {
         ModelState.AddModelError("result", "Incorrect user name or password.  Try again.");
         return View(model);
     }
 }
Пример #2
0
        public ActionResult RegisterUser(LoginModel model)
        {
            if ( ModelState.IsValid)
            {
                User newUser = new User()
                {
                    Email = model.NewUser.Email,
                    Location = model.NewUser.Location,
                    Name = model.NewUser.Name,
                    Password = model.NewUser.Password,
                    UserName = model.NewUser.UserName
                };
                _userService.CreateUser(newUser);
                _unit.Commit();

                FormsAuthentication.SetAuthCookie(model.NewUser.UserName, false);

                return RedirectToAction("Index", "Home");
            }
            else
            {
                return RedirectToAction("Index", "Login", model);
            }
        }