Account creation checks public key

This commit is contained in:
Chris Proctor 2024-05-20 09:03:38 -04:00
parent 780c1e581a
commit 0ff6bb784a
1 changed files with 5 additions and 1 deletions

View File

@ -10,12 +10,16 @@ from encryption import PrivateKey, PublicKey
@route_post("users/new", args={'name': str, 'public_key': str})
def create_user(params):
"Creates a new user"
try:
PublicKey.load(params['public_key'])
except (ValueError, FileNotFoundError):
raise NotAllowed("Invalid public key")
try:
new_user = User.from_dict(params)
new_user.save()
return new_user.to_dict()
except:
raise NotAllowed("Username and public key must be unique.")
raise NotAllowed(f"Username {params['name']} is already in use.")
@route_get("users", args={'name': str})
def get_user(params):