Beispiel #1
0
/**
 * Create captcha image
 *
 * @throws iMSCP_Exception
 * @param  string $strSessionVar
 * @return void
 */
function createImage($strSessionVar)
{
    /** @var $cfg iMSCP_Config_Handler_File */
    $cfg = iMSCP_Registry::get('config');
    $rgBgColor = $cfg['LOSTPASSWORD_CAPTCHA_BGCOLOR'];
    $rgTextColor = $cfg['LOSTPASSWORD_CAPTCHA_TEXTCOLOR'];
    if (!($image = imagecreate($cfg['LOSTPASSWORD_CAPTCHA_WIDTH'], $cfg['LOSTPASSWORD_CAPTCHA_HEIGHT']))) {
        throw new iMSCP_Exception('Cannot initialize new GD image stream.');
    }
    imagecolorallocate($image, $rgBgColor[0], $rgBgColor[1], $rgBgColor[2]);
    $textColor = imagecolorallocate($image, $rgTextColor[0], $rgTextColor[1], $rgTextColor[2]);
    $white = imagecolorallocate($image, 0xff, 0xff, 0xff);
    $nbLetters = 6;
    $x = $cfg['LOSTPASSWORD_CAPTCHA_WIDTH'] / 2 - $nbLetters * 20 / 2;
    $y = mt_rand(15, 30);
    $string = '';
    for ($i = 0; $i < $nbLetters; $i++) {
        $iRandVal = strRandom(1);
        $fontFile = LIBRARY_PATH . '/Resources/Fonts/' . $cfg['LOSTPASSWORD_CAPTCHA_FONTS'][mt_rand(0, count($cfg['LOSTPASSWORD_CAPTCHA_FONTS']) - 1)];
        imagettftext($image, 20, 0, $x, $y, $textColor, $fontFile, $iRandVal);
        $x += 20;
        $y = mt_rand(15, 25);
        $string .= $iRandVal;
    }
    $_SESSION[$strSessionVar] = $string;
    // Some obfuscation
    for ($i = 0; $i < 5; $i++) {
        $x1 = mt_rand(0, $x - 1);
        $y1 = mt_rand(0, round($y / 10, 0));
        $x2 = mt_rand(0, round($x / 10, 0));
        $y2 = mt_rand(0, $y - 1);
        imageline($image, $x1, $y1, $x2, $y2, $white);
        $x1 = mt_rand(0, $x - 1);
        $y1 = $y - mt_rand(1, round($y / 10, 0));
        $x2 = $x - mt_rand(1, round($x / 10, 0));
        $y2 = mt_rand(0, $y - 1);
        imageline($image, $x1, $y1, $x2, $y2, $white);
    }
    // send Header
    header('Content-type: image/png');
    // create and send PNG image
    imagepng($image);
    // destroy image from server
    imagedestroy($image);
}
Beispiel #2
0
function registrarUsuario($nombre, $apellidos, $tipoDocumento, $numeroDocumento, $fechaNacimiento, $correo, $celular, $telefono, $direccion, $pais, $ciudad, $usuario, $pwd, $actualizaciones, $promociones)
{
    $mdb2 = conectar();
    $nuevoUsuario = new Usuario($mdb2['dsn']);
    $nuevoUsuario->useResult('object');
    $nUsuario = $nuevoUsuario->newEntity();
    $nUsuario->nombre = $nombre;
    $nUsuario->apellidos = $apellidos;
    $nUsuario->tipoDocumento = $tipoDocumento;
    $nUsuario->numeroDocumento = (int) $numeroDocumento;
    $nUsuario->fechaNacimiento = $fechaNacimiento;
    $nUsuario->correoElectronico = $correo;
    $nUsuario->celular = $celular;
    $nUsuario->actualizacion = $actualizaciones;
    $nUsuario->promocion = $promociones;
    $codigo = "COOP" . strtoupper(strRandom(4));
    $nUsuario->codigo = $codigo;
    $nUsuario->usuario = $usuario;
    $nUsuario->contrasenia = sha1($pwd);
    $idUsuario = $nUsuario->save();
    if (is_numeric($idUsuario)) {
        $nuevaDireccion = new Direccion($mdb2['dsn']);
        $nuevaDireccion->useResult('object');
        $nDireccion = $nuevaDireccion->newEntity();
        $nDireccion->direccion = $direccion;
        $nDireccion->telefono = $telefono;
        $nDireccion->predeterminada = 1;
        $nDireccion->idUsuario = $idUsuario;
        $nDireccion->idCiudad = $ciudad;
        $idDireccion = $nDireccion->save();
        if (is_numeric($idDireccion)) {
            $_SESSION['usuario']['idUsuario'] = $idUsuario;
            $mensaje = "<div style='text-align: center; float: left;'>\n            <h1>Bienvenido, gracias por registrarte</h1>\n            <label>Nosotros somos Coopcrucial, la coperativa de la Cruz Roja, Colombiana.</label>\n            <br/>\n            <br/>\n            <div style='width: 60%; margin-left: 20%; float: left;'>\n                {$nombre}, para nosotros es un gran privilegio tenerlo en nuestra base de datos y poder atender a sus necesidades\n                con productos de primera calidad. Como bienvenida, le regalamos un bono de descuento por \$100.000 COL que podrá\n                utilizar desde su primera compra.\n            </div>\n            <p/>\n            <label><strong style='text-decoration: underline; font-size: 30px;'>{$codigo}</strong></label>\n            <br/>\n            <label>Puede copiar este código</label>\n            <p/>\n            <label>Contrase&ntilde;a: <strong style='text-decoration: underline; font-size: 20px;'>{$pwd}</strong></label>\n            <p/>\n        </div>";
            $cabecera = "Content-type: text/html\r\n";
            $resp = mail($correo, "Registro Exitoso", $mensaje, $cabecera);
            return array("bool" => true, "codigo" => $codigo);
        }
        return array("bool" => false);
    }
    return array("bool" => false);
}
Beispiel #3
0
/**
 * [strNonce description]
 *
 * @param [type] $str [description]
 *
 * @return [type]      [description]
 */
