Exemplo n.º 1
0
        public void ComprobarDatosUsuarioTest()
        {
            bool paso = false;

            paso = UsuariosBLL.ComprobarDatosUsuario("Admin", "admin");

            Assert.AreEqual(true, paso);
        }
Exemplo n.º 2
0
        public async Task <ActionResult> OnGetAsync(string Usuario, string Clave)
        {
            string returnUrl = Url.Content("/LogInPage");

            try
            {
                await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
            }
            catch
            {
                throw;
            }

            if (UsuariosBLL.ComprobarDatosUsuario(Usuario, Clave))
            {
                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, Usuario),
                    new Claim(ClaimTypes.Role, UsuariosBLL.GetTipoUsuario(Usuario)),
                };

                var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);

                var authProperties = new AuthenticationProperties
                {
                    IsPersistent = true,
                    RedirectUri  = this.Request.Host.Value
                };
                try
                {
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties);
                }
                catch (Exception)
                {
                    throw;
                }
                return(LocalRedirect("/"));
            }
            else if (!UsuariosBLL.ComprobarDatosUsuario(Usuario, Clave))
            {
                return(LocalRedirect("/UserNotExist"));
            }
            else
            {
                return(LocalRedirect(returnUrl));
            }
        }