コード例 #1
0
        public async Task <IActionResult> Login(LoginViewsModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await signInManager.PasswordSignInAsync(
                    userName : model.Email,
                    password : model.Password,
                    isPersistent : model.Remember,
                    lockoutOnFailure : false
                    );

                if (result.Succeeded)
                {
                    if (!string.IsNullOrEmpty(model.ReturnUrl))
                    {
                        return(Redirect(model.ReturnUrl));
                    }
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Error");

                    if (!string.IsNullOrEmpty(model.ReturnUrl))
                    {
                        return(Redirect(model.ReturnUrl));
                    }
                }
            }
            return(View(model));
        }
コード例 #2
0
        public async Task <ActionResult> Login([Bind(Include = "Email,Senha")] LoginViewsModel login)
        {
            var user = new Usuario();

            if (ModelState.IsValid)
            {
                if (login == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    user = await db.Usuarios.FirstOrDefaultAsync(l => l.Email == login.email && l.Senha == login.senha);

                    if (user == null)
                    {
                        return(HttpNotFound());
                    }
                }

                Session["User"] = user;
                return(RedirectToAction("Index", "Eventoes"));
            }

            return(View());
        }
コード例 #3
0
        public async Task <IActionResult> Login(LoginViewsModel model)
        {
            Microsoft.AspNetCore.Identity.SignInResult result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, isPersistent : true, lockoutOnFailure : false);

            if (result.Succeeded)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
コード例 #4
0
        public ActionResult Login(LoginViewsModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var userMgr = HttpContext.GetOwinContext().GetUserManager <UserManager <Users> >();
            var autMgr  = HttpContext.GetOwinContext().Authentication;

            // attempt to load the user with this password
            var user = userMgr.Find(model.UserName, model.Password);

            // user will be null if the password or user name is bad
            if (user == null)
            {
                ModelState.AddModelError("", "Invalid username or password");

                return(View(model));
            }
            else
            {
                // successful login, set up their cookies and send them on their way
                var identity = userMgr.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
                autMgr.SignIn(new AuthenticationProperties {
                    IsPersistent = true
                }, identity);

                UserLogIn.User = user;

                if (!string.IsNullOrEmpty(returnUrl))
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
        }
コード例 #5
0
        public ActionResult Login(string returnUrl)
        {
            var model = new LoginViewsModel();

            return(View(model));
        }