From: Marnanel Thurman Date: Mon, 29 Nov 2021 21:29:51 +0000 (+0000) Subject: ersatz fake-dw gives correct messages on username and password failure X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~tthurman/git?a=commitdiff_plain;h=0eeed64a3162b5e01e159544e2597ae711c9e278;p=dwim.git ersatz fake-dw gives correct messages on username and password failure --- diff --git a/fake-dw/fake-dw.py b/fake-dw/fake-dw.py index 21d69a0..9b80c8e 100644 --- a/fake-dw/fake-dw.py +++ b/fake-dw/fake-dw.py @@ -159,17 +159,17 @@ class ErsatzHandler(http.server.BaseHTTPRequestHandler): elif method=='POST': - if not self.check_headers(query, + fields['template-name'] = self.check_headers(query, [ - ('user', 'wombat', 'Unknown user'), - ('password', 'hunter2', 'Wrong password'), + ('user', 'wombat', 'Unknown user', + 'login-fail-username'), + ('password', 'hunter2', 'Wrong password', + 'login-fail-password'), ('lj_form_auth', self.server.lj_form_auth, - 'Wrong auth string'), + 'Wrong auth string', + 'login-fail-username'), # apparently ], - ): - return - - fields['template-name'] = 'logged-in' + ) else: self.send_error(405, 'Unknown method') @@ -217,22 +217,20 @@ class ErsatzHandler(http.server.BaseHTTPRequestHandler): def check_headers(self, query, checks): - for (field, value, message) in checks: + for (field, value, message, failure_template) in checks: field = bytes(field, encoding='ascii') value = [bytes(value, encoding='ascii')] if field not in query: - self.send_error(410, - f'{message}: {field} missing') - return False + print(f'{message}: {field} missing') + return failure_template elif query[field]!=value: - self.send_error(410, - f'{message}: got {query[field]}, wanted {value}') - return False + print(f'{message}: got {query[field]}, wanted {value}') + return failure_template - return True + return 'login-success' class TCPServerWithSettings(socketserver.TCPServer): diff --git a/fake-dw/templates/login-fail-password b/fake-dw/templates/login-fail-password new file mode 100644 index 0000000..a716e0b --- /dev/null +++ b/fake-dw/templates/login-fail-password @@ -0,0 +1,167 @@ + + + Log in + + + + + + + + + + + + + + + +
+
+ + + + +

Log in

+
+
+
+There was an error processing your request:
  • You typed the wrong password. If you make too many wrong login attempts in a row, your account access will be temporarily blocked, so you may want to reset your password if you aren't sure what it is. If you're sure you typed the right password, but are still having trouble logging in, you may need to update or disable your browser extensions.
  • +
+
+
+
+
+
+ + +
+
+
+ + + + + + +
+
+
+
+
+ + + + diff --git a/fake-dw/templates/login-fail-username b/fake-dw/templates/login-fail-username new file mode 100644 index 0000000..6038654 --- /dev/null +++ b/fake-dw/templates/login-fail-username @@ -0,0 +1,167 @@ + + + Log in + + + + + + + + + + + + + + + +
+
+ + + + +

Log in

+
+
+
+There was an error processing your request:
  • This account name was not found. Would you like to create an account using this account name?
  • +
+
+
+
+
+
+ + +
+
+
+ + + + + + +
+
+
+
+
+ + + + diff --git a/fake-dw/templates/logged-in b/fake-dw/templates/login-success similarity index 100% rename from fake-dw/templates/logged-in rename to fake-dw/templates/login-success