Ejemplo n.º 1
0
<?php

session_start();
$array_data = array();
$user = $_REQUEST['login_user'];
$pass = $_REQUEST['login_pass'];
$strconn = "host=localhost port=5432 dbname=gitbook user=postgres password=12345";
$conn = pg_connect($strconn);
$query = "Select * from personas where usuario='{$user}'";
$result = pg_query($conn, $query);
$row = pg_fetch_row($result);
$array_data[] = userValidate($user, $row);
$array_data[] = passValidate($pass, $row);
if (pg_num_rows($result) > 0) {
    $query1 = "Select idEmpresa from persona_empresa where idPersona='{$row['0']}'";
    $result1 = pg_query($conn, $query1);
    if (pg_num_rows($result1) > 0) {
        $row1 = pg_fetch_row($result1);
        $query2 = "Select * from empresas where idEmpresa='{$row1['0']}'";
        $result2 = pg_query($conn, $query2);
        $row2 = pg_fetch_row($result2);
        $_SESSION["rowCompany"] = $row2;
    }
}
echo json_encode($array_data);
function userValidate($user, $row)
{
    if (strlen($user) >= 2) {
        if ($row != NULL) {
            $_SESSION["rowUser"] = $row;
            return array('state' => "Correcto", 'box' => "box-user-login");
    $sex = $_REQUEST['sex'];
} else {
    $sex = "";
}
$pass = $_REQUEST['pass'];
$passConfirm = $_REQUEST['pass-confirm'];
$securityAnswer = $_REQUEST['security-answer'];
$strconn = "host=localhost port=5432 dbname=gitbook user=postgres password=12345";
$conn = pg_connect($strconn);
$array_data[] = nameValidate($name);
$array_data[] = lastNameValidate($lastName);
$array_data[] = emailValidate($email, $conn);
$array_data[] = admissionDateValidate($admissionDate);
$array_data[] = userValidate($user, $conn);
$array_data[] = sexValidate($sex);
$array_data[] = passValidate($pass);
$array_data[] = passConfirmValidate($pass, $passConfirm);
$array_data[] = securityAnswerValidate($securityAnswer);
echo json_encode($array_data);
function nameValidate($name)
{
    if (strlen($name) >= 3) {
        return array('state' => "Correcto", 'box' => "#box-name");
    } else {
        return array('state' => "Incorrecto", 'box' => "#box-name", 'errorBox' => "#error-name", 'error' => "Debe tener al menos 3 caracteres.");
    }
}
function lastNameValidate($lastName)
{
    if (strlen($lastName) >= 2) {
        return array('state' => "Correcto", 'box' => "#box-last-name");