Ejemplo n.º 1
0
        public async Task <ActionResult> SignIn()
        {
            IAuthenticationManager authMgr = HttpContext.GetOwinContext().Authentication;
            StoreUserManager       userMgr = HttpContext.GetOwinContext().GetUserManager <StoreUserManager>();
            StoreUser user = await userMgr.FindAsync("Admin", "secret");

            authMgr.SignIn(await userMgr.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie));
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindAsync(model.UserName, model.Password);

                if (user != null)
                {
                    await SignInAsync(user, model.RememberMe);

                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    ModelState.AddModelError("", "Sai tên đăng nhập hoặc mật khẩu");
                }
            }

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