Exemplo n.º 1
0
    def put(self, resp):
        post_data = request.get_json()
        response_object = {'status': 'fail', 'message': 'Invalid payload'}
        if not is_admin(resp):
            response_object['message'] = \
                "You do not have permission to do that."
            return response_object, HTTPStatus.UNAUTHORIZED
        if not post_data:
            return response_object, HTTPStatus.BAD_REQUEST

        id = post_data.get('id')
        username = post_data.get('username')
        email = post_data.get('email')
        password = post_data.get('password')

        user_to_update = UsersModel.query.get(int(id))
        user_to_update.username = username
        user_to_update.username = email
        user_to_update.username = password
        db.session.commit()

        try:
            response_object = {
                'status': 'success',
                'message': f'{email} was added!'
            }
            return response_object, HTTPStatus.CREATED
        except Exception as e:
            log.error(e)
Exemplo n.º 2
0
    def post(self, resp):
        post_data = request.get_json()
        response_object = {'status': 'fail', 'message': 'Invalid payload'}
        if not is_admin(resp.id):
            response_object['message'] = \
                "You do not have permission to do that."
            return response_object, HTTPStatus.UNAUTHORIZED
        if not post_data:
            return response_object, HTTPStatus.BAD_REQUEST

        try:
            username = post_data.get('username')
            email = post_data.get('email')
            password = post_data.get('password')

            new_user = Users(username=username, email=email, password=password)
            db.session.add(new_user)
            db.session.commit()

            response_object = {
                'status': 'success',
                'message': f'{email} was added!'
            }
            return response_object, HTTPStatus.CREATED
        except Exception as e:
            log.error(e)
Exemplo n.º 3
0
    def put(self, user):
        post_data = request.get_json()
        response_object = {'status': 'fail', 'message': 'Invalid payload'}
        if not is_admin(resp):
            response_object['message'] = \
                "You do not have permission to do that."
            return response_object, HTTPStatus.UNAUTHORIZED
        if not post_data:
            return response_object, HTTPStatus.BAD_REQUEST

        username = post_data.get('username')
        email = post_data.get('email')
        try:
            response_object = {
                'status': 'success',
                'message': f'{email} was added!'
            }
            return response_object, HTTPStatus.CREATED
        except Exception as e:
            log.error(e)