Progress.

This commit is contained in:
2025-01-25 05:50:23 +01:00
parent 12ca8e4296
commit bb6bcf41d1
9 changed files with 185 additions and 19 deletions
+13 -3
View File
@@ -5,13 +5,23 @@ from snek.system.service import BaseService
class UserService(BaseService):
mapper_name = "user"
async def validate_login(self, username, password):
model = await self.get(username=username)
print("FOUND USER!", model, flush=True)
if not model:
return False
print("AU", password, model.password.value, flush=True)
if not await security.verify(password, model["password"]):
return False
return True
async def register(self, email, username, password):
if await self.exists(username=username):
raise Exception("User already exists.")
model = await self.new()
model.email = email
model.username = username
model.password = await security.hash(password)
model.email.value = email
model.username.value = username
model.password.value = await security.hash(password)
if await self.save(model):
return model
raise Exception(f"Failed to create user: {model.errors}.")