From 47db4802099ce3a727d5eb5dea3f80f31c046aa8 Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 13 Mar 2019 22:59:27 -0300 Subject: [PATCH] register: properly handle missing j.invite - schemas: fix 80col line breaks --- litecord/blueprints/auth.py | 20 ++++++++++++++------ litecord/schemas.py | 7 ++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/litecord/blueprints/auth.py b/litecord/blueprints/auth.py index e779e27..e6d4124 100644 --- a/litecord/blueprints/auth.py +++ b/litecord/blueprints/auth.py @@ -23,6 +23,7 @@ import secrets import itsdangerous import bcrypt from quart import Blueprint, jsonify, request, current_app as app +from logbook import Logger from litecord.auth import token_check, create_user from litecord.schemas import validate, REGISTER, REGISTER_WITH_INVITE @@ -30,7 +31,7 @@ from litecord.errors import BadRequest from litecord.snowflake import get_snowflake from .invites import use_invite - +log = Logger(__name__) bp = Blueprint('auth', __name__) @@ -64,10 +65,17 @@ async def register(): j = await request.get_json() if not 'password' in j: - j['password'] = 'default_password' # we need some password to make a token + # we need a password to generate a token. + # passwords are optional, so + j['password'] = 'default_password' j = validate(j, REGISTER) - email, password, username, invite = j['email'] if 'email' in j else None, j['password'], j['username'], j['invite'] + + # they're optional + email = j.get('email') + invite = j.get('invite') + + username, password = j['username'], j['password'] new_id, pwd_hash = await create_user( username, email, password, app.db @@ -76,9 +84,9 @@ async def register(): if invite: try: await use_invite(new_id, invite) - except Exception as e: - print(e) - pass # do nothing + except Exception: + log.exception('failed to use invite for register {} {!r}', + new_id, invite) return jsonify({ 'token': make_token(new_id, pwd_hash) diff --git a/litecord/schemas.py b/litecord/schemas.py index 80deca9..97c0a8f 100644 --- a/litecord/schemas.py +++ b/litecord/schemas.py @@ -175,7 +175,12 @@ REGISTER = { 'username': {'type': 'username', 'required': True}, 'email': {'type': 'email', 'required': False}, 'password': {'type': 'string', 'minlength': 5, 'required': False}, - 'invite': {'type': 'string', 'required': False, 'nullable': True}, # optional + + # invite stands for a guild invite, not an instance invite (that's on + # the register_with_invite handler). + 'invite': {'type': 'string', 'required': False, 'nullable': True}, + + # following fields only sent by official client 'fingerprint': {'type': 'string', 'required': False, 'nullable': True}, # these are sent by official client 'captcha_key': {'type': 'string', 'required': False, 'nullable': True}, 'consent': {'type': 'boolean'},