Example #1
0
        public IActionResult Login(ELogin eLogin)
        {
            EOutLogin eOutLogin = iRepositorioAuth.Login(eLogin);

            if (eOutLogin == null)
            {
                var badResult = BadRequest(new { message = "Usuario y/o contraseƱa incorrectos" });
                return(badResult);
            }

            return(Ok(eOutLogin));
        }
Example #2
0
        public EOutLogin Login(ELogin eLogin)
        {
            EOutLogin eOutLogin = null;

            using (var context = new cita_doctorContext())
            {
                string pass = Hash.Crear(eLogin.Password, "jor290714luc300617");

                var user = (from us in context.Users
                            .Where(us => (us.Email.Equals(eLogin.Username) && us.PasswordHash.Equals(pass)))
                            select us);

                if (user.ToList().Count == 0)
                {
                    return(eOutLogin);
                }

                var secretKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("MySp$cialPassw0rd"));
                var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);

                var token = new JwtSecurityToken(
                    issuer: "http://localhost:4200",
                    audience: "http://localhost:4200",
                    claims: new List <Claim>(),
                    expires: DateTime.Now.AddMinutes(1440),
                    signingCredentials: signinCredentials
                    );

                var tokenString = new JwtSecurityTokenHandler().WriteToken(token);

                eOutLogin = new EOutLogin()
                {
                    Token     = tokenString,
                    ExpiresIn = token.ValidTo,
                    Usuario   = user.ToList()[0],
                    Tipo      = "owner"
                };

                return(eOutLogin);
            }
        }