Hello All.
I need to create a page that only asks for a code to enter and once the person enters, the code is no longer reusable.
The problem with my code, is in my database, when overwriting the information to remove the password used, the new information is written at the beginning of the database and not in the field that matches the password.
I want to overwrite the password with the word "DONE", making it not match in a next use.
This is my code, if i put the correct password i can enter to the URL (inside the code) and in my database is saving the word "DONE" but at the beginning. The problem, i can enter with the same password.
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
});
export function button29_click(event) {
let contrasena = $w('#input1').value;
wixData.query('EvaluaciondeClimaLaboral')
.eq('title', contrasena)
.find()
.then(results => {
if (results.items[0].title === $w('#input1').value) {
$w('#EvaluacionD').setFieldValue("title", 'DONE');
$w('#EvaluacionD').save();
wixLocation.to("http://xxxxxxxxxxxxxxxxxxxxxxxx");
}
else if (results.length === 0) {
$w('#text134').show();
}
else {
}
})
}
If you could help me I would appreciate it.
import wixData from 'wix-data'; import wixLocation from 'wix-location'; $w.onReady(function () { }); export function button29_click(event) { let contrasena = $w('#input1').value; wixData.query('EvaluaciondeClimaLaboral') .eq('title', contrasena) .eq('status', true) .find() .then(results => { results.items.forEach((e) =>{ if (e.title === $w('#input1').value) { $w('#EvaluacionD').setFieldValue("status", false); $w('#EvaluacionD').save(); wixLocation.to("http://xxxxxxxxxxxxxxxxxxxxxxxx"); } }) setTimeout( $w('#text134').show() ,1000) }) }
I assume that you add the "key" in the dataset with the status boolean checked(true)
the key becomes not checked (false) after used.
I don't code this on Wix, so there is some minor mistake, google it will helps.
Important: Since you are retrieving the data with all passwords that haven't used on the front-end/Client-side, your data is exposed to users on the browser dev console (they can find it). And, the wix location.to means that they can save the link and skip "key" to get access to that page.
Please try moving the important code to the backend. AND try to put all the content on the same page, so they cannot save the link for future use.
Hello Yisrael (Wix)Dash, please can you help me where i can start?
Thans for you reply.
But i can't do it, dont know how that can help me, i try this for 3 days, and i think is not the problem. Can you told me how coding that? im a newby in this. Thanks you a lot again.
For your purposes, you should better use this one......
https://www.wix.com/corvid/reference/wix-data/save
import wixData from 'wix-data'; 2 3// ... 4 5let toSave = { 6 "_id": "00001", 7 "title": "Mr.", 8 "first_name": "John", 9 "last_name": "Doe" 10}; 11 12wixData.save("myCollection", toSave) 13 .then( (results) => { 14 let item = results; //see item below 15 } ) 16 .catch( (err) => { 17 let errorMsg = err; 18 } );