New settings for user model

Removed first_name and last_name in favor of full_name. Also tweaked
response handling from validation endpoint.
This commit is contained in:
2015-10-13 19:40:25 +02:00
parent f8e7e7ff12
commit 2ad8c5458a
2 changed files with 31 additions and 18 deletions

View File

@@ -58,13 +58,9 @@ def validate(token):
if r.status_code == 200: if r.status_code == 200:
response = r.json() response = r.json()
validation_result = dict(
message=response['message'],
valid=response['valid'],
user=response['user'])
else: else:
validation_result = dict(valid=False) response = None
return validation_result return response
def validate_token(): def validate_token():
@@ -89,16 +85,17 @@ def validate_token():
# to verify the validity of the token. We will get basic user info if # to verify the validity of the token. We will get basic user info if
# the user is authorized and we will make a new token. # the user is authorized and we will make a new token.
validation = validate(token) validation = validate(token)
if validation['valid']: if validation['status'] == 'success':
users = app.data.driver.db['users'] users = app.data.driver.db['users']
email = validation['user']['email'] email = validation['data']['user']['email']
db_user = users.find_one({'email': email}) db_user = users.find_one({'email': email})
tmpname = email.split('@')[0] tmpname = email.split('@')[0]
if not db_user: if not db_user:
user_data = { user_data = {
'first_name': tmpname, 'full_name': tmpname,
'last_name': tmpname,
'email': email, 'email': email,
'auth': list(dict(provider='blender-id',
user_id=validation['data']['user']['id']))
} }
r = post_internal('users', user_data) r = post_internal('users', user_data)
user_id = r[0]['_id'] user_id = r[0]['_id']

View File

@@ -13,15 +13,10 @@ PAGINATION_LIMIT = 25
users_schema = { users_schema = {
'first_name': { 'full_name': {
'type': 'string', 'type': 'string',
'minlength': 1, 'minlength': 1,
'maxlength': 60, 'maxlength': 128,
},
'last_name': {
'type': 'string',
'minlength': 1,
'maxlength': 60,
}, },
'username': { 'username': {
'type': 'string', 'type': 'string',
@@ -34,7 +29,7 @@ users_schema = {
'minlength': 1, 'minlength': 1,
'maxlength': 60, 'maxlength': 60,
}, },
'role': { 'roles': {
'type': 'list', 'type': 'list',
'allowed': ["admin"], 'allowed': ["admin"],
'required': True, 'required': True,
@@ -50,6 +45,27 @@ users_schema = {
'embeddable': True 'embeddable': True
} }
} }
},
'auth': {
# Storage of authentication credentials (one will be able to auth with
# multiple providers on the same account)
'type': 'list',
'required': True,
'schema': {
'type': 'dict',
'schema': {
'provider': {
'type': 'string',
'allowed': ["blender-id",],
},
'user_id' : {
'type': 'string'
},
'token': {
'type': 'string'
}
}
}
} }
} }