+
+
+
${photo.title}
+
+
+
+
+
+
+
+
+
+
${photo.description}
+
+
+
+
+ ${but_like}
+ ${but_dislike}
+
+
+
Tags:
+
+
+
+
+
+
Actions:
+
+
+
+
+
+
+
+
+
+
`;
+
+
+
+
+ }
+
+
+
+
+
+
+
+
+
+
+ let col = $.parseHTML(html);
+ row.append(col);
+
+ let photo_date = photo.date;
+ let date = new Date(photo_date);
+
+ let year = date.getFullYear();
+ let month = date.getMonth() + 1;
+ let day = date.getDate();
+
+
+ //let date_string = "Fecha: " + day + "/" + month + "/" + year;
+ let date_string = `Fecha: ${day}/${month}/${year}`;
+ $("p.date").last().append(date_string);
+
+
+
+ let p_tags = $("p.card-text").last();
+
+ for (var tag of photo.tags) {
+ let aux = -1;
+
+ for (var z = 0; z < tagsId.length; z++) {
+ console.log(tag);
+ if (tagsId[z] == tag) {
+
+ aux = z;
+ console.log(aux);
+ }
+ }
+ if (aux != -1) {
+
+ let tag_span = $("
", {
+ "class": "badge badge-primary",
+ text: tags[aux],
+ });
+ p_tags.append(tag_span);
+ }
+ }
+ $("span.badge").after(" ");
+ /*
+ for (var tag of photo.tags) {
+ let tag_span = $("
", {
+ "class": "badge badge-primary",
+ text: tag,
+ });
+ p_tags.append(tag_span);
+ }
+ $("span.badge").after(" ");*/
+
+ counter++;
+ photoUsId++;
+ list_img_id.push(photo.id);
+ list_us.push(photo.userId);
+ if (counter % PHOTOS_PER_ROW == 0) {
+ let new_row = $("
", { "class": "row" });
+ $("div.container-fluid").append(new_row);
+ row = new_row;
+ }
+
+ }
+
+
+ }
+}
+
+
+
+
+function deletePhoto(id) {
+
+ let cnnnt =0;
+
+ $.ajax({
+ url: "http://localhost:3000/comments?photoId=" + id,
+ success: function(data){
+ for(var element of data)
+ cnnnt++;
+
+ },
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function(){
+
+ if(cnnnt == 0){
+ fetch('http://localhost:3000/photos/' + id, {
+ method: "DELETE",
+ headers: {
+ 'Authorization': 'Bearer ' + getToken(),
+ }
+ }).then(function (response) {
+ if (response.ok) {
+ window.location.href = "index.php";
+ } else {
+ console.log("Error al borrar la foto: " + response.statusText);
+ }
+ }).catch(function (error) {
+ console.log("Error al borrar la foto: " + error);
+ });
+
+
+
+ }
+
+ else{
+
+ $("#errors-container").append(
+ getError("No se puede borrar una foto con comentarios.")
+ );
+
+ }
+
+
+
+ });
+
+
+}
+
+function removeError(error) {
+ $(error).empty();
+}
+
+function getError(message) {
+ removeError( $("#errors-container"));
+ return (
+ "
Error! " +
+ message +
+ "
"
+ );
+}
+function loadPhotos() {
+ console.log("Cargando fotos...");
+ let tok = localStorage.token
+ if (tok == null) {
+
+ var a = $.ajax({
+ url: "http://localhost:3000/tags",
+ success: function (data) {
+
+ for (var tag of data) {
+
+ tags.push(tag.tag);
+ tagsId.push(tag.id);
+ }
+
+
+
+ },
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+ $.ajax({
+ url: "http://localhost:3000/likes?userId=" + localStorage.userId,
+ success: storageLikesFromUser,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+ $.ajax({
+ url: "http://localhost:3000/dislikes?userId=" + localStorage.userId,
+ success: storageDislikesFromUser,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ })
+
+
+ }).done(function () {
+
+
+ var promise = $.ajax({
+ url: "http://localhost:3000/photos?_sort=id&_order=desc",
+ success: processPhotos,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ });
+
+ promise.then(function () {
+ // enviar(0);
+
+ $.ajax({
+ url: "http://localhost:3000/users",
+ success: processUssers,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+ fillUsers();
+
+ });
+
+
+ }).done(processScore);;
+
+
+ });
+
+
+
+ });
+
+
+
+
+
+ }
+
+ else {
+
+ var a = $.ajax({
+ url: "http://localhost:3000/tags",
+ success: function (data) {
+
+ for (var tag of data) {
+
+ tags.push(tag.tag);
+ tagsId.push(tag.id);
+ }
+
+
+
+ },
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+ $.ajax({
+ url: "http://localhost:3000/likes?userId=" + localStorage.userId,
+ success: storageLikesFromUser,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+ $.ajax({
+ url: "http://localhost:3000/dislikes?userId=" + localStorage.userId,
+ success: storageDislikesFromUser,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ })
+
+
+ }).done(function () {
+
+
+ var promise = $.ajax({
+ url: "http://localhost:3000/photos?_sort=id&_order=desc",
+ success: processPhotosLogged,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ });
+
+ promise.then(function () {
+ // enviar(0);
+
+ $.ajax({
+ url: "http://localhost:3000/users",
+ success: processUssers,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+ fillUsers();
+
+ });
+
+
+ }).done(processScore);
+
+
+
+ });
+
+ });
+
+
+
+
+ }
+
+}
+
+function storageLikesFromUser(data) {
+
+
+ for (var w of data) {
+ console.log(w);
+
+ likes.push(w.photoId);
+ }
+
+}
+
+
+function storageDislikesFromUser(data) {
+
+
+ for (var w of data) {
+
+
+ dislikes.push(w.photoId);
+ }
+
+}
+
+function processScore() {
+ let cnt = 0;
+
+ var a = $.ajax({
+ url: "http://localhost:3000/likes",
+ success: true,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+
+ for (var numero = 0; numero < photoUsId; numero++) {
+
+ let cntL = 0;
+
+
+
+ for (var w of a.responseJSON) {
+
+ if (w.photoId == list_img_id[numero]) {
+ cntL++;
+
+ }
+ }
+ cntL = cntL++;
+ let v = "#image-score-" + numero;
+ $(v).empty();
+ $(v).append(cntL);
+
+
+
+ }
+
+ var z = $.ajax({
+ url: "http://localhost:3000/dislikes",
+ success: true,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+ for (var numero = 0; numero < photoUsId; numero++) {
+
+ let cntD = 0;
+
+ for (var w of z.responseJSON) {
+
+ if (w.photoId == list_img_id[numero]) {
+ cntD = cntD - 1;
+
+ }
+ }
+
+
+ let v = "#image-score-" + numero;
+ cnt = $(v).text();
+ let va = parseInt(cnt, 10);
+ $(v).empty();
+ $(v).append("Score : " + (cntD + va));
+
+ cnt = 0;
+
+
+ }
+
+
+
+ });
+
+
+ });
+
+
+
+ var b = $.ajax({
+ url: "http://localhost:3000/dislikes",
+ success: true,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+
+
+ });
+}
+
+function processUssers(data) {
+
+ for (var user of data) {
+
+ list.push(user.user);
+
+ }
+
+
+
+}
+
+function fillUsers() {
+
+ for (var numero = 0; numero < photoUsId; numero++) {
+ let as = "#userlabel" + numero;
+
+
+ let p_user = $(as);
+
+ p_user.append(list[list_us[numero] - 1]);
+
+
+ }
+
+
+}
+
+// Llamar a loadPhotos cuando la página esté lista
+$(loadPhotos);
+function like(photoId, zId, but) {
+
+ let exist;
+ let likeId;
+ let existDistict;
+
+ var promise = $.ajax({
+
+ url: "http://localhost:3000/likes?userId=" + localStorage.userId + "&photoId=" + photoId,
+ method: "GET",
+
+ success: function (data) {
+
+
+ for (var element of data) {
+
+ exist = true;
+
+ likeId = element.id;
+ }
+
+ },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+
+
+ promise.done(
+
+ function () {
+ if (!(exist)) {
+
+ var promise = $.ajax({
+
+ url: "http://localhost:3000/dislikes?userId=" + localStorage.userId + "&photoId=" + photoId,
+ method: "GET",
+
+ success: function (data) {
+
+
+
+ for (var element of data) {
+
+ existDistict = true;
+
+ likeId = element.id;
+ }
+
+ },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+ promise.done(function () {
+
+ if (existDistict) {
+
+ $.ajax({
+
+ url: "http://localhost:3000/dislikes/" + likeId,
+ method: "DELETE",
+
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+ but.parentNode.children[1].classList.add('btn-danger');
+ but.parentNode.children[1].classList.remove('btn-success');
+
+
+
+ }
+
+ let vote = {
+
+ photoId: photoId,
+ userId: localStorage.userId
+ };
+ but.classList.add('btn-success');
+ but.classList.remove('btn-primary');
+
+ $.ajax({
+
+ url: "http://localhost:3000/likes",
+ method: "POST",
+ data: JSON.stringify(vote),
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).then(function () {
+
+ if (existDistict) {
+ ProcessOneScore(photoId, zId, +2);
+ }
+ else {
+
+ ProcessOneScore(photoId, zId, +1);
+ }
+
+
+ });
+
+
+ });
+
+ }
+
+ else {
+
+ $.ajax({
+
+ url: "http://localhost:3000/likes/" + likeId,
+ method: "DELETE",
+
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).then(ProcessOneScore(photoId, zId, -1));
+ but.classList.remove('btn-success');
+ but.classList.add('btn-primary');
+
+ }
+
+ }
+ );
+}
+function ProcessOneScore(spId, zId, val) {
+
+ let v = "#image-score-" + zId;
+ let cnt = $(v).text();
+ let a = cnt.split(":");
+ let va = parseInt(a[1].trim(), 10);
+ $(v).empty();
+ $(v).append("Score : " + (va + val));
+
+
+
+
+
+}
+function dislike(photoId, zId, but) {
+
+
+ let exist;
+ let likeId;
+ let existDistict;
+
+ var promise = $.ajax({
+
+ url: "http://localhost:3000/dislikes?userId=" + localStorage.userId + "&photoId=" + photoId,
+ method: "GET",
+
+ success: function (data) {
+
+
+
+ for (var element of data) {
+
+ exist = true;
+
+ likeId = element.id;
+ }
+
+ },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+
+ promise.done(
+
+ function () {
+ if (!(exist)) {
+
+
+ var promise = $.ajax({
+
+ url: "http://localhost:3000/likes?userId=" + localStorage.userId + "&photoId=" + photoId,
+ method: "GET",
+
+ success: function (data) {
+
+
+
+ for (var element of data) {
+
+ existDistict = true;
+
+ likeId = element.id;
+ }
+
+ },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+
+ promise.done(function () {
+
+ if (existDistict) {
+ $.ajax({
+
+ url: "http://localhost:3000/likes/" + likeId,
+ method: "DELETE",
+
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+ but.parentNode.children[0].classList.add('btn-primary');
+ but.parentNode.children[0].classList.remove('btn-success');
+ }
+ but.classList.remove('btn-danger');
+ but.classList.add('btn-success');
+ let vote = {
+
+ photoId: photoId,
+ userId: localStorage.userId
+ };
+
+ $.ajax({
+
+ url: "http://localhost:3000/dislikes",
+ method: "POST",
+ data: JSON.stringify(vote),
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).done(
+
+ function () {
+ if (existDistict) {
+ ProcessOneScore(photoId, zId, -2);
+ }
+ else {
+
+ ProcessOneScore(photoId, zId, -1);
+ }
+ });
+
+
+ });
+
+ }
+
+
+ else {
+
+ $.ajax({
+
+ url: "http://localhost:3000/dislikes/" + likeId,
+ method: "DELETE",
+
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).done(ProcessOneScore(photoId, zId, +1));
+ but.classList.remove('btn-success');
+ but.classList.add('btn-danger');
+ }
+
+ }
+ );
+
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/js/login.js b/js/login.js
new file mode 100644
index 0000000..1afd01c
--- /dev/null
+++ b/js/login.js
@@ -0,0 +1,41 @@
+function validateForm() {
+ let email = $("#input-email").val();
+ let password = $("#input-password").val();
+
+ // Hay que validar este formulario como cualquier otro!!!
+
+ let login_data = {
+ email,
+ password,
+ };
+
+ $.ajax({
+ url: "http://localhost:3000/login",
+ method: "POST",
+ contentType: "application/json",
+ data: JSON.stringify(login_data),
+
+ success: handleLogin,
+ error: function(){
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el login y mostrárselo al usuario
+ });
+
+ return false;
+}
+
+function getError(message) {
+ return (
+ "
Error! " +
+ message +
+ "
"
+ );
+}
+function handleLogin(data) {
+ let token = data.accessToken;
+ saveToken(token).then(function () {
+ window.location.href = "index.php";
+ });
+}
diff --git a/js/mypictures.js b/js/mypictures.js
new file mode 100644
index 0000000..70d591a
--- /dev/null
+++ b/js/mypictures.js
@@ -0,0 +1,683 @@
+const PHOTOS_PER_ROW = 3;
+let photoUsId = 0;
+let list_img_id = [];
+let likes = [];
+let dislikes = [];
+let tags = [];
+let tagsId = [];
+const maxImg = 5;
+
+
+function addNewPictures(){
+
+ if(maxImg>photoUsId){
+
+ window.location.href = "create_picture.php";
+
+
+ }
+
+ else{
+
+ $("#errors-container").append(
+ getError("Se ha superado el número máximo de fotos, borra 1 para poder añadir nuevas imágenes.")
+ );
+
+ }
+
+
+
+}
+
+
+function getError(message) {
+ return (
+ "
Error! " +
+ message +
+ "
"
+ );
+}
+function deletePhoto(id) {
+ let cnnnt =0;
+
+ $.ajax({
+ url: "http://localhost:3000/comments?photoId=" + id,
+ success: function(data){
+ for(var element of data)
+ cnnnt++;
+
+ },
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function(){
+
+ if(cnnnt == 0){
+ fetch('http://localhost:3000/photos/' + id, {
+ method: "DELETE",
+ headers: {
+ 'Authorization': 'Bearer ' + getToken(),
+ }
+ }).then(function (response) {
+ if (response.ok) {
+ window.location.href = "index.php";
+ } else {
+ console.log("Error al borrar la foto: " + response.statusText);
+ }
+ }).catch(function (error) {
+ console.log("Error al borrar la foto: " + error);
+ });
+
+
+
+ }
+
+ else{
+
+ $("#errors-container").append(
+ getError("No se puede borrar una foto con comentarios.")
+ );
+
+ }
+
+
+
+ });
+}
+
+
+
+function processPhotos(data) {
+ let row = $("div.container-fluid > div.row").last();
+ let counter = 0;
+
+ //cambiamos photo Id por photo edit para el test
+ for (photo of data) {
+ console.log(likes);
+ let but_like = `
`;
+ if (likes.includes(photo.id)) {
+ but_like = `
`;
+ }
+ let but_dislike = `
`;
+
+ if (dislikes.includes(photo.id)) {
+
+ but_dislike = `
`;
+ }
+
+
+ let html = `
+
${photo.title}
+
+
+
+
+
+
+
+
+
+
${photo.description}
+
+
+
+
+ ${but_like}
+ ${but_dislike}
+
+
+
Tags:
+
+
+
+
+
+
Actions:
+
+
+
+
+
+
`;
+
+ photoUsId++;
+ list_img_id.push(photo.id);
+
+ let col = $.parseHTML(html);
+ row.append(col);
+ let photo_date = photo.date;
+ let date = new Date(photo_date);
+
+ let year = date.getFullYear();
+ let month = date.getMonth() + 1;
+ let day = date.getDate();
+
+
+ //let date_string = "Fecha: " + day + "/" + month + "/" + year;
+ let date_string = `Fecha: ${day}/${month}/${year}`;
+ $("p.date").last().append(date_string);
+
+ let p_tags = $("p.card-text").last();
+
+ for (tag of photo.tags) {
+ let aux = -1;
+
+ for (var z = 0; z < tagsId.length; z++) {
+ console.log(tag);
+ if (tagsId[z] == tag) {
+
+ aux = z;
+ console.log(aux);
+ }
+ }
+ if (aux != -1) {
+
+ let tag_span = $("
", {
+ "class": "badge badge-primary",
+ text: tags[aux],
+ });
+ p_tags.append(tag_span);
+ }
+ }
+ $("span.badge").after(" ");
+
+ counter++;
+ if (counter % PHOTOS_PER_ROW == 0) {
+ let new_row = $("
", { "class": "row" });
+ $("div.container-fluid").append(new_row);
+ row = new_row;
+ }
+ }
+}
+
+
+
+function loadPhotos() {
+ console.log("Cargando fotos...");
+ //let tok = localStorage.token
+ // if(tok == null){
+ let tok = localStorage.userId;
+ $.ajax({
+ url: "http://localhost:3000/photos?_sort=id&_order=desc&userId=" + tok,
+ success: processPhotos,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(processScore());
+
+
+
+}
+
+function processScore() {
+ let cnt = 0;
+
+ var a = $.ajax({
+ url: "http://localhost:3000/likes",
+ success: true,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+
+ for (var numero = 0; numero < photoUsId; numero++) {
+
+ let cntL = 0;
+
+
+
+ for (var w of a.responseJSON) {
+
+ if (w.photoId == list_img_id[numero]) {
+ cntL++;
+
+ }
+ }
+ cntL = cntL++;
+ let v = "#image-score-" + numero;
+ $(v).empty();
+ $(v).append(cntL);
+
+
+
+ }
+
+ var z = $.ajax({
+ url: "http://localhost:3000/dislikes",
+ success: true,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+ for (var numero = 0; numero < photoUsId; numero++) {
+
+ let cntD = 0;
+
+ for (var w of z.responseJSON) {
+
+ if (w.photoId == list_img_id[numero]) {
+ cntD = cntD - 1;
+
+ }
+ }
+
+
+ let v = "#image-score-" + numero;
+ cnt = $(v).text();
+ let va = parseInt(cnt.trim(), 10);
+ $(v).empty();
+ $(v).append("Score : " + (cntD + va));
+
+ cnt = 0;
+
+
+ }
+
+
+
+ });
+
+
+ });
+
+
+
+ var b = $.ajax({
+ url: "http://localhost:3000/dislikes",
+ success: true,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+
+
+ });
+}
+
+// Llamar a loadPhotos cuando la página esté lista
+
+
+
+function storageLikesFromUser(data) {
+
+
+ for (var w of data) {
+ console.log(w);
+
+ likes.push(w.photoId);
+ }
+
+}
+
+
+function storageDislikesFromUser(data) {
+
+
+ for (var w of data) {
+
+
+ dislikes.push(w.photoId);
+ }
+
+}
+
+function loadPage() {
+
+ var a = $.ajax({
+ url: "http://localhost:3000/tags",
+ success: function (data) {
+
+ for (var tag of data) {
+
+ tags.push(tag.tag);
+ tagsId.push(tag.id);
+ }
+
+
+
+ },
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ });
+
+ a.done(function () {
+ $.ajax({
+ url: "http://localhost:3000/likes?userId=" + localStorage.userId,
+ success: storageLikesFromUser,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+ $.ajax({
+ url: "http://localhost:3000/dislikes?userId=" + localStorage.userId,
+ success: storageDislikesFromUser,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ })
+
+
+ }).done(loadPhotos);
+ });
+
+
+}
+
+function ProcessOneScore(spId, zId, val) {
+
+ let v = "#image-score-" + zId;
+ cnt = $(v).text();
+ let a = cnt.split(":");
+ let va = parseInt(a[1].trim(), 10);
+ $(v).empty();
+ $(v).append("Score : " + (va + val));
+
+
+
+
+
+}
+function like(photoId, zId, but) {
+
+ let exist;
+ let likeId;
+ let existDistict;
+
+ var promise = $.ajax({
+
+ url: "http://localhost:3000/likes?userId=" + localStorage.userId + "&photoId=" + photoId,
+ method: "GET",
+
+ success: function (data) {
+
+
+ for (var element of data) {
+
+ exist = true;
+
+ likeId = element.id;
+ }
+
+ },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+
+
+ promise.done(
+
+ function () {
+ if (!(exist)) {
+
+ var promise = $.ajax({
+
+ url: "http://localhost:3000/dislikes?userId=" + localStorage.userId + "&photoId=" + photoId,
+ method: "GET",
+
+ success: function (data) {
+
+
+
+ for (var element of data) {
+
+ existDistict = true;
+
+ likeId = element.id;
+ }
+
+ },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+ promise.done(function () {
+
+ if (existDistict) {
+
+ $.ajax({
+
+ url: "http://localhost:3000/dislikes/" + likeId,
+ method: "DELETE",
+
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+ but.parentNode.children[1].classList.add('btn-danger');
+ but.parentNode.children[1].classList.remove('btn-success');
+
+
+
+ }
+
+ let vote = {
+
+ photoId: photoId,
+ userId: localStorage.userId
+ };
+ but.classList.add('btn-success');
+ but.classList.remove('btn-primary');
+
+ $.ajax({
+
+ url: "http://localhost:3000/likes",
+ method: "POST",
+ data: JSON.stringify(vote),
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).then(function () {
+
+ if (existDistict) {
+ ProcessOneScore(photoId, zId, +2);
+ }
+ else {
+
+ ProcessOneScore(photoId, zId, +1);
+ }
+
+
+ });
+
+
+ });
+
+ }
+
+ else {
+
+ $.ajax({
+
+ url: "http://localhost:3000/likes/" + likeId,
+ method: "DELETE",
+
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).then(ProcessOneScore(photoId, zId, -1));
+ but.classList.remove('btn-success');
+ but.classList.add('btn-primary');
+
+ }
+
+ }
+ );
+}
+
+
+function dislike(photoId, zId, but) {
+
+
+ let exist;
+ let likeId;
+ let existDistict;
+
+ var promise = $.ajax({
+
+ url: "http://localhost:3000/dislikes?userId=" + localStorage.userId + "&photoId=" + photoId,
+ method: "GET",
+
+ success: function (data) {
+
+
+
+ for (var element of data) {
+
+ exist = true;
+
+ likeId = element.id;
+ }
+
+ },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+
+ promise.done(
+
+ function () {
+ if (!(exist)) {
+
+
+ var promise = $.ajax({
+
+ url: "http://localhost:3000/likes?userId=" + localStorage.userId + "&photoId=" + photoId,
+ method: "GET",
+
+ success: function (data) {
+
+
+
+ for (var element of data) {
+
+ existDistict = true;
+
+ likeId = element.id;
+ }
+
+ },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+
+ promise.done(function () {
+
+ if (existDistict) {
+ $.ajax({
+
+ url: "http://localhost:3000/likes/" + likeId,
+ method: "DELETE",
+
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+ but.parentNode.children[0].classList.add('btn-primary');
+ but.parentNode.children[0].classList.remove('btn-success');
+ }
+ but.classList.remove('btn-danger');
+ but.classList.add('btn-success');
+ let vote = {
+
+ photoId: photoId,
+ userId: localStorage.userId
+ };
+
+ $.ajax({
+
+ url: "http://localhost:3000/dislikes",
+ method: "POST",
+ data: JSON.stringify(vote),
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).done(
+
+ function () {
+ if (existDistict) {
+ ProcessOneScore(photoId, zId, -2);
+ }
+ else {
+
+ ProcessOneScore(photoId, zId, -1);
+ }
+ });
+
+
+ });
+
+ }
+
+
+ else {
+
+ $.ajax({
+
+ url: "http://localhost:3000/dislikes/" + likeId,
+ method: "DELETE",
+
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).done(ProcessOneScore(photoId, zId, +1));
+ but.classList.remove('btn-success');
+ but.classList.add('btn-danger');
+ }
+
+ }
+ );
+
+}
+
+
+
+
+
+
+
+$(loadPage);
diff --git a/js/photoDetail.js b/js/photoDetail.js
new file mode 100644
index 0000000..2e89d82
--- /dev/null
+++ b/js/photoDetail.js
@@ -0,0 +1,735 @@
+/*const queryString = window.location.search;
+const urlParams = new URLSearchParams(queryString);
+const id = urlParams.get('photoId');*/
+const id = window.location.search.split('=')[1];
+const photoId = id;
+let photoUsId = 0;
+let list_img_id = [];
+let likes = [];
+let dislikes = [];
+let list = [];
+let tags = [];
+let tagsId = [];
+let photId;
+
+list_img_id.push(window.location.search.split('=')[1]);
+/*
+function editPhoto() {
+ window.location.href = "photo_edit.php?id=" + id;
+}
+
+function deletePhoto() {
+ fetch('http://localhost:3000/photos/' + id, {
+ method: "DELETE",
+ headers: {
+ 'Authorization': 'Bearer ' + getToken(),
+ }
+ }).then(function(response) {
+ if(response.ok) {
+ window.location.href = "index.php";
+ } else {
+ console.log("Error al borrar la foto: " + response.statusText);
+ }
+ }).catch(function(error){
+ console.log("Error al borrar la foto: " + error);
+ });
+ }
+*/
+function processPhotoLoad(data) {
+ $("#image").attr("src", data.url);
+ $("#image-title").text(data.title);
+ $("#image-desc").text(data.description);
+
+ loadComments(data.id);
+ photId = data.id;
+ let photo_date = data.date;
+ let date = new Date(photo_date);
+
+ let year = date.getFullYear();
+ let month = date.getMonth() + 1;
+ let day = date.getDate();
+ let tok = localStorage.userId;
+ list_img_id.push(data.id);
+ let but_like = `
`;
+ if (likes.includes(data.id)) {
+ but_like = `
`;
+ }
+ let but_dislike = `
`;
+ console.log( " aaaaaa "+ dislikes );
+ if (dislikes.includes(data.id)) {
+
+ but_dislike = `
`;
+ }
+
+ //let date_string = "Fecha: " + day + "/" + month + "/" + year;
+ let date_string = `Fecha: ${day}/${month}/${year}`;
+ $("#image-date").text(date_string);
+ let p_tags = $("p.card-text").last();
+ for (tag of data.tags) {
+ let aux = -1;
+
+ for (var z = 0; z < tagsId.length; z++) {
+ console.log(tag);
+ if (tagsId[z] == tag) {
+
+ aux = z;
+ console.log(aux);
+ }
+ }
+ if (aux != -1) {
+
+ let tag_span = $("
", {
+ "class": "badge badge-primary",
+ text: tags[aux],
+ });
+ p_tags.append(tag_span);
+ }
+ }
+ $("span.badge").after(" ");
+ $("#votebutton").append(but_like);
+ $("#votebutton").append(but_dislike);
+ let score = data.upvotes - data.downvotes;
+ let score_text = "Puntuación: " + score;
+ $("#image-score").text(score_text);
+
+ if (tok == data.userId) {
+
+ $('#follow').remove();
+ }
+}
+
+function processUssers(data) {
+
+ for (var user of data) {
+
+ list.push(user.user);
+
+ }
+
+
+
+}
+
+let bw = [];
+loadBadWords();
+
+function loadBadWords(){
+
+ $.ajax({
+ url: "http://localhost:3000/badwords",
+ success: function(data){
+
+ for(i of data){
+ bw.push(i.word);
+ }
+ },
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function(){console.log(bw)});
+
+
+}
+
+function addComment(){
+
+ let comm = $("#input-comment").val();
+
+ let palabrota = false;
+ for(z of bw){
+
+
+ if(comm.includes(z)){
+
+ palabrota = true;
+ }
+ }
+
+ if(palabrota){
+
+ $("#errors-container").append(
+ getError("Esa boca.")
+ );
+ }
+
+ else{
+
+ let comment ={
+
+ userId: localStorage.userId,
+ comment: comm,
+ photoId : photId
+ }
+
+ $.ajax({
+
+ url: "http://localhost:3000/comments",
+ method: "POST",
+ data: JSON.stringify(comment),
+ contentType: "application/json",
+ success: function(){
+
+ location.reload();
+ },
+ error: function(){
+ $("#errors-container").append(
+ getError("Vaya ha habido un fallo subiendo ese comentario.")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+
+
+ }
+
+}
+
+function getError(message) {
+ removeError( $("#errors-container"));
+ return (
+ "
Error! " +
+ message +
+ "
"
+ );
+}
+
+
+function removeError(error) {
+ $(error).empty();
+}
+
+
+function loadComments(pid){
+
+ $.ajax({
+ url: "http://localhost:3000/users",
+ success: processUssers,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function(){
+
+
+ $.ajax({
+ url: "http://localhost:3000/comments?photoId=" + pid,
+ success: function(data){
+
+
+ for(com of data){
+
+ $("#image-comments").append(
+
+ `
+
+

