Fix PIN validation bug for new players
- Fixed logic where generated PINs for new players were incorrectly rejected - Now correctly handles: new players can use any PIN (auto-generated or custom), existing players must use their stored PIN - Removed unnecessary code update for existing players since PIN shouldn't change
This commit is contained in:
13
app.js
13
app.js
@@ -284,13 +284,15 @@ function initGame() {
|
|||||||
const name = nameInput.value.trim() || 'Anonymous';
|
const name = nameInput.value.trim() || 'Anonymous';
|
||||||
let secretCode = codeInput.value.trim().toUpperCase();
|
let secretCode = codeInput.value.trim().toUpperCase();
|
||||||
|
|
||||||
if (secretCode && playersData[name] && playersData[name].code === secretCode) {
|
if (!playersData[name]) {
|
||||||
secretCode = playersData[name].code;
|
if (!secretCode) {
|
||||||
} else if (!secretCode) {
|
secretCode = generateSecretCode();
|
||||||
secretCode = generateSecretCode();
|
}
|
||||||
} else {
|
} else if (secretCode && playersData[name].code !== secretCode) {
|
||||||
alert('PIN not found for this name. Leave blank for new PIN.');
|
alert('PIN not found for this name. Leave blank for new PIN.');
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
secretCode = playersData[name].code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!playersData[name]) {
|
if (!playersData[name]) {
|
||||||
@@ -301,7 +303,6 @@ function initGame() {
|
|||||||
lastPlayed: new Date().toISOString()
|
lastPlayed: new Date().toISOString()
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
playersData[name].code = secretCode;
|
|
||||||
playersData[name].lastPlayed = new Date().toISOString();
|
playersData[name].lastPlayed = new Date().toISOString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user