Skip to content

Commit 234bed2

Browse files
committed
2.1.10a2
1 parent 2942a1d commit 234bed2

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

scratchattach/site/_base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import requests
66
from ..utils import exceptions, commons
7+
from typing import TypeVar
78
from types import FunctionType
89

9-
10+
C = TypeVar("C", bound="BaseSiteComponent")
1011
class BaseSiteComponent(ABC):
1112
@abstractmethod
1213
def __init__(self):
@@ -51,7 +52,7 @@ def _assert_auth(self):
5152
raise exceptions.Unauthenticated(
5253
"You need to use session.connect_xyz (NOT get_xyz) in order to perform this operation.")
5354

54-
def _make_linked_object(self, identificator_id, identificator, Class, NotFoundException) -> BaseSiteComponent:
55+
def _make_linked_object(self, identificator_id, identificator, Class: type[C], NotFoundException) -> C:
5556
"""
5657
Internal function for making a linked object (authentication kept) based on an identificator (like a project id or username)
5758
Class must inherit from BaseSiteComponent

scratchattach/site/user.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919

2020
from ..utils.requests import Requests as requests
2121

22+
class Verificator:
23+
24+
def __init__(self, user: User, project_id: int):
25+
self.project = user._make_linked_object("id", project_id, project.Project, exceptions.ProjectNotFound)
26+
self.projecturl = self.project.url
27+
self.code = ''.join(random.choices(string.ascii_letters + string.digits, k=8))
28+
self.username = user.username
29+
30+
def check(self) -> bool:
31+
return bool(list(filter(lambda x : x.author_name == self.username and (x.content == self.code or x.content.startswith(self.code) or x.content.endswith(self.code)), self.project.comments())))
32+
2233
class User(BaseSiteComponent):
2334

2435
'''
@@ -799,20 +810,8 @@ def verify_identity(self, *, verification_project_id=395330233):
799810
It will return True if the user commented the code.
800811
"""
801812

802-
class Verificator:
803-
804-
def __init__(self, user):
805-
self.project = user._make_linked_object("id", verification_project_id, project.Project, exceptions.ProjectNotFound)
806-
self.projecturl = self.project.url
807-
self.code = ''.join(random.choices(string.ascii_letters + string.digits, k=130))
808-
self.username = user.username
809-
810-
def check(self):
811-
return list(filter(lambda x : x.author_name == self.username, self.project.comments())) != []
812-
813-
v = Verificator(self)
814-
print(f"{self.username} has to go to {v.projecturl} and comment {v.code} to verify their identity")
815-
return Verificator(self)
813+
v = Verificator(self, verification_project_id)
814+
return v
816815

817816
# ------ #
818817

0 commit comments

Comments
 (0)