Esempio n. 1
0
        // GET: Auth
        public ActionResult LogIn(string returnUrl)
        {
            var model = new LogInModel
            {
                ReturnUrl = returnUrl
            };

            return View(model);
        }
Esempio n. 2
0
        public ActionResult LogIn(LogInModel model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            var user = userManager.Find(model.Email, model.Password);

            if (user != null)
            {
                var identity = userManager.CreateIdentity(
                    user, DefaultAuthenticationTypes.ApplicationCookie);

                GetAuthenticationManager().SignIn(identity);

                return Redirect(GetRedirectUrl(model.ReturnUrl));
            }

            ModelState.AddModelError("", "Invalid email or password");
            return View();

            ////CHANGE WHEN YOU GO TO PRODUCTION!!!
            //if (model.Email == "*****@*****.**" && model.Password == "password")
            //{
            //    //once the user is authenticated, user info is passed to the cookie
            //    //using the ClaimsIdentity object
            //    var identity = new ClaimsIdentity(new[]
            //    {
            //        new Claim(ClaimTypes.Name, "Charles"),
            //        new Claim(ClaimTypes.Email, "*****@*****.**"),
            //        new Claim(ClaimTypes.Country, "USA"),
            //    },
            //        "ApplicationCookie");

            //    var ctx = Request.GetOwinContext();
            //    var authManager = ctx.Authentication;

            //    //set the auth cookie on the client
            //    authManager.SignIn(identity);

            //    //redirect the user to the url they were attempting 
            //    //to access before they were forced to login
            //    return Redirect(GetRedirectUrl(model.ReturnUrl));
            //}

            //ModelState.AddModelError("", "Invalid email or password");
            //return View();
        }