Exemplo n.º 1
0
    def post(self):
        data = UserRegister.parser.parse_args()

        try:
            user = UserModel(**data)
            user.add_to_db()

        except Exception as err:
            print(err)
            return {'message': 'an error occured'}, 500

        return {'message': 'user created successfully'}, 201
Exemplo n.º 2
0
    def post(self):
        data = UserRegister.parser.parse_args()
        username = data['username']
        password = data['password']

        user = UserModel.find_by_username(username)
        if not user:
            user = UserModel(**data)
            user.add_to_db()
            return {'message': 'successfully created'}

        return {'message': 'user already exists'}
Exemplo n.º 3
0
 def post(self):
     data = UserRegister.parser.parse_args()
     username = data.get("username")
     password = data.get("password")
     if username is None or password is None:
         return {"message": "username/password missing :| "}, 422
     if UserModel.find_by_uname(username=username):
         return {"message": "The username is taken. :( "}, 422
     user = UserModel(username=username)
     user.hash_password(password)
     user.add_to_db()
     return {"message": f"User {username} added successfully"}, 200
Exemplo n.º 4
0
    def post(self, is_customer):
        # Creates new employee/customer if one with that email does not exist.
        data = UserCreator.parser.parse_args()

        user = UserModel.find_by_email(data['email'], is_customer)

        if user:
            return {"message": "User already exists"}, 404

        user = UserModel(data['email'], data['name'], is_customer=is_customer)

        try:
            user.add_to_db()
        except IntegrityError:
            return {"message": "An error occurred inserting the item."}, 500

        return user.json(), 201