Exemplo n.º 1
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var authService = new UserIdentityAuthenticationService();
                if (authService.SignIn(model.LoginName, model.Password))
                {
                    if (Url != null && !string.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Dashboard"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid username/password. Please try again.");
                    return(RedirectToAction("Login", model));
                }
            }

            ModelState.AddModelError("", "Invalid username/password. Please try again.");
            return(RedirectToAction("Login", model));
        }
Exemplo n.º 2
0
 public static UserIdentity Deserialize(string data)
 {
     try
     {
         var ticket = FormsAuthentication.Decrypt(data);
         return(new UserIdentity(ticket));
     }
     catch
     {
         var service = new UserIdentityAuthenticationService();
         service.SignOut();
         return(null);
     }
 }