mirror of
https://github.com/csd4ni3l/grass_touching_captcha.git
synced 2026-01-01 12:33:45 +01:00
reset file input after incorrect image submission
This commit is contained in:
2
main.py
2
main.py
@@ -44,7 +44,7 @@ def register():
|
|||||||
elif request.method == "POST":
|
elif request.method == "POST":
|
||||||
username, password = request.form.get("username"), request.form.get("password")
|
username, password = request.form.get("username"), request.form.get("password")
|
||||||
|
|
||||||
return "a"
|
return f"Username: {username}\nPassword: {password}"
|
||||||
|
|
||||||
@app.route("/upload", methods=["POST"])
|
@app.route("/upload", methods=["POST"])
|
||||||
def upload():
|
def upload():
|
||||||
|
|||||||
@@ -42,6 +42,13 @@ file_input.addEventListener("change", function () {
|
|||||||
document.getElementById("grass-touching-form").innerHTML += `<img class="preview-img" src="${image_url}"></img>`;
|
document.getElementById("grass-touching-form").innerHTML += `<img class="preview-img" src="${image_url}"></img>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function upload_error(error_message) {
|
||||||
|
console.error(error_message)
|
||||||
|
file_input.value = ''
|
||||||
|
document.getElementById("submit").innerHTML = "Submit"
|
||||||
|
document.getElementById("grass-touching-form").innerHTML += `<div class="text-danger">${error_message}</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
function upload_file(file_type, file_content) {
|
function upload_file(file_type, file_content) {
|
||||||
fetch('{{ url_for("upload") }}', {
|
fetch('{{ url_for("upload") }}', {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -54,9 +61,7 @@ file_input.addEventListener("change", function () {
|
|||||||
if (response.status == 401) {
|
if (response.status == 401) {
|
||||||
response.text().then(text => {
|
response.text().then(text => {
|
||||||
if (text) {
|
if (text) {
|
||||||
console.error(text);
|
upload_error(text);
|
||||||
document.getElementById("grass-touching-form").innerHTML += `<div class="text-danger">${text}</div>`;
|
|
||||||
document.getElementById("submit").innerHTML = "Submit"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,9 +69,7 @@ file_input.addEventListener("change", function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (response.status == 400) {
|
else if (response.status == 400) {
|
||||||
document.getElementById("grass-touching-form").innerHTML += `<div class="text-danger">Unknown error happened. Please try again.</div>`;
|
upload_error("Unknown error");
|
||||||
document.getElementById("submit").innerHTML = "Submit"
|
|
||||||
console.error("Unknown error")
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user