From 2ad8c5458accb668e06cd126737d852aa60eae26 Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Tue, 13 Oct 2015 19:40:25 +0200 Subject: [PATCH] New settings for user model Removed first_name and last_name in favor of full_name. Also tweaked response handling from validation endpoint. --- pillar/application/__init__.py | 17 +++++++---------- pillar/settings.py | 32 ++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/pillar/application/__init__.py b/pillar/application/__init__.py index 722a7017..eec27b27 100644 --- a/pillar/application/__init__.py +++ b/pillar/application/__init__.py @@ -58,13 +58,9 @@ def validate(token): if r.status_code == 200: response = r.json() - validation_result = dict( - message=response['message'], - valid=response['valid'], - user=response['user']) else: - validation_result = dict(valid=False) - return validation_result + response = None + return response def validate_token(): @@ -89,16 +85,17 @@ def validate_token(): # 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. validation = validate(token) - if validation['valid']: + if validation['status'] == 'success': users = app.data.driver.db['users'] - email = validation['user']['email'] + email = validation['data']['user']['email'] db_user = users.find_one({'email': email}) tmpname = email.split('@')[0] if not db_user: user_data = { - 'first_name': tmpname, - 'last_name': tmpname, + 'full_name': tmpname, 'email': email, + 'auth': list(dict(provider='blender-id', + user_id=validation['data']['user']['id'])) } r = post_internal('users', user_data) user_id = r[0]['_id'] diff --git a/pillar/settings.py b/pillar/settings.py index 2e2c56e2..04fbfb8a 100644 --- a/pillar/settings.py +++ b/pillar/settings.py @@ -13,15 +13,10 @@ PAGINATION_LIMIT = 25 users_schema = { - 'first_name': { + 'full_name': { 'type': 'string', 'minlength': 1, - 'maxlength': 60, - }, - 'last_name': { - 'type': 'string', - 'minlength': 1, - 'maxlength': 60, + 'maxlength': 128, }, 'username': { 'type': 'string', @@ -34,7 +29,7 @@ users_schema = { 'minlength': 1, 'maxlength': 60, }, - 'role': { + 'roles': { 'type': 'list', 'allowed': ["admin"], 'required': True, @@ -50,6 +45,27 @@ users_schema = { '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' + } + } + } } }