def create_user(): missing = User.check_required(request.json) if missing: return error_response(apierrors.API_FIELDS_MISSING.format(missing), 400) else: user = get_datastore().create_user(email=request.json.get('email'), password=encrypt_password( request.json.get('password'))) userrole = user_datastore.find_role('admin') user_datastore.add_role_to_user(user, userrole) try: db.session.add(user) db.session.flush() apikey = ApiKey(user_id=user.id, api_key=str(uuid.uuid4()).replace("-", "")) db.session.add(apikey) db.session.commit() except IntegrityError: return error_response(errors.AUTH_USERNAME_EXISTS, 400) else: return jsonify(user.to_dict())
def create_user(): missing = User.check_required(request.json) if missing: return error_response( apierrors.API_FIELDS_MISSING.format(missing), 400) else: user = get_datastore().create_user( email=request.json.get('email'), password=encrypt_password(request.json.get('password'))) userrole = user_datastore.find_role('admin') user_datastore.add_role_to_user(user, userrole) try: db.session.add(user) db.session.commit() except IntegrityError: return error_response(errors.AUTH_USERNAME_EXISTS, 400) else: return jsonify(user.to_dict())
def create_user(): missing = User.check_required(request.json) if missing: return error_response(apierrors.API_FIELDS_MISSING.format(missing), 400) else: user = get_datastore().create_user( email=request.json.get("email"), password=encrypt_password(request.json.get("password")) ) userrole = user_datastore.find_role("admin") user_datastore.add_role_to_user(user, userrole) try: db.session.add(user) db.session.flush() apikey = ApiKey(user_id=user.id, api_key=str(uuid.uuid4()).replace("-", "")) db.session.add(apikey) db.session.commit() except IntegrityError: return error_response(errors.AUTH_USERNAME_EXISTS, 400) else: return jsonify(user.to_dict())