Compare commits
8 Commits
nodejs
...
116bbe5218
Author | SHA1 | Date | |
---|---|---|---|
116bbe5218 | |||
1b52864952 | |||
92b70e632b | |||
c81937d6a5 | |||
f451850601 | |||
3bc6a56516 | |||
536af5f9c5 | |||
e5bdf2cc2c |
@@ -7,9 +7,11 @@
|
||||
<body>
|
||||
<div id="root">
|
||||
<h1>Link Shortener</h1>
|
||||
<form id="form" action="result.js">
|
||||
<form id="form" method="GET" action="result.php" onsubmit="return validate()">
|
||||
|
||||
<!-- <form id="form"> -->
|
||||
<label for="url">URL:</label><span class="mandatory">*</span>
|
||||
<input type="text" name="url" id="URL" value="example.com" required><br><br>
|
||||
<input type="text" name="url" id="URL" value="https://example.com" required><br><br>
|
||||
|
||||
<label for="labels">GLink:</label><span class="mandatory">*</span>
|
||||
<label for="GLink" id="labels" class="glink">glink.zip/</label><input type="text" name="glink" id="GLink" class="glink" value="exampleWebsite" required>
|
||||
|
19
index.js
19
index.js
@@ -1,7 +1,7 @@
|
||||
const submit = document.getElementById("button");
|
||||
submit.addEventListener('click', validate);
|
||||
function validate(e) {
|
||||
e.preventDefault();
|
||||
//const submit = document.getElementById("button");
|
||||
//submit.addEventListener('click', validate);
|
||||
function validate() {
|
||||
// e.preventDefault();
|
||||
|
||||
const url = document.getElementById("URL");
|
||||
const glink = document.getElementById("GLink");
|
||||
@@ -48,7 +48,13 @@ function validate(e) {
|
||||
error.setAttribute('aria-hidden', true);
|
||||
error.setAttribute('aria-invalid', false);
|
||||
console.log("Valid");
|
||||
return valid;
|
||||
|
||||
return valid;
|
||||
|
||||
/* var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.open('GET','result.php',true);
|
||||
xmlhttp.send();
|
||||
console.log(xmlhttp.responseText);*/
|
||||
} else {
|
||||
|
||||
/*flag*/
|
||||
@@ -62,6 +68,7 @@ function validate(e) {
|
||||
url.classList.add("invalid");
|
||||
error.setAttribute('aria-hidden', false);
|
||||
error.setAttribute('aria-invalid', true);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
5
redirect.php
Normal file
5
redirect.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
$uri = $_SERVER['REQUEST_URI'];
|
||||
// Take the substring, and verify that it only contains capital and small letters.
|
||||
|
||||
?>
|
@@ -1,8 +0,0 @@
|
||||
const cassandra = require('cassandra-driver');
|
||||
|
||||
const client = new cassandra.Client({
|
||||
contactPoints: ['127.0.0.1:9042'],
|
||||
keyspace: 'glink',
|
||||
});
|
||||
|
||||
const query =
|
48
result.php
Normal file
48
result.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
use Casssandra;
|
||||
|
||||
$cluster = Cassandra::cluster()->build();
|
||||
$keyspace = 'glink';
|
||||
|
||||
$url = $_GET["url"];
|
||||
$matches = preg_match('/^http(s)*:\\/\\/[a-zA-Z0-9\\-]+(\\.[a-zA-Z0-9\\-]+)+$/',$url);
|
||||
if (($matches == 0) || ($matches == false)) {
|
||||
printf("The URL entered was invalid. Please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
$shortlink = $_GET["glink"];
|
||||
$matches_shortlink = preg_match('/^[a-zA-Z]+$/',$shortlink);
|
||||
if (($matches_shortlink == 0) || ($matches_shortlink == false)) {
|
||||
printf("The GLink entered was invalid. The GLink can only contain letters. Please try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$session = $cluster->connect($keyspace);
|
||||
|
||||
//$statement = new Cassandra\SimpleStatement('SELECT name FROM data WHERE id=5');
|
||||
$rand_num = rand(0,99999999);
|
||||
|
||||
$statement = $session->prepare('INSERT INTO data (id, url, shortlink, when_created) VALUES (?,?,?,toTimestamp(now()))');
|
||||
$result = $session->execute($statement,array('arguments' => array($rand_num,$url,$shortlink)));
|
||||
|
||||
$statement = $session->prepare('SELECT url,shortlink FROM data WHERE id=?');
|
||||
$options = array('arguments' => array($rand_num));
|
||||
$result = $session->execute($statement,$options);
|
||||
|
||||
//$stringRepresentation= json_encode($result[0]);
|
||||
|
||||
//printf("%s\n\n\n",$stringRepresentation);
|
||||
|
||||
foreach($result as $row) {
|
||||
if (is_null($row)) {
|
||||
printf('Unsuccessful');
|
||||
} else {
|
||||
printf('Successful: The URL you entered was: %s and your GLink is: https://glink.zip/%s', $row['url'],$row['shortlink']);
|
||||
}
|
||||
}
|
||||
//printf('Done');
|
||||
|
||||
?>
|
Reference in New Issue
Block a user