def post(self): data = request.get_json() mandatory_fields = ["name", "email", "password"] if any(data.get(item) is None for item in mandatory_fields): return ResponseGenerator.mandatory_field(fields=mandatory_fields) name, email, password = data.pop("name"), data.pop("email"), data.pop("password") user = UserRepository.create_user(name=name, email=email, password=password, **data) if not user: return ResponseGenerator.error_response(msg="Email is already registered, try to login", code=400) access_token = UserToken.create_user_access_token(user=user) return ResponseGenerator.generate_response({ "access_token": access_token }, code=201)
def create_user(): data = request.get_json() email = data['email'] user = User.query.filter_by(email=email).first() if user: return ResponseGenerator.error_response( f"Already {email} exist in DB. Try using other email address", 409) if data['admin'] == "True": admin = True else: admin = False new_user = User(name=data['name'], email=data['email'], password=data['password'], admin=admin) User.save(new_user) return ResponseGenerator.generate_response(data, 200)