function googleLogin($connect, $name, $email)
{
    $id = getUserId($connect, $email);
    if ($id > 0) {
        updateLastLogin($connect, $id);
        $response = array();
        $response['status'] = 1;
        $response['message'] = "Successfully logged in";
        $response['user_id'] = $id;
        echo json_encode($response);
    } else {
        $code = createAccount($connect, $name, $email);
        if ($code == 1) {
            $response = array();
            $response['status'] = 5;
            $response['message'] = "Account Created Successfully";
            $response['user_id'] = getUserId($connect, $email);
            echo json_encode($response);
        } elseif ($code == 3) {
            showJson(3, "Email already registered\nLogin using email and password");
        } else {
            showJson(0, "Oops!...Details cannot be added into Database.Try again later.");
        }
    }
}
Exemplo n.º 2
0
function normalLogin($connect, $email, $password)
{
    $id = checkCredentials($connect, $email, $password);
    if ($id > 0) {
        updateLastLogin($connect, $id);
        $response = array();
        $response['status'] = 1;
        $response['message'] = "Successfully logged in";
        $response['user_id'] = $id;
        echo json_encode($response);
    } else {
        showJson(2, "Cannot login\nCheck your Credentials");
    }
}
Exemplo n.º 3
0
<?php

include_once '../conf/config.inc.php';
// app config
include_once '../lib/_functions.inc.php';
// app functions
include_once '../lib/classes/Db.class.php';
// db connector, queries
date_default_timezone_set('UTC');
$callback = safeParam('callback');
$now = date(DATE_RFC2822);
$db = new Db();
// Db query result: all "non-hidden" networks
$rsNetworks = $db->queryNetworks();
// Initialize array template for json feed
$output = ['generated' => $now, 'count' => $rsNetworks->rowCount(), 'type' => 'FeatureCollection', 'features' => []];
// Store results from db into features array
while ($row = $rsNetworks->fetch(PDO::FETCH_ASSOC)) {
    // Points
    $feature = ['geometry' => ['coordinates' => [floatval($row['lon']), floatval($row['lat'])], 'type' => 'Point'], 'id' => 'point' . intval($row['id']), 'properties' => ['name' => $row['name'], 'type' => $row['type']], 'type' => 'Feature'];
    array_push($output['features'], $feature);
    // Polygons
    if ($row['polygon']) {
        // not all networks necessarily have a polygon defined
        $poly = array('geometry' => array('coordinates' => array(json_decode($row['polygon'], true)), 'type' => 'Polygon'), 'id' => 'poly' . intval($row['id']), 'properties' => [], 'type' => 'Feature');
        array_push($output['features'], $poly);
    }
}
// Send json stream to browser
showJson($output, $callback);
                    sendEmailConfirmation($email);
                    $id = getUserId($connect, $email);
                    $response = array();
                    $response['status'] = 1;
                    $response['message'] = "Account Created";
                    $response['user_id'] = $id;
                    echo json_encode($response);
                } else {
                    showJson(0, "Oops!...Details cannot be added into Database.Try again later.");
                    die;
                }
            } else {
                showJson(3, "Email has already been registered.");
            }
        } else {
            showJson(4, "Fields cannot be empty.");
        }
    }
    mysqli_close($connect);
}
function getUserId($connect, $email)
{
    $query = "SELECT `id` FROM `users` WHERE `email`='{$email}' LIMIT 1";
    $query_run = mysqli_query($connect, $query);
    if ($result = mysqli_fetch_assoc($query_run)) {
        $user_id = $result['id'];
        return $user_id;
    } else {
        return 0;
    }
}
Exemplo n.º 5
0
// Create a nested array for each type of data to store
$fields = ['comp_obs', 'date', 'mp1', 'mp2', 'pos_obs', 'slips', 'sn1', 'sn2'];
foreach ($fields as $field) {
    $output[$field] = [];
}
// Store results from db into output array
while ($row = $rsQcData->fetch(PDO::FETCH_ASSOC)) {
    foreach ($fields as $field) {
        $value = $row[$field];
        if ($field === 'date') {
            $value = date('Y-m-d', strtotime($value));
        } else {
            if ($field === 'slips') {
                // convert slips to log base 10
                if ($value <= 0) {
                    $value = 0;
                } else {
                    $value = round(log10($value), 2);
                }
            } else {
                if ($value !== null) {
                    $value = floatval($value);
                }
            }
        }
        array_push($output[$field], $value);
    }
}
// send json stream
showJson($output);