Пример #1
0
        public ActionResult Login(LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //Verificar en la base de datos

            var usuario = seguridadService.VerificarUsuario(
                model.Login, model.Password
                );

            if (usuario != null)
            {
                var claims      = SecurityHelper.CreateClaimsUsuario(usuario);
                var identity    = new ClaimsIdentity(claims, "ApplicationCookie");
                var context     = Request.GetOwinContext();
                var authManager = context.Authentication;

                authManager.SignIn(identity);

                return(Redirect(model.ReturnUrl ?? "~/"));
            }
            else
            {
                model.MensajeValidacion = "Usuario no registrado en el sistema";
                return(View(model));
            }

            //return View();
        }
Пример #2
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            await Task.Factory.StartNew(() =>
            {
                var user = seguridadService.VerificarUsuario(context.UserName, context.Password);

                if (user == null)
                {
                    context.SetError("Usuario o contraseña incorrecta.");
                    return;
                }

                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                identity.AddClaim(new Claim("usuarioID", user.UsuarioID.ToString()));
                identity.AddClaim(new Claim("nombres", $"{user.Nombres} {user.Apellidos}"));

                context.Validated(identity);
            });
        }