mirror of
https://github.com/csd4ni3l/grass_touching_captcha.git
synced 2026-01-01 04:23: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":
|
||||
username, password = request.form.get("username"), request.form.get("password")
|
||||
|
||||
return "a"
|
||||
return f"Username: {username}\nPassword: {password}"
|
||||
|
||||
@app.route("/upload", methods=["POST"])
|
||||
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>`;
|
||||
}
|
||||
|
||||
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) {
|
||||
fetch('{{ url_for("upload") }}', {
|
||||
method: "POST",
|
||||
@@ -54,9 +61,7 @@ file_input.addEventListener("change", function () {
|
||||
if (response.status == 401) {
|
||||
response.text().then(text => {
|
||||
if (text) {
|
||||
console.error(text);
|
||||
document.getElementById("grass-touching-form").innerHTML += `<div class="text-danger">${text}</div>`;
|
||||
document.getElementById("submit").innerHTML = "Submit"
|
||||
upload_error(text);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -64,9 +69,7 @@ file_input.addEventListener("change", function () {
|
||||
return;
|
||||
}
|
||||
else if (response.status == 400) {
|
||||
document.getElementById("grass-touching-form").innerHTML += `<div class="text-danger">Unknown error happened. Please try again.</div>`;
|
||||
document.getElementById("submit").innerHTML = "Submit"
|
||||
console.error("Unknown error")
|
||||
upload_error("Unknown error");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user