def get_session(space_id, auth_key): start_time = int(round(time.time() * 1000)) response = requests.get(ONEAUTH_API + space_id + '/session/' + auth_key) if response.status_code != 200: return (response.status_code, response.json()) oa_response = jwt_utils.decode(response.json()['token']) existing_user_data = user_service.find_by_user_id(space_id, oa_response['userId']) if len(existing_user_data) == 1: updated_record = user_service.update_user(space_id, { '_id': existing_user_data[0]['_id'], 'firstName': oa_response['firstName'], 'lastName': oa_response['lastName'], 'email': oa_response['email'] }) updated_record['token'] = response.json()['token'] return (200, updated_record) else: new_data = user_service.insert_user(space_id, { '_id': oa_response['userId'], 'firstName': oa_response['firstName'], 'lastName': oa_response['lastName'], 'email': oa_response['email'] }) new_data['token'] = response.json()['token'] return (200, new_data)
def get_session(space_id, auth_key): session_list = db_utils.find(space_id, domain_session, {'key': auth_key}) if len(session_list) == 0: return (404, {'data': 'not found'}) else: session = session_list[0] content = jwt_utils.decode(session['token']) if content == None: return (401, {'data': 'session expired'}) else: content['token'] = session['token'] print(content) return (200, content)
def get_session(space_id, auth_key): start_time = int(round(time.time() * 1000)) response = requests.get(ONEAUTH_API + 'space/' + space_id + '/session/' + auth_key) if response.status_code != 200: print(response) return (response.status_code, response.json()) oa_response = jwt_utils.decode(response.json()['token']) existing_user_data = user_service.find_by_user_id(space_id, oa_response['userId']) if len(existing_user_data) == 1: updated_record = user_service.update_user( space_id, { '_id': existing_user_data[0]['_id'], 'firstName': oa_response['firstName'], 'lastName': oa_response['lastName'], 'email': oa_response['email'] }) updated_record['token'] = response.json()['token'] return (200, {'data': updated_record}) else: if user_service.is_first_user(space_id): sequence_service.create_sequence(space_id, 'userColor', '', 1) new_data = user_service.insert_user( space_id, { '_id': oa_response['userId'], 'firstName': oa_response['firstName'], 'lastName': oa_response['lastName'], 'email': oa_response['email'], 'color': 'color_' + str((sequence_service.nextval(space_id, 'userColor', '') % 10) + 1) }) new_data['token'] = response.json()['token'] return (200, {'data': new_data})