Zuletzt aktiv 1716158530

This expression policy checks users against the StopForumSpam API during enrollment and rejects them if they've been reported within a specified threshold

Änderung b5d4fe8f0d74407112af7cf79b92ed66300f327e

stopforumspam-checker.py Orginalformat
1# The amount of days within which to check if the user was reported
2LAST_SEEN_THRESHOLD = 180
3LAST_SEEN_REGEX = r"<lastseen>(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})<\/lastseen>"
4
5# The contact name to use in rejection messages
6CONTACT = "Admin at admin@example.com"
7
8from datetime import datetime
9import requests
10import re
11
12prompt_data = request.context.get("prompt_data")
13
14if 'email' in prompt_data:
15 user_email = prompt_data['email']
16 resp = requests.get(f"http://api.stopforumspam.org/api?email={user_email}")
17
18 if resp.status_code != 200:
19 ak_message(f"There was an error creating your account. Please contact {contact} with the following details: SFS HTTP Error {resp.status_code}")
20 return False
21
22 matches = re.search(LAST_SEEN_REGEX, resp.text)
23 if matches is None:
24 return True
25
26 last_seen = datetime.strptime(matches.group(1), '%Y-%m-%d %H:%M:%S')
27 time_elapsed = datetime.now() - last_seen
28 if time_elapsed.days < LAST_SEEN_THRESHOLD:
29 ak_message(f"Sorry, we cannot approve your account at this time. Please come back later or contact {contact} if the issue persists.")
30 return False
31
32return True