Fix GitHub claim method being broken by phpBB update

This commit is contained in:
rubenwardy 2020-07-10 18:41:08 +01:00
parent 000259fc88
commit 491f9ed679
2 changed files with 10 additions and 9 deletions

View File

@ -30,6 +30,7 @@ def claim():
username = "" username = ""
else: else:
method = request.args.get("method") method = request.args.get("method")
user = User.query.filter_by(forums_username=username).first() user = User.query.filter_by(forums_username=username).first()
if user and user.rank.atLeast(UserRank.NEW_MEMBER): if user and user.rank.atLeast(UserRank.NEW_MEMBER):
flash("User has already been claimed", "danger") flash("User has already been claimed", "danger")
@ -37,7 +38,7 @@ def claim():
elif method == "github": elif method == "github":
if user is None or user.github_username is None: if user is None or user.github_username is None:
flash("Unable to get Github username for user", "danger") flash("Unable to get Github username for user", "danger")
return redirect(url_for("users.claim")) return redirect(url_for("users.claim", username=username))
else: else:
return redirect(url_for("github.start")) return redirect(url_for("github.start"))
elif user is None and request.method == "POST": elif user is None and request.method == "POST":

View File

@ -21,10 +21,10 @@ class Profile:
self.properties = {} self.properties = {}
def set(self, key, value): def set(self, key, value):
self.properties[key] = value self.properties[key.lower()] = value
def get(self, key): def get(self, key):
return self.properties[key] if key in self.properties else None return self.properties.get(key.lower())
def __str__(self): def __str__(self):
return self.username + "\n" + str(self.signature) + "\n" + str(self.properties) return self.username + "\n" + str(self.signature) + "\n" + str(self.properties)
@ -39,7 +39,7 @@ def __extract_properties(profile, soup):
if len(imgs) == 1: if len(imgs) == 1:
profile.avatar = imgs[0]["src"] profile.avatar = imgs[0]["src"]
res = el.find_all("dl", class_ = "left-box details") res = el.select("dl.left-box.details")
if len(res) != 1: if len(res) != 1:
return None return None
@ -85,12 +85,12 @@ def getProfile(url, username):
soup = BeautifulSoup(contents, "lxml") soup = BeautifulSoup(contents, "lxml")
if soup is None: if soup is None:
return None return None
else:
profile = Profile(username)
profile.signature = __extract_signature(soup)
__extract_properties(profile, soup)
return profile profile = Profile(username)
profile.signature = __extract_signature(soup)
__extract_properties(profile, soup)
return profile
regex_id = re.compile(r"^.*t=([0-9]+).*$") regex_id = re.compile(r"^.*t=([0-9]+).*$")