diff --git a/server/githubsrm/administrator/errors.py b/server/githubsrm/administrator/errors.py index e1ee6672..deaba8bd 100644 --- a/server/githubsrm/administrator/errors.py +++ b/server/githubsrm/administrator/errors.py @@ -53,3 +53,9 @@ class InvalidUserError(AuthenticationErrors): def __init__(self, *args, **kwargs): detail = kwargs.get("detail", {"error": "Invalid User!"}) super().__init__(detail=detail) + + +class InvalidMember(AdminErrors): + def __init__(self, *args, **kwargs): + detail = kwargs.get("detail", {"error": "Invalid Member!"}) + super().__init__(detail=detail) diff --git a/server/githubsrm/administrator/models.py b/server/githubsrm/administrator/models.py index 0c2270b2..8fbbf4ea 100644 --- a/server/githubsrm/administrator/models.py +++ b/server/githubsrm/administrator/models.py @@ -20,6 +20,7 @@ MaintainerApprovedError, MaintainerNotFoundError, ProjectNotFoundError, + InvalidMember, ) @@ -368,6 +369,7 @@ def admin_remove_maintainer(self, identifier: str) -> bool: project_name = self.db.project.find_one({"_id": project_id})["project_name"] + #! Why does this exist? project = self.db.project.find_one_and_delete( {"_id": project_id, "maintainer_id": {"$exists": False}} ) @@ -439,3 +441,20 @@ def get_maintainer_email(self, identifier: str) -> str: return maintainer["email"] return False + + def register_member(self, doc: Dict[str, Any]): + # Using admin db to register members since members are pseudo admins :) + doc["member"] = True + self.insert_admin(doc) + + def verify_member(self, doc: Dict[str, Any]): + member = self.db.admin.find_one( + { + "email": doc["email"], + "password": hashlib.sha256(doc["password"]), + "member": True, + } + ) + if member: + return member + raise InvalidMember() diff --git a/server/githubsrm/administrator/views.py b/server/githubsrm/administrator/views.py index 17264afa..693e0442 100644 --- a/server/githubsrm/administrator/views.py +++ b/server/githubsrm/administrator/views.py @@ -315,3 +315,13 @@ def refresh(request) -> JsonResponse: @api_view(["GET"]) def verify(request) -> JsonResponse: return JsonResponse(data={"success": True}, status=200) + + +@api_view(["POST"]) +def register_member(request): + ... + + +@api_view(["POST"]) +def login_member(request): + ...