def user_add(context, request): ''' if we have a password in our request, create and auth entry for the user as well ''' #do we have valid data pwd = request.json.get('password', None) pwd_less_data = request.json.copy() if pwd is not None: del pwd_less_data['password'] validate_request(context.type_info.schema, request, pwd_less_data) if request.errors: return HTTPUnprocessableEntity(json={'errors': request.errors}, content_type='application/json') # this will create an AuthUser with random password result = collection_add(context, request) if result: email = request.json.get('email') pwd = request.json.get('password', None) if pwd is not None: # now update the password db = request.registry['dbsession'] auth_user = db.query(AuthUser).filter_by(email=email).first() auth_user.password = pwd import transaction transaction.commit() return result
def signup(context, request): """ Create new user. :param request: Pyramid request object """ domain = 'encode.auth0.com' access_token = request.json.get('accessToken') if not access_token: raise HTTPBadRequest(explanation='Access token required') url = 'https://{domain}/userinfo?access_token={access_token}'.format(domain=domain, access_token=access_token) user_data_request = requests.get(url) if user_data_request.status_code != 200: raise HTTPBadRequest(explanation='Could not get user data') user_data = user_data_request.json() if user_data['email_verified'] is not True: raise HTTPBadRequest(explanation='Unverified email') user_info = _get_user_info(user_data) validate_request(context.type_info.schema, request, user_info) if request.errors: raise ValidationError(', '.join(request.errors)) result = collection_add(context, request, user_info) if not result or result['status'] != 'success': raise HTTPInternalServerError(explanation='attempt to create account was not successful') return HTTPCreated(explanation='User created')
def access_key_add(context, request): crypt_context = request.registry[CRYPT_CONTEXT] if 'access_key_id' not in request.validated: request.validated['access_key_id'] = generate_user() if 'user' not in request.validated: request.validated['user'], = [ principal.split('.', 1)[1] for principal in effective_principals(request) if principal.startswith('userid.') ] password = None if 'secret_access_key_hash' not in request.validated: password = generate_password() request.validated['secret_access_key_hash'] = crypt_context.encrypt(password) result = collection_add(context, request) if password is None: result['secret_access_key'] = None else: result['secret_access_key'] = password result['access_key_id'] = request.validated['access_key_id'] result['description'] = request.validated['description'] return result
def access_key_add(context, request): crypt_context = request.registry[CRYPT_CONTEXT] if 'access_key_id' not in request.validated: request.validated['access_key_id'] = generate_user() if 'user' not in request.validated: request.validated['user'], = [ principal.split('.', 1)[1] for principal in effective_principals(request) if principal.startswith('userid.') ] password = None if 'secret_access_key_hash' not in request.validated: password = generate_password() request.validated['secret_access_key_hash'] = crypt_context.encrypt( password) result = collection_add(context, request) if password is None: result['secret_access_key'] = None else: result['secret_access_key'] = password result['access_key_id'] = request.validated['access_key_id'] result['description'] = request.validated['description'] return result
def user_add(context, request): ''' if we have a password in our request, create and auth entry for the user as well ''' # do we have valid data pwd = request.json.get('password', None) pwd_less_data = request.json.copy() if pwd is not None: del pwd_less_data['password'] validate_request(context.type_info.schema, request, pwd_less_data) if request.errors: return HTTPUnprocessableEntity(json={'errors': request.errors}, content_type='application/json') result = collection_add(context, request) if result: email = request.json.get('email') pwd = request.json.get('password', None) name = request.json.get('first_name') if pwd is not None: auth_user = AuthUser(email, pwd, name) db = request.registry['dbsession'] db.add(auth_user) transaction.commit() return result
def user_add(context,request): ''' if we have a password in our request, create and auth entry for the user as well ''' #do we have valid data pwd = request.json.get('password', None) pwd_less_data = request.json.copy() if pwd is not None: del pwd_less_data['password'] validate_request(context.type_info.schema, request, pwd_less_data) if request.errors: return HTTPUnprocessableEntity(json={'errors':request.errors}, content_type='application/json') # this will create an AuthUser with random password result = collection_add(context, request) if result: email = request.json.get('email') pwd = request.json.get('password', None) if pwd is not None: # now update the password db = request.registry['dbsession'] auth_user = db.query(AuthUser).filter_by(email=email).first() auth_user.password = pwd import transaction transaction.commit() return result