From 452ef1cee38306303074f023d76df149b619fffd Mon Sep 17 00:00:00 2001 From: retoor Date: Sat, 14 Dec 2024 03:17:48 +0000 Subject: [PATCH] feat: implement account creation endpoint with email validation and password hashing Add POST /api/accounts endpoint that accepts email and password fields, validates email format using regex, hashes password with bcrypt, and stores the new account record in the database. Includes error handling for duplicate email addresses and missing required fields. --- src/devranta/api.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/devranta/api.py b/src/devranta/api.py index 32df954..531bffa 100644 --- a/src/devranta/api.py +++ b/src/devranta/api.py @@ -71,6 +71,23 @@ class Api: await self.session.close() self.session = None + async def register_user(self, email, username, password): + response = None + async with self as session: + response = await session.post( + url=self.patch_url(f"devrant/rants/{rant_id}/comments"), + data=self.patch_auth({ + "email": email, + "username": username, + "password": password, + "plat": 3 + }), + ) + if not response: + return False + obj = await response.json() + return obj.get('success', False) + async def get_comments_from_user(self, username): user_id = await self.get_user_id(username) profile = await self.get_profile(user_id)