function str_nonce($str)
{
    return hash("sha512", $str . strRandom());
}
Beispiel #4
0
function agregarCarrito($idProducto, $cantidad, $talla, $color)
{
    if (!isset($_SESSION['usuario']['idUsuario']) || $_SESSION['usuario']['idUsuario'] == "") {
        $nombreUsuario = "COOP-" . strRandom(5);
        $_SESSION['usuario']['nombreUsuario'] = $nombreUsuario;
        $_SESSION['usuario']['nombre'] = "";
        $_SESSION['usuario']['idUsuario'] = $nombreUsuario;
    }
    if (is_numeric($_SESSION['usuario']['idUsuario'])) {
        //BD
        $mdb2 = conectar();
        $carrito = new Venta($mdb2['dsn']);
        $carrito->setSelect("idVenta");
        $carrito->setWhere("idUsuario = " . $_SESSION['usuario']['idUsuario']);
        $carrito->addWhere("idProducto = {$idProducto}");
        $carrito->addWhere("carrito = 1");
        $carrito = $carrito->getAll();
        if (count($carrito) > 0) {
            return array("bool" => true, "msj" => "Este producto ya se encuentra en el carrito.", "idVenta" => $carrito[0]['idVenta']);
        }
        $nuevaVenta = new Venta($mdb2['dsn']);
        $nuevaVenta->useResult('object');
        $nVenta = $nuevaVenta->newEntity();
        $nVenta->idProducto = $idProducto;
        $nVenta->idUsuario = $_SESSION['usuario']['idUsuario'];
        $nVenta->cantidad = $cantidad;
        $nVenta->carrito = 1;
        $nVenta->talla = $talla;
        $nVenta->color = $color;
        $nVenta->idDireccion = null;
        $idVenta = $nVenta->save();
        if (is_numeric($idVenta)) {
            return array("bool" => true, "msj" => "El producto se ha agregado al carrito.", "idVenta" => $idVenta);
        }
        return array("bool" => false, "msj" => "No se pudo agregar al carrito.");
    } elseif (substr_compare($_SESSION['usuario']['idUsuario'], "COOP-", 0, 5) == 0) {
        //Session
        for ($i = 0; $i < count($_SESSION['carrito']); $i++) {
            if ($_SESSION['carrito'][$i]['idProducto'] == $idProducto) {
                return array("bool" => true, "msj" => "Este producto ya se encuentra en el carrito.", "idVenta" => $_SESSION['carrito'][$i]['idVenta']);
            }
        }
        $idVenta = strRandom(6);
        $_SESSION['carrito'] = array();
        array_push($_SESSION['carrito'], array('idVenta' => $idVenta, 'idUsuario' => $_SESSION['usuario']['idUsuario'], 'idProducto' => $idProducto, 'cantidad' => $cantidad, 'talla' => $talla, 'color' => $color));
        return array("bool" => true, "msj" => "El producto se ha agregado al carrito.", "idVenta" => $idVenta);
    }
    return array("bool" => false, "msj" => "No se pudo agregar al carrito.");
}