コード例 #1
0
        public async Task <IActionResult> AutenticarClienteConClave([FromRoute] long identificacion, [FromRoute] string clave)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    //return BadRequest(ModelState);
                    throw new Exception("Datos incorrectos.");
                }

                string strClave = HashMD5.FromHexString(clave);
                strClave = HashMD5.CreateMD5(strClave);

                var cliente = await _context.Cliente.FirstOrDefaultAsync(e => e.Identificacion == identificacion && e.Clave == strClave);

                if (cliente == null)
                {
                    //return NotFound();
                    throw new Exception("Datos incorrectos.");
                }

                cliente.Clave = string.Empty;
                return(Ok(cliente));
            }
            catch (Exception ex)
            {
                Response.StatusCode = StatusCodes.Status404NotFound;
                return(new JsonResult(new Respuesta()
                {
                    Resultado = "Error de autenticación con clave.", Mensaje = ex.Message
                }));
            }
        }