mirror of https://gitlab.com/litecord/litecord.git
register: properly handle missing j.invite
- schemas: fix 80col line breaks
This commit is contained in:
parent
1ad328904d
commit
47db480209
|
|
@ -23,6 +23,7 @@ import secrets
|
||||||
import itsdangerous
|
import itsdangerous
|
||||||
import bcrypt
|
import bcrypt
|
||||||
from quart import Blueprint, jsonify, request, current_app as app
|
from quart import Blueprint, jsonify, request, current_app as app
|
||||||
|
from logbook import Logger
|
||||||
|
|
||||||
from litecord.auth import token_check, create_user
|
from litecord.auth import token_check, create_user
|
||||||
from litecord.schemas import validate, REGISTER, REGISTER_WITH_INVITE
|
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 litecord.snowflake import get_snowflake
|
||||||
from .invites import use_invite
|
from .invites import use_invite
|
||||||
|
|
||||||
|
log = Logger(__name__)
|
||||||
bp = Blueprint('auth', __name__)
|
bp = Blueprint('auth', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -64,10 +65,17 @@ async def register():
|
||||||
j = await request.get_json()
|
j = await request.get_json()
|
||||||
|
|
||||||
if not 'password' in j:
|
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)
|
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(
|
new_id, pwd_hash = await create_user(
|
||||||
username, email, password, app.db
|
username, email, password, app.db
|
||||||
|
|
@ -76,9 +84,9 @@ async def register():
|
||||||
if invite:
|
if invite:
|
||||||
try:
|
try:
|
||||||
await use_invite(new_id, invite)
|
await use_invite(new_id, invite)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print(e)
|
log.exception('failed to use invite for register {} {!r}',
|
||||||
pass # do nothing
|
new_id, invite)
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'token': make_token(new_id, pwd_hash)
|
'token': make_token(new_id, pwd_hash)
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,12 @@ REGISTER = {
|
||||||
'username': {'type': 'username', 'required': True},
|
'username': {'type': 'username', 'required': True},
|
||||||
'email': {'type': 'email', 'required': False},
|
'email': {'type': 'email', 'required': False},
|
||||||
'password': {'type': 'string', 'minlength': 5, '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
|
'fingerprint': {'type': 'string', 'required': False, 'nullable': True}, # these are sent by official client
|
||||||
'captcha_key': {'type': 'string', 'required': False, 'nullable': True},
|
'captcha_key': {'type': 'string', 'required': False, 'nullable': True},
|
||||||
'consent': {'type': 'boolean'},
|
'consent': {'type': 'boolean'},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue