revert Minify.
This commit is contained in:
2025-05-09 14:57:22 +02:00
parent 4c34d7eda5
commit 1616e4edb9
86 changed files with 5826 additions and 1885 deletions
+87 -49
View File
@@ -1,53 +1,91 @@
_B='color'
_A=True
import pathlib
from snek.system import security
from snek.system.service import BaseService
class UserService(BaseService):
mapper_name='user'
async def get_by_username(A,username):return await A.get(username=username)
async def search(C,query,**D):
A=query;A=A.strip().lower()
if not A:return[]
B=[]
async for E in C.find(username={'ilike':'%'+A+'%'},**D):B.append(E)
return B
async def validate_login(C,username,password):
A=False;B=await C.get(username=username)
if not B:return A
if not await security.verify(password,B['password']):return A
return _A
async def save(B,user):
A=user
if not A[_B]:A[_B]=await B.services.util.random_light_hex_color()
return await super().save(A)
async def authenticate(B,username,password):
C=password;A=username;print(A,C,flush=_A);D=await B.validate_login(A,C);print(D,flush=_A)
if not D:return
E=await B.get(username=A,deleted_at=None);return E
def get_admin_uids(A):return A.mapper.get_admin_uids()
async def get_repository_path(A,user_uid):return pathlib.Path(f"./drive/repositories/{user_uid}")
async def get_static_path(B,user_uid):
A=pathlib.Path(f"./drive/{user_uid}/snek/static")
if not A.exists():return
return A
async def get_template_path(B,user_uid):
A=pathlib.Path(f"./drive/{user_uid}/snek/templates")
if not A.exists():return
return A
async def get_home_folder(B,user_uid):
A=pathlib.Path(f"./drive/{user_uid}")
if not A.exists():
try:A.mkdir(parents=_A,exist_ok=_A)
except:pass
return A
async def register(B,email,username,password):
C=username
if await B.exists(username=C):raise Exception('User already exists.')
A=await B.new();A['nick']=C;A[_B]=await B.services.util.random_light_hex_color();A.email.value=email;A.username.value=C;A.password.value=await security.hash(password)
if await B.save(A):
if A:
D=await B.services.channel.ensure_public_channel(A['uid'])
if not D:raise Exception('Failed to create public channel.')
return A
raise Exception(f"Failed to create user: {A.errors}.")
mapper_name = "user"
async def get_by_username(self, username):
return await self.get(username=username)
async def search(self, query, **kwargs):
query = query.strip().lower()
if not query:
return []
results = []
async for result in self.find(username={"ilike": "%" + query + "%"}, **kwargs):
results.append(result)
return results
async def validate_login(self, username, password):
model = await self.get(username=username)
if not model:
return False
if not await security.verify(password, model["password"]):
return False
return True
async def save(self, user):
if not user["color"]:
user["color"] = await self.services.util.random_light_hex_color()
return await super().save(user)
async def authenticate(self, username, password):
print(username, password, flush=True)
success = await self.validate_login(username, password)
print(success, flush=True)
if not success:
return None
model = await self.get(username=username, deleted_at=None)
return model
def get_admin_uids(self):
return self.mapper.get_admin_uids()
async def get_repository_path(self, user_uid):
return pathlib.Path(f"./drive/repositories/{user_uid}")
async def get_static_path(self, user_uid):
path = pathlib.Path(f"./drive/{user_uid}/snek/static")
if not path.exists():
return None
return path
async def get_template_path(self, user_uid):
path = pathlib.Path(f"./drive/{user_uid}/snek/templates")
if not path.exists():
return None
return path
async def get_home_folder(self, user_uid):
folder = pathlib.Path(f"./drive/{user_uid}")
if not folder.exists():
try:
folder.mkdir(parents=True, exist_ok=True)
except:
pass
return folder
async def register(self, email, username, password):
if await self.exists(username=username):
raise Exception("User already exists.")
model = await self.new()
model["nick"] = username
model["color"] = await self.services.util.random_light_hex_color()
model.email.value = email
model.username.value = username
model.password.value = await security.hash(password)
if await self.save(model):
if model:
channel = await self.services.channel.ensure_public_channel(
model["uid"]
)
if not channel:
raise Exception("Failed to create public channel.")
return model
raise Exception(f"Failed to create user: {model.errors}.")