" +
message +
diff --git a/js/generalprofile.js b/js/generalprofile.js
index 6b2bd91..ca5b597 100644
--- a/js/generalprofile.js
+++ b/js/generalprofile.js
@@ -10,10 +10,33 @@ let list_us = [];
let tags = [];
let tagsId = [];
+if(localStorage.token!=null){
+ requestUser();
+ requestTags();
+}//requestLikes();
+
+else{
+
+ $("#errors-container").append(
+ getError("¡Tienes que estar logeado para acceder a esta página!")
+ );
+
+}
+
+function getError(message) {
+ removeError( $("#errors-container"));
+ return (
+ "
"
+ );
+}
+
+
+function removeError(error) {
+ $(error).empty();
+}
-requestUser();
-requestTags();
-//requestLikes();
function requestTags(){
@@ -389,6 +412,10 @@ function like(photoId, zId, but) {
method: "DELETE",
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -418,6 +445,10 @@ function like(photoId, zId, but) {
method: "POST",
data: JSON.stringify(vote),
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -451,6 +482,10 @@ function like(photoId, zId, but) {
contentType: "application/json",
success: function () { },
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
error: function () {
$("#errors-container").append(
getError("Ha habido un error")
@@ -551,6 +586,10 @@ function dislike(photoId, zId, but) {
method: "DELETE",
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -575,6 +614,10 @@ function dislike(photoId, zId, but) {
method: "POST",
data: JSON.stringify(vote),
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -608,6 +651,10 @@ function dislike(photoId, zId, but) {
contentType: "application/json",
success: function () { },
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
error: function () {
$("#errors-container").append(
getError("Ha habido un error")
diff --git a/js/indexgallery.js b/js/indexgallery.js
index 53bcb1a..404a3a8 100644
--- a/js/indexgallery.js
+++ b/js/indexgallery.js
@@ -34,9 +34,9 @@ function processPhotos(data) {
${photo.title}
-
+
-
+
@@ -756,6 +756,10 @@ function like(photoId, zId, but) {
method: "DELETE",
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -784,6 +788,10 @@ function like(photoId, zId, but) {
url: "http://localhost:3000/likes",
method: "POST",
data: JSON.stringify(vote),
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
contentType: "application/json",
success: function () { },
error: function () {
@@ -815,6 +823,10 @@ function like(photoId, zId, but) {
url: "http://localhost:3000/likes/" + likeId,
method: "DELETE",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
contentType: "application/json",
success: function () { },
@@ -918,6 +930,10 @@ function dislike(photoId, zId, but) {
method: "DELETE",
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -942,6 +958,10 @@ function dislike(photoId, zId, but) {
method: "POST",
data: JSON.stringify(vote),
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -972,6 +992,10 @@ function dislike(photoId, zId, but) {
url: "http://localhost:3000/dislikes/" + likeId,
method: "DELETE",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
contentType: "application/json",
success: function () { },
diff --git a/js/login.js b/js/login.js
index 1afd01c..ab7a4d8 100644
--- a/js/login.js
+++ b/js/login.js
@@ -18,7 +18,7 @@ function validateForm() {
success: handleLogin,
error: function(){
$("#errors-container").append(
- getError("Ha habido un error")
+ getError("Wrong email or password")
);
}, // Hay que gestionar este posible error en el login y mostrárselo al usuario
});
@@ -27,6 +27,7 @@ function validateForm() {
}
function getError(message) {
+ $("#errors-container").empty();
return (
"
Error! " +
message +
diff --git a/js/mypictures.js b/js/mypictures.js
index 70d591a..61bbcda 100644
--- a/js/mypictures.js
+++ b/js/mypictures.js
@@ -5,12 +5,13 @@ let likes = [];
let dislikes = [];
let tags = [];
let tagsId = [];
-const maxImg = 5;
+const maxImg = 50;
+let numImg = 0;
function addNewPictures(){
- if(maxImg>photoUsId){
+ if(maxImg>numImg){
window.location.href = "create_picture.php";
@@ -28,6 +29,10 @@ function addNewPictures(){
}
+function removeError(error) {
+ $(error).empty();
+}
+
function getError(message) {
@@ -60,7 +65,7 @@ function deletePhoto(id) {
}
}).then(function (response) {
if (response.ok) {
- window.location.href = "index.php";
+ window.location.href = "mypictures.php";
} else {
console.log("Error al borrar la foto: " + response.statusText);
}
@@ -93,6 +98,7 @@ function processPhotos(data) {
//cambiamos photo Id por photo edit para el test
for (photo of data) {
+ numImg++;
console.log(likes);
let but_like = ``;
if (likes.includes(photo.id)) {
@@ -140,7 +146,7 @@ function processPhotos(data) {
`;
- photoUsId++;
+
list_img_id.push(photo.id);
let col = $.parseHTML(html);
@@ -182,12 +188,14 @@ function processPhotos(data) {
$("span.badge").after(" ");
counter++;
+ photoUsId++;
if (counter % PHOTOS_PER_ROW == 0) {
let new_row = $("
", { "class": "row" });
$("div.container-fluid").append(new_row);
row = new_row;
}
}
+ processScore();
}
@@ -203,7 +211,7 @@ function loadPhotos() {
error: function (error) {
console.log("Ha ocurrido un error: " + error.toString());
}
- }).done(processScore());
+ }).done();
@@ -266,7 +274,7 @@ function processScore() {
let v = "#image-score-" + numero;
cnt = $(v).text();
- let va = parseInt(cnt.trim(), 10);
+ let va = parseInt(cnt, 10);
$(v).empty();
$(v).append("Score : " + (cntD + va));
@@ -283,7 +291,7 @@ function processScore() {
});
-
+/*
var b = $.ajax({
url: "http://localhost:3000/dislikes",
success: true,
@@ -294,7 +302,7 @@ function processScore() {
- });
+ });*/
}
// Llamar a loadPhotos cuando la página esté lista
@@ -452,6 +460,10 @@ function like(photoId, zId, but) {
method: "DELETE",
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -481,6 +493,10 @@ function like(photoId, zId, but) {
method: "POST",
data: JSON.stringify(vote),
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -513,6 +529,10 @@ function like(photoId, zId, but) {
method: "DELETE",
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -602,6 +622,10 @@ function dislike(photoId, zId, but) {
method: "DELETE",
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -626,6 +650,10 @@ function dislike(photoId, zId, but) {
method: "POST",
data: JSON.stringify(vote),
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -658,6 +686,10 @@ function dislike(photoId, zId, but) {
method: "DELETE",
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
diff --git a/js/photoDetail.js b/js/photoDetail.js
index 2e89d82..a6abaff 100644
--- a/js/photoDetail.js
+++ b/js/photoDetail.js
@@ -40,7 +40,7 @@ function processPhotoLoad(data) {
$("#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);
@@ -91,6 +91,11 @@ function processPhotoLoad(data) {
let score = data.upvotes - data.downvotes;
let score_text = "Puntuación: " + score;
$("#image-score").text(score_text);
+
+
+ $("#image-user").text(list[(data.userId-1)]);
+ $("#image-user").click(function(){window.location = "generalprofile.php?userId="+data.userId});
+
if (tok == data.userId) {
@@ -106,7 +111,7 @@ function processUssers(data) {
}
-
+ loadPhoto();
}
@@ -139,7 +144,7 @@ function addComment(){
for(z of bw){
- if(comm.includes(z)){
+ if(comm.toLowerCase().includes(z)){
palabrota = true;
}
@@ -161,22 +166,24 @@ function addComment(){
photoId : photId
}
- $.ajax({
-
- url: "http://localhost:3000/comments",
- method: "POST",
- data: JSON.stringify(comment),
- contentType: "application/json",
- success: function(){
+ fetch('http://localhost:3000/comments', {
+ method: "POST",
+ body: JSON.stringify(comment),
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ }
+ }).then(function (response) {
+ if (response.ok) {
+ location.reload();
- 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
+ } else {
+ $("#errors-container").append(
+ getError("Vaya ha habido un fallo subiendo ese comentario.")
+ );
+ }
});
+
@@ -209,9 +216,9 @@ function loadComments(pid){
}
}).done(function(){
-
+
$.ajax({
- url: "http://localhost:3000/comments?photoId=" + pid,
+ url: "http://localhost:3000/comments?photoId=" + id,
success: function(data){
@@ -283,55 +290,66 @@ function storageLikesFromUser(data) {
}
}
-
-
-var a = $.ajax({
- url: "http://localhost:3000/tags",
- success: function (data) {
-
- for (var tag of data) {
-
- tags.push(tag.tag);
- tagsId.push(tag.id);
+if(localStorage.token!=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());
}
-
-
-
- },
- 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,
+ });
+ 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(loadComments(photId));});
+ function storageDislikesFromUser(data) {
+
+
+ for (var w of data) {
+
+
+ dislikes.push(w.photoId);
+
+ }
+ console.log(dislikes);
+ }
+}
+else{
+ $("#errors-container").append(
+ getError("¡Tienes que estar logeado para acceder a esta página!")
+ );
-}).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
@@ -497,6 +515,10 @@ function like(photoId, zId, but) {
contentType: "application/json",
success: function () { },
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
error: function () {
$("#errors-container").append(
getError("Ha habido un error")
@@ -525,6 +547,10 @@ function like(photoId, zId, but) {
method: "POST",
data: JSON.stringify(vote),
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -557,6 +583,10 @@ function like(photoId, zId, but) {
method: "DELETE",
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -647,6 +677,10 @@ function dislike(photoId, zId, but) {
contentType: "application/json",
success: function () { },
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
error: function () {
$("#errors-container").append(
getError("Ha habido un error")
@@ -670,6 +704,10 @@ function dislike(photoId, zId, but) {
method: "POST",
data: JSON.stringify(vote),
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -702,6 +740,10 @@ function dislike(photoId, zId, but) {
method: "DELETE",
contentType: "application/json",
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ },
success: function () { },
error: function () {
$("#errors-container").append(
@@ -732,4 +774,14 @@ function ProcessOneScore(spId, zId, val) {
-}
\ No newline at end of file
+}
+
+$(document).ready(function () {
+
+ if(localStorage.token==null){
+ $("#bod").empty();
+
+ }
+
+});
+
diff --git a/js/register.js b/js/register.js
index a6f3820..d5d4080 100644
--- a/js/register.js
+++ b/js/register.js
@@ -87,7 +87,7 @@ function validateForm() {
};
for(z of bw){
- if(nombre.includes(z)||apellidos.includes(z)||telefono.includes(z)||email.includes(z)||usuario.includes(z)){
+ if(nombre.toLowerCase().includes(z)||apellidos.toLowerCase().includes(z)||telefono.toLowerCase().includes(z)||email.toLowerCase().includes(z)||usuario.toLowerCase().includes(z)){
errorCounterBw++;
console.log("palabramala");}
}
diff --git a/js/uploadphoto.js b/js/uploadphoto.js
index 686448f..e51a7e6 100644
--- a/js/uploadphoto.js
+++ b/js/uploadphoto.js
@@ -1,6 +1,3 @@
-function getError(message) {
- return "
Error! " + message + "
";
-}
let cntTag = 0;
let cntNewTag = 0;
@@ -12,8 +9,9 @@ let tagsServidor = [];
let tags = [];
let newTags = [];
loadServerTags();
-const maxImg = 5;
+const maxImg = 50;
let bw = [];
+let numImg = 0;
loadPhotosNumber();
loadBadWords();
@@ -190,7 +188,27 @@ $("form").submit(function (event) {
}
if (maxImg > photoNumber) {
if (blbw) {
- $.ajax({
+
+ fetch('http://localhost:3000/tags/', {
+ method: "POST",
+ body: JSON.stringify(tag),
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': 'Bearer ' + getToken(),
+ }
+ }).then(function (response) {
+ if (response.ok) {
+ if (errorCounter == 0){}
+ //window.location.href = "mypictures.php";
+
+ } else {
+
+ $("#errors-container").append(getError(response.statusText));
+ }
+ })
+
+
+ /*$.ajax({
url: "http://localhost:3000/tags",
method: "POST",
@@ -205,7 +223,7 @@ $("form").submit(function (event) {
}).done(function () {
window.location.href = "mypictures.php";
- });
+ });*/
}
}
@@ -239,7 +257,7 @@ $("form").submit(function (event) {
let aux = tags;
for (z of bw) {
- if (title.includes(z) || description.includes(z)) {
+ if (title.toLowerCase().includes(z) || description.toLowerCase().includes(z)) {
errorCounter++;
console.log("palabramala");
}
@@ -256,7 +274,7 @@ $("form").submit(function (event) {
tags = [];
for (w of newTags) {
- if(!tags.includes(w))
+ if (!tags.includes(w))
tags.push(w);
}
@@ -450,4 +468,12 @@ function del(s) {
+}
+
+function getError(message) {
+ removeError($("#errors-container"));
+ return "
Error! " + message + "
";
+}
+function removeError(error) {
+ $(error).empty();
}
\ No newline at end of file
diff --git a/mypictures.php b/mypictures.php
index 4073b69..d8bd439 100644
--- a/mypictures.php
+++ b/mypictures.php
@@ -13,7 +13,7 @@