+
+
+
${list[com.userId-1]}
+
+
+
+
+
+
+
+
+
+
+
+
`
+
+
+ )
+
+
+ }
+
+
+ },
+ error: console.log,
+ });
+
+
+
+
+ });
+
+
+
+
+
+}
+
+
+
+function loadPhoto() {
+ if (id === null) {
+ alert("Please provide a photo ID");
+ } else {
+ $.ajax({
+ url: "http://localhost:3000/photos/" + id,
+ success: processPhotoLoad,
+ error: console.log,
+ }).done(processScore());
+ }
+}
+function storageLikesFromUser(data) {
+
+
+ for (var w of data) {
+ console.log(w);
+
+ likes.push(w.photoId);
+ }
+
+}
+
+
+var a = $.ajax({
+ url: "http://localhost:3000/tags",
+ success: function (data) {
+
+ for (var tag of data) {
+
+ tags.push(tag.tag);
+ tagsId.push(tag.id);
+ }
+
+
+
+ },
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+});
+
+a.done(function(){$.ajax({
+ url: "http://localhost:3000/likes?userId=" + localStorage.userId,
+ success: storageLikesFromUser,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+}).done(function () {
+
+ $.ajax({
+ url: "http://localhost:3000/dislikes?userId=" + localStorage.userId,
+ success: storageDislikesFromUser,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ })
+
+
+}).done(loadPhoto);});
+function storageDislikesFromUser(data) {
+
+
+ for (var w of data) {
+
+
+ dislikes.push(w.photoId);
+
+ }
+ console.log(dislikes);
+}
+
+ // Cargar la foto cuando la página esté lista
+
+function processScore() {
+ let cnt = 0;
+
+ var a = $.ajax({
+ url: "http://localhost:3000/likes?photoId=" + id,
+ success: true,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+
+
+
+ let cntL = 0;
+
+
+
+ for (var w of a.responseJSON) {
+
+
+ cntL++;
+
+
+ }
+ cntL = cntL++;
+ let v = "#image-score-0";
+ $(v).empty();
+ $(v).append(cntL);
+
+
+
+
+
+
+ var z = $.ajax({
+ url: "http://localhost:3000/dislikes?photoId=" + id,
+ success: true,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+
+
+ let cntD = 0;
+
+ for (var w of z.responseJSON) {
+
+
+ cntD = cntD - 1;
+
+
+ }
+
+
+ let v = "#image-score-0";
+ cnt = $(v).text();
+ let va = parseInt(cnt, 10);
+ $(v).empty();
+ $(v).append("Score : " + (cntD + va));
+
+ cnt = 0;
+
+
+
+
+
+
+ });
+
+
+ });
+
+
+
+ var b = $.ajax({
+ url: "http://localhost:3000/dislikes",
+ success: true,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+
+
+ });
+}
+
+// Llamar a loadPhotos cuando la página esté lista
+
+function like(photoId, zId, but) {
+
+ let exist;
+ let likeId;
+ let existDistict;
+
+ var promise = $.ajax({
+
+ url: "http://localhost:3000/likes?userId=" + localStorage.userId + "&photoId=" + photoId,
+ method: "GET",
+
+ success: function (data) {
+
+
+ for (var element of data) {
+
+ exist = true;
+
+ likeId = element.id;
+ }
+
+ },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+
+
+ promise.done(
+
+ function () {
+ if (!(exist)) {
+
+ var promise = $.ajax({
+
+ url: "http://localhost:3000/dislikes?userId=" + localStorage.userId + "&photoId=" + photoId,
+ method: "GET",
+
+ success: function (data) {
+
+
+
+ for (var element of data) {
+
+ existDistict = true;
+
+ likeId = element.id;
+ }
+
+ },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+ promise.done(function () {
+
+ if (existDistict) {
+
+ $.ajax({
+
+ url: "http://localhost:3000/dislikes/" + likeId,
+ method: "DELETE",
+
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+ but.parentNode.children[1].classList.add('btn-danger');
+ but.parentNode.children[1].classList.remove('btn-success');
+
+
+
+ }
+
+ let vote = {
+
+ photoId: photoId,
+ userId: localStorage.userId
+ };
+ but.classList.add('btn-success');
+ but.classList.remove('btn-primary');
+
+ $.ajax({
+
+ url: "http://localhost:3000/likes",
+ method: "POST",
+ data: JSON.stringify(vote),
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).then(function () {
+
+ if (existDistict) {
+ ProcessOneScore(photoId, zId, +2);
+ }
+ else {
+
+ ProcessOneScore(photoId, zId, +1);
+ }
+
+
+ });
+
+
+ });
+
+ }
+
+ else {
+
+ $.ajax({
+
+ url: "http://localhost:3000/likes/" + likeId,
+ method: "DELETE",
+
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).then(ProcessOneScore(photoId, zId, -1));
+ but.classList.remove('btn-success');
+ but.classList.add('btn-primary');
+
+ }
+
+ }
+ );
+}
+
+
+function dislike(photoId, zId, but) {
+
+
+ let exist;
+ let likeId;
+ let existDistict;
+
+ var promise = $.ajax({
+
+ url: "http://localhost:3000/dislikes?userId=" + localStorage.userId + "&photoId=" + photoId,
+ method: "GET",
+
+ success: function (data) {
+
+
+
+ for (var element of data) {
+
+ exist = true;
+
+ likeId = element.id;
+ }
+
+ },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+
+ promise.done(
+
+ function () {
+ if (!(exist)) {
+
+
+ var promise = $.ajax({
+
+ url: "http://localhost:3000/likes?userId=" + localStorage.userId + "&photoId=" + photoId,
+ method: "GET",
+
+ success: function (data) {
+
+
+
+ for (var element of data) {
+
+ existDistict = true;
+
+ likeId = element.id;
+ }
+
+ },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+
+
+ promise.done(function () {
+
+ if (existDistict) {
+ $.ajax({
+
+ url: "http://localhost:3000/likes/" + likeId,
+ method: "DELETE",
+
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+ but.parentNode.children[0].classList.add('btn-primary');
+ but.parentNode.children[0].classList.remove('btn-success');
+ }
+ but.classList.remove('btn-danger');
+ but.classList.add('btn-success');
+ let vote = {
+
+ photoId: photoId,
+ userId: localStorage.userId
+ };
+
+ $.ajax({
+
+ url: "http://localhost:3000/dislikes",
+ method: "POST",
+ data: JSON.stringify(vote),
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).done(
+
+ function () {
+ if (existDistict) {
+ ProcessOneScore(photoId, zId, -2);
+ }
+ else {
+
+ ProcessOneScore(photoId, zId, -1);
+ }
+ });
+
+
+ });
+
+ }
+
+
+ else {
+
+ $.ajax({
+
+ url: "http://localhost:3000/dislikes/" + likeId,
+ method: "DELETE",
+
+ contentType: "application/json",
+ success: function () { },
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).done(ProcessOneScore(photoId, zId, +1));
+ but.classList.remove('btn-success');
+ but.classList.add('btn-danger');
+ }
+
+ }
+ );
+
+}
+
+
+function ProcessOneScore(spId, zId, val) {
+
+ let v = "#image-score-" + zId;
+ cnt = $(v).text();
+ let a = cnt.split(":");
+ let va = parseInt(a[1].trim(), 10);
+ $(v).empty();
+ $(v).append("Score : " + (va + val));
+
+
+
+
+
+}
\ No newline at end of file
diff --git a/js/register.js b/js/register.js
new file mode 100644
index 0000000..a6f3820
--- /dev/null
+++ b/js/register.js
@@ -0,0 +1,156 @@
+let errorCounterBw = 0;
+let bw = [];
+loadBadWords();
+
+function loadBadWords(){
+
+ $.ajax({
+ url: "http://localhost:3000/badwords",
+ success: function(data){
+
+ for(i of data){
+ bw.push(i.word);
+ }
+ },
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function(){console.log(bw)});
+
+
+}
+
+
+function validateForm() {
+ $("#errors-container").empty();
+
+ let errorCounter = 0;
+
+ console.log("Asacatun");
+ let nombre = $("#input-name").val();
+ let apellidos = $("#input-surname").val();
+ let telefono = $("#input-telephone").val();
+ let email = $("#input-email").val();
+ let usuario = $("#input-username").val();
+ let password1 = $("#input-password1").val();
+ let password2 = $("#input-password2").val();
+ let accept = $("#input-accept")[0].checked;
+ console.log(accept);
+ console.log("Inicio variables");
+ if (nombre.trim().length < 3) {
+ $("#errors-container").append(
+ getError("El nombre debe tener al menos 3 caracteres de longitud")
+ );
+ errorCounter++;
+ }
+
+ if (apellidos.trim().length < 6) {
+ $("#errors-container").append(
+ getError("Los apellidos deben tener al menos 6 caracteres de longitud")
+ );
+ errorCounter++;
+ }
+
+ if (
+ !new RegExp("^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-s./0-9]*$").test(telefono)
+ ) {
+ $("#errors-container").append(getError("El telefono esta mal formateado"));
+ errorCounter++;
+ }
+
+ if (password1 != password2) {
+ $("#errors-container").append(
+ getError("Las contraseñas deben ser iguales")
+ );
+ errorCounter++;
+ }
+
+ if (accept){
+
+
+ }
+ else{
+
+ errorCounter++;
+ }
+ console.log("Trato variables");
+ console.log(errorCounter);
+
+ if (errorCounter === 0) {
+ let user = {
+ name: nombre,
+ surname: apellidos,
+ phone: telefono,
+ email: email,
+ password: password1,
+ user: usuario,
+ };
+ for(z of bw){
+
+ if(nombre.includes(z)||apellidos.includes(z)||telefono.includes(z)||email.includes(z)||usuario.includes(z)){
+ errorCounterBw++;
+ console.log("palabramala");}
+ }
+ if(errorCounterBw==0){
+ $.ajax({
+
+ url: "http://localhost:3000/register",
+ method: "POST",
+ data: JSON.stringify(user),
+ contentType: "application/json",
+ success: handleRegister,
+ error: function(data){
+ $("#errors-container").append(
+ getError(data.responseJSON)
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ });
+ }
+ else{
+
+ $("#errors-container").append(
+ getError("¡Cuidado con ese vocabulario!")
+ );
+ errorCounterBw = 0;
+ }
+
+
+ }
+
+ return false;
+}
+
+function handleRegister(data) {
+ let token = data.accessToken;
+ saveToken(token).then(() => {
+ window.location.href = "index.php";
+ });
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+function getError(message) {
+ return (
+ "
Error! " +
+ message +
+ "
"
+ );
+}
+
+
+function removeError(error) {
+ $(error).remove();
+}
+
+$(document).ready(function () {
+ $("#name").change(function () {
+ input = $(this);
+ if (input.val().length < 3) {
+ input.removeClass("is-valid");
+ input.addClass("is-invalid");
+ } else {
+ input.removeClass("is-invalid");
+ input.addClass("is-valid");
+ }
+ });
+});
diff --git a/js/scripts.js b/js/scripts.js
new file mode 100644
index 0000000..7577ba6
--- /dev/null
+++ b/js/scripts.js
@@ -0,0 +1,24 @@
+/*let date = new Date();
+
+let day = date.getDate();
+let month = date.getMonth() + 1; // Months are 0-based for some reason...
+let year = date.getFullYear();
+
+let hour = date.getHours();
+let minutes = date.getMinutes();
+let seconds = date.getSeconds();
+
+// Add a leading 0 if they're only one digit
+hour = hour.toString().padStart(2, "0");
+minutes = minutes.toString().padStart(2, "0");
+seconds = seconds.toString().padStart(2, "0");
+*/
+/*
+ Print the current date
+ and a message to report that we're finished
+*/
+/*
+console.log("Loading finished.")
+console.log(`The current time is: ${day}/${month}/${year} ${hour}:${minutes}:${seconds}`);*/
+
+// Alternatively, we can use alert() to emit a popup message
diff --git a/js/token_decode.js b/js/token_decode.js
new file mode 100644
index 0000000..31e7c2a
--- /dev/null
+++ b/js/token_decode.js
@@ -0,0 +1,128 @@
+(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o
> (-2 * bc & 6)) : 0
+ ) {
+ // try to find character in table (0-63, not found => -1)
+ buffer = chars.indexOf(buffer);
+ }
+ return output;
+}
+
+
+module.exports = typeof window !== 'undefined' && window.atob && window.atob.bind(window) || polyfill;
+
+},{}],2:[function(require,module,exports){
+var atob = require('./atob');
+
+function b64DecodeUnicode(str) {
+ return decodeURIComponent(atob(str).replace(/(.)/g, function (m, p) {
+ var code = p.charCodeAt(0).toString(16).toUpperCase();
+ if (code.length < 2) {
+ code = '0' + code;
+ }
+ return '%' + code;
+ }));
+}
+
+module.exports = function(str) {
+ var output = str.replace(/-/g, "+").replace(/_/g, "/");
+ switch (output.length % 4) {
+ case 0:
+ break;
+ case 2:
+ output += "==";
+ break;
+ case 3:
+ output += "=";
+ break;
+ default:
+ throw "Illegal base64url string!";
+ }
+
+ try{
+ return b64DecodeUnicode(output);
+ } catch (err) {
+ return atob(output);
+ }
+};
+
+},{"./atob":1}],3:[function(require,module,exports){
+'use strict';
+
+var base64_url_decode = require('./base64_url_decode');
+
+function InvalidTokenError(message) {
+ this.message = message;
+}
+
+InvalidTokenError.prototype = new Error();
+InvalidTokenError.prototype.name = 'InvalidTokenError';
+
+module.exports = function (token,options) {
+ if (typeof token !== 'string') {
+ throw new InvalidTokenError('Invalid token specified');
+ }
+
+ options = options || {};
+ var pos = options.header === true ? 0 : 1;
+ try {
+ return JSON.parse(base64_url_decode(token.split('.')[pos]));
+ } catch (e) {
+ throw new InvalidTokenError('Invalid token specified: ' + e.message);
+ }
+};
+
+module.exports.InvalidTokenError = InvalidTokenError;
+
+},{"./base64_url_decode":2}],4:[function(require,module,exports){
+(function (global){
+/*
+ *
+ * This is used to build the bundle with browserify.
+ *
+ * The bundle is used by people who doesn't use browserify.
+ * Those who use browserify will install with npm and require the module,
+ * the package.json file points to index.js.
+ */
+var jwt_decode = require('./lib/index');
+let getTokenID = token => jwt_decode(token).sub;
+
+//use amd or just throught to window object.
+if (typeof global.window.define == 'function' && global.window.define.amd) {
+ global.window.define('jwt_decode', function () { return jwt_decode; });
+ global.window.define('getTokenID', function () { return getTokenID; });
+} else if (global.window) {
+ global.window.jwt_decode = jwt_decode;
+ global.window.getTokenID = getTokenID;
+}
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+
+},{"./lib/index":3}]},{},[4])
+
diff --git a/js/uploadphoto.js b/js/uploadphoto.js
new file mode 100644
index 0000000..686448f
--- /dev/null
+++ b/js/uploadphoto.js
@@ -0,0 +1,453 @@
+function getError(message) {
+ return " Error! " + message + "
";
+}
+
+let cntTag = 0;
+let cntNewTag = 0;
+let photoNumber = 0;
+let errorCounter = 0;
+
+let tagsId = [];
+let tagsServidor = [];
+let tags = [];
+let newTags = [];
+loadServerTags();
+const maxImg = 5;
+let bw = [];
+
+loadPhotosNumber();
+loadBadWords();
+
+function loadBadWords() {
+
+ $.ajax({
+ url: "http://localhost:3000/badwords",
+ success: function (data) {
+
+ for (i of data) {
+ bw.push(i.word);
+ }
+ },
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () { console.log(bw) });
+
+
+}
+
+function loadPhotosNumber() {
+
+
+ $.ajax({
+ url: "http://localhost:3000/photos?userId=" + localStorage.userId,
+ success: function (data) {
+
+ for (i of data) {
+ photoNumber++;
+ console.log(photoNumber);
+ }
+ },
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+
+ if (maxImg <= photoNumber) {
+ $("#errors-container").append(
+ getError("Se ha superado el número máximo de fotos, borra 1 para poder añadir nuevas imágenes.")
+ );
+ }
+
+ });
+
+
+}
+function loadServerTags() {
+
+ $.ajax({
+ url: "http://localhost:3000/tags",
+ success: processServerTags,
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ });
+}
+
+function processServerTags(data) {
+
+
+ for (tag of data) {
+
+
+ tagsServidor.push(tag.tag);
+ tagsId.push(tag.id);
+ }
+
+}
+
+function getError(message) {
+ return (
+ " Error! " +
+ message +
+ "
"
+ );
+}
+
+$("form").submit(function (event) {
+
+ photoNumber = 0;
+
+ $.ajax({
+ url: "http://localhost:3000/photos?userId=" + localStorage.userId,
+ success: function (data) {
+
+ for (i of data) {
+ photoNumber++;
+ console.log(photoNumber);
+ }
+ },
+ error: function (error) {
+ console.log("Ha ocurrido un error: " + error.toString());
+ }
+ }).done(function () {
+
+
+ if (maxImg <= photoNumber) {
+ $("#errors-container").append(
+ getError("Se ha superado el número máximo de fotos, borra 1 para poder añadir nuevas imágenes.")
+ );
+ }
+
+ else {
+
+ let tags = [];
+
+ if (maxImg > photoNumber) {
+
+ event.preventDefault();
+ $("#errors-container").empty();
+
+ let url = $("#input-url").val();
+ let title = $("#input-title").val();
+
+
+ let description = $("#input-description").val();
+ //let tags = $("#input-tags").val().split(",").map(tag => tag.trim());
+
+
+
+ for (n = 0; n < cntTag + 1; n++) {
+
+ let p = "#input-tags-" + n;
+
+ let w = $(p)[0];
+ console.log(w);
+
+ if (w != undefined && w[w.selectedIndex].text != null && w[w.selectedIndex].text != undefined && !(tags.includes(w[w.selectedIndex].text))) {
+
+ tags.push(w[w.selectedIndex].text);
+ }
+ }
+
+ for (n = 0; n < cntNewTag + 1; n++) {
+
+ let p = "#input-new-tags-" + n;
+
+ let w = $(p);
+
+ if (w.val() != null && $.trim(w.val()).length !== 0 && w != undefined && !(tags.includes(w.val())) && !(tagsServidor.includes(w.val()))) {
+
+ tags.push(w.val());
+ tagsServidor.push(w.val());
+ let aux = 0;
+ for (l of tagsId) {
+
+ if (l > aux) {
+ aux = l;
+ }
+ }
+
+ aux++;
+ tagsId.push(aux);
+ newTags.push(aux);
+
+
+ let tag = {
+ tag: w.val(),
+
+ };
+
+ if (errorCounter == 0) {
+ let blbw = true;
+ for (zk of bw) {
+
+ if (w.val().includes(zk)) {
+
+ blbw = false;
+ }
+ }
+ if (maxImg > photoNumber) {
+ if (blbw) {
+ $.ajax({
+
+ url: "http://localhost:3000/tags",
+ method: "POST",
+ data: JSON.stringify(tag),
+ contentType: "application/json",
+ success: true,
+ error: function () {
+ $("#errors-container").append(
+ getError("Ha habido un error")
+ );
+ }, // Hay que gestionar este posible error en el registro y mostrárselo al usuario
+ }).done(function () {
+
+ window.location.href = "mypictures.php";
+ });
+ }
+
+ }
+
+ else {
+
+ $("#errors-container").append(
+ getError("Se ha superado el número máximo de fotos, borra 1 para poder añadir nuevas imágenes.")
+ );
+ }
+
+
+ }
+ }
+ else if (tagsServidor.includes(w.val()) && !(tags.includes(w.val()))) {
+ tags.push(w.val());
+
+ }
+ }
+
+ /*let tagsString =""+tags[0];
+
+ for(numero = 1; numero${tag.tag}`;
+
+ $("#input-tags-0").append(html);
+
+ tags.push(tag.tag);
+
+ }
+
+
+
+
+}
+
+function createNewTagBox() {
+ cntNewTag++;
+ let html = `
+
+
+
+
+
+
+
+
+
+ `;
+
+ $("#new-tags-list").append(html);
+
+
+
+
+
+
+
+
+
+}
+function createTagBox() {
+ cntTag++;
+
+ let html = `
+
+
+
+
+
+
+
+
+
+
`;
+
+ $("#tags-list").append(html);
+
+ for (numero = 0; numero < tags.length; numero++) {
+
+ let input = "#input-tags-" + cntTag;
+ $(input).append(`
`);
+ }
+}
+
+processTags();
+
+function del(s) {
+
+ $(s).parent().parent().parent().remove();
+
+
+
+}
\ No newline at end of file
diff --git a/login.php b/login.php
new file mode 100644
index 0000000..9f7d1f7
--- /dev/null
+++ b/login.php
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
Log in!
+
+
Welcome to PixiArts!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mypictures.php b/mypictures.php
new file mode 100644
index 0000000..4073b69
--- /dev/null
+++ b/mypictures.php
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
Hi @loremIpsum
+
+
My pictures!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/myprofile.php b/myprofile.php
new file mode 100644
index 0000000..44f2daf
--- /dev/null
+++ b/myprofile.php
@@ -0,0 +1,367 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
Likes: 1000
+ Dislikes:1000
+ Pictures: 120
+
+
+
+
+
+
+
+
+
My profile!
+
+
+
+
+
+
+
+
Last updates
+
+
1.Title
+
+
+
+
+
+
+
+
+
Date: 02/03/2020
+
Description: Lorem Ipsum Dolor Sit Amet
+
+
+
Score: +30
+
+
+
+
Tags:
+
+
+
+
+
+
+
+
+
+
2.Title
+
+
+
+
+
+
+
+
+
Date: 02/03/2020
+
Description: Lorem Ipsum Dolor Sit Amet
+
+
+
Score: +30
+
+
+
+
Tags:
+
+
+
+
+
+
+
+
+
+
Top
+
+
1.Title
+
+
+
+
+
+
+
+
+
Date: 02/03/2020
+
Description: Lorem Ipsum Dolor Sit Amet
+
+
+
Score: +30
+
+
+
+
+
Tags:
+
+
+
+
+
+
+
+
+
+
+
+
+
Following
+
+
+
+
+

+
+
@user1
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+

+
+
@user1
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+

+
+
@user2
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+

+
+
@user3
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+

+
+
@user4
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+

+
+
@user5
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+

+
+
@user6
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+
+
+
+
+
+
+
+
Followers
+
+
+
+
+

+
+
@user1
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+

+
+
@user1
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+

+
+
@user2
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+

+
+
@user3
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+

+
+
@user4
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+

+
@user5
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+

+
+
@user6
+
+
Likes: 2000
+
Dislikes: 1234
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/photo_detail.php b/photo_detail.php
new file mode 100644
index 0000000..7ff03fa
--- /dev/null
+++ b/photo_detail.php
@@ -0,0 +1,89 @@
+
+
+
+
+
+ Detalles foto
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
@user
+
+
+
+
Date: 02/03/2020
+
Description: Lorem Ipsum Dolor Sit Amet
+
+
+
+
+
+
Tags:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/photo_edit.php b/photo_edit.php
new file mode 100644
index 0000000..bd279b2
--- /dev/null
+++ b/photo_edit.php
@@ -0,0 +1,119 @@
+
+
+
+
+
+
Subir foto
+
+
+
+
+
+