Compare commits
3 Commits
8b68547644
...
ae036686b8
Author | SHA1 | Date | |
---|---|---|---|
ae036686b8 | |||
70f91c7586 | |||
913d53b757 |
14
index.html
14
index.html
@@ -18,8 +18,22 @@
|
|||||||
|
|
||||||
<span role="alert" id="error" aria-hidden="true">Invalid URL</span>
|
<span role="alert" id="error" aria-hidden="true">Invalid URL</span>
|
||||||
|
|
||||||
|
<br><br>
|
||||||
|
<label for="restricted">Geo-restricted?: </label><input type="checkbox" name="restricted" id="restricted">
|
||||||
|
<br><br>
|
||||||
|
<label for="radius">Radius: </label>
|
||||||
|
<select name="radius" id="radius">
|
||||||
|
<option value="5">5 mi</option>
|
||||||
|
<option value="10">10 mi</option>
|
||||||
|
<option value="15">15 mi</option>
|
||||||
|
<option value="20">20 mi</option>
|
||||||
|
</select>
|
||||||
<br><br>
|
<br><br>
|
||||||
<input type="submit" id="button" value="Zip It!">
|
<input type="submit" id="button" value="Zip It!">
|
||||||
|
|
||||||
|
|
||||||
|
<input type="hidden" name="latitude" id="latitude">
|
||||||
|
<input type="hidden" name="longitude" id="longitude">
|
||||||
</form>
|
</form>
|
||||||
<hr>
|
<hr>
|
||||||
<div>
|
<div>
|
||||||
|
195
index.js
195
index.js
@@ -1,74 +1,127 @@
|
|||||||
//const submit = document.getElementById("button");
|
// const submit = document.getElementById("button");
|
||||||
//submit.addEventListener('click', validate);
|
// submit.addEventListener('click', validate);
|
||||||
function validate() {
|
|
||||||
// e.preventDefault();
|
|
||||||
|
|
||||||
const url = document.getElementById("URL");
|
mycheckbox = document.getElementById("restricted");
|
||||||
const glink = document.getElementById("GLink");
|
mycheckbox.addEventListener('change',checkboxCallback);
|
||||||
// if (!url) {
|
|
||||||
// /* Flag */
|
|
||||||
// }
|
|
||||||
let valid = true;
|
|
||||||
const domainExp = new RegExp("http(s)*:\\/\\/[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+");
|
|
||||||
const filepathExp = new RegExp("[a-zA-Z]+");
|
|
||||||
let count = 0;
|
|
||||||
let index = -1;
|
|
||||||
let domain = "";
|
|
||||||
let filepath = "";
|
|
||||||
for (let i=0; i < url.value.length; i++) {
|
|
||||||
if (url.value.charAt(i) == '/') {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (count == 3) {
|
|
||||||
index = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (count >= 3) {
|
|
||||||
domain = url.value.substring(0, index);
|
|
||||||
if (index == url.value.length - 1) {
|
|
||||||
filepath = url.value.charAt(index);
|
|
||||||
} else {
|
|
||||||
filepath = url.value.substring(index, url.value.length - 1);
|
|
||||||
}
|
|
||||||
alert("Domain is " + domain + " filepath is " + filepath);
|
|
||||||
} else {
|
|
||||||
domain = url.value;
|
|
||||||
}
|
|
||||||
console.log(domain);
|
|
||||||
if (domain.match(domainExp)) /** and is available? */{
|
|
||||||
const error = document.getElementById("error");
|
|
||||||
if (error.classList.contains("visible")) {
|
|
||||||
error.classList.remove("visible");
|
|
||||||
}
|
|
||||||
if (url.classList.contains("invalid")) {
|
|
||||||
url.classList.remove("invalid");
|
|
||||||
}
|
|
||||||
url.classList.add("valid");
|
|
||||||
error.setAttribute('aria-hidden', true);
|
|
||||||
error.setAttribute('aria-invalid', false);
|
|
||||||
console.log("Valid");
|
|
||||||
|
|
||||||
return valid;
|
|
||||||
|
|
||||||
/* var xmlhttp = new XMLHttpRequest();
|
|
||||||
xmlhttp.open('GET','result.php',true);
|
|
||||||
xmlhttp.send();
|
|
||||||
console.log(xmlhttp.responseText);*/
|
|
||||||
} else {
|
|
||||||
|
|
||||||
/*flag*/
|
|
||||||
const error = document.getElementById("error");
|
|
||||||
error.classList.add("visible");
|
|
||||||
|
|
||||||
//error.classList.add("hidden");
|
|
||||||
if (url.classList.contains("valid")) {
|
|
||||||
url.classList.remove("valid");
|
|
||||||
}
|
|
||||||
url.classList.add("invalid");
|
|
||||||
error.setAttribute('aria-hidden', false);
|
|
||||||
error.setAttribute('aria-invalid', true);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
function checkboxCallback(event) {
|
||||||
|
if (event.currentTarget.checked) {
|
||||||
|
getLocation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLocation() {
|
||||||
|
if (navigator.geolocation) {
|
||||||
|
navigator.geolocation.getCurrentPosition(showPosition);
|
||||||
|
} else {
|
||||||
|
console.log("Your browser does not support geolocation.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showPosition(position) {
|
||||||
|
console.log(position.coords.latitude);
|
||||||
|
console.log(position.coords.longitude);
|
||||||
|
|
||||||
|
document.getElementById("latitude").value = position.coords.latitude;
|
||||||
|
document.getElementById("longitude").value = position.coords.longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function validate() {
|
||||||
|
//e.preventDefault();
|
||||||
|
|
||||||
|
const url = document.getElementById("URL");
|
||||||
|
let glink = document.getElementById("GLink");
|
||||||
|
const error = document.getElementById("error");
|
||||||
|
// if (!url) {
|
||||||
|
// /* Flag */
|
||||||
|
// }
|
||||||
|
let valid = true;
|
||||||
|
const domainExp = new RegExp("^http(s)*:\\/\\/[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+$");
|
||||||
|
const filepathExp = new RegExp("^[a-zA-Z]+$");
|
||||||
|
const glinkExp = new RegExp("^[a-zA-Z]*$");
|
||||||
|
let glinkStr = glink.value;
|
||||||
|
let count = 0;
|
||||||
|
let index = -1;
|
||||||
|
let domain = "";
|
||||||
|
let filepath = "";
|
||||||
|
for (let i = 0; i < url.value.length; i++) {
|
||||||
|
if (url.value.charAt(i) == '/') {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if (count == 3) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count >= 3) {
|
||||||
|
domain = url.value.substring(0, index);
|
||||||
|
if (index == url.value.length - 1) {
|
||||||
|
filepath = url.value.charAt(index);
|
||||||
|
} else {
|
||||||
|
filepath = url.value.substring(index, url.value.length - 1);
|
||||||
|
}
|
||||||
|
alert("Domain is " + domain + " filepath is " + filepath);
|
||||||
|
} else {
|
||||||
|
domain = url.value;
|
||||||
|
}
|
||||||
|
console.log(domain);
|
||||||
|
|
||||||
|
if (glinkStr === "") {
|
||||||
|
var result = window.confirm("You have left the glink field blank. A random one will be generated for you.");
|
||||||
|
if (result === false) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
glinkStr = getRandomGLink();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (domain.match(domainExp) && glinkStr.match(glinkExp))/** and is available? */{
|
||||||
|
if (error.classList.contains("visible")) {
|
||||||
|
error.classList.remove("visible");
|
||||||
|
}
|
||||||
|
if (url.classList.contains("invalid")) {
|
||||||
|
url.classList.remove("invalid");
|
||||||
|
}
|
||||||
|
url.classList.add("valid");
|
||||||
|
if (glink.classList.contains("invalid")) {
|
||||||
|
glink.classList.remove("invalid");
|
||||||
|
}
|
||||||
|
glink.classList.add("valid");
|
||||||
|
error.setAttribute('aria-hidden', true);
|
||||||
|
error.setAttribute('aria-invalid', false);
|
||||||
|
console.log("Valid with url= " +url.value+ " glink=" +glink);
|
||||||
|
return valid;
|
||||||
|
} else {
|
||||||
|
/*flag*/
|
||||||
|
error.classList.add("visible");
|
||||||
|
|
||||||
|
//error.classList.add("hidden");
|
||||||
|
if (!domain.match(domainExp)) {
|
||||||
|
if (url.classList.contains("valid")) {
|
||||||
|
url.classList.remove("valid");
|
||||||
|
}
|
||||||
|
url.classList.add("invalid");
|
||||||
|
} else {
|
||||||
|
if (url.classList.contains("invalid")) {
|
||||||
|
url.classList.remove("invalid");
|
||||||
|
}
|
||||||
|
url.classList.add("valid");
|
||||||
|
}
|
||||||
|
if (!glinkStr.match(glinkExp)) {
|
||||||
|
if (glink.classList.contains("valid")) {
|
||||||
|
glink.classList.remove("valid");
|
||||||
|
}
|
||||||
|
glink.classList.add("invalid");
|
||||||
|
} else {
|
||||||
|
if (glink.classList.contains("invalid")) {
|
||||||
|
glink.classList.remove("invalid");
|
||||||
|
}
|
||||||
|
glink.classList.add("valid");
|
||||||
|
}
|
||||||
|
error.setAttribute('aria-hidden', false);
|
||||||
|
error.setAttribute('aria-invalid', true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,7 @@ use Casssandra;
|
|||||||
|
|
||||||
$cluster = Cassandra::cluster()->withPersistentSessions(true)->build();
|
$cluster = Cassandra::cluster()->withPersistentSessions(true)->build();
|
||||||
$keyspace = 'glink';
|
$keyspace = 'glink';
|
||||||
|
$session = $cluster->connect($keyspace);
|
||||||
|
|
||||||
$url = $_GET["url"];
|
$url = $_GET["url"];
|
||||||
$matches = preg_match('/^http(s)*:\\/\\/[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+$/',$url);
|
$matches = preg_match('/^http(s)*:\\/\\/[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+$/',$url);
|
||||||
@@ -55,7 +56,7 @@ if ($shortlink != '') {
|
|||||||
$shortlink = $rand_string;
|
$shortlink = $rand_string;
|
||||||
|
|
||||||
/* Check if shortlink is already taken by querying the database */
|
/* Check if shortlink is already taken by querying the database */
|
||||||
$statement = $session->prepare('SELECT url FROM data WHERE id=?');
|
$statement = $session->prepare('SELECT url FROM data WHERE shortlink=? ALLOW FILTERING');
|
||||||
$result = $session->execute($statement,array('arguments' => array($shortlink)));
|
$result = $session->execute($statement,array('arguments' => array($shortlink)));
|
||||||
|
|
||||||
if ($result->count() != 0) {
|
if ($result->count() != 0) {
|
||||||
@@ -64,8 +65,6 @@ if ($shortlink != '') {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$session = $cluster->connect($keyspace);
|
|
||||||
|
|
||||||
//$statement = new Cassandra\SimpleStatement('SELECT name FROM data WHERE id=5');
|
//$statement = new Cassandra\SimpleStatement('SELECT name FROM data WHERE id=5');
|
||||||
|
|
||||||
$statement = $session->prepare('SELECT url FROM data WHERE shortlink=? ALLOW FILTERING');
|
$statement = $session->prepare('SELECT url FROM data WHERE shortlink=? ALLOW FILTERING');
|
||||||
|
Reference in New Issue
Block a user