Ejemplo n.º 1
0
    def post(self):
        """
        create new user
        """
        data, status = validate(request.json,
                                'user_create',
                                validate_password=True)
        if status is False:
            raise BadRequest(json.dumps(data))

        admin = data.get('admin', False)

        # Only admin users can create.
        if admin:
            user_id, grants, _ = get_userinfo_by_token()

            if 'admin' not in grants:
                raise Forbidden('You need to be an administrator!')

        user = UsersBusiness.create(data, admin=admin)

        if not user:
            raise InternalServerError('Error creating user!')

        return marshal(user, get_user_serializer()), 200
Ejemplo n.º 2
0
    def get(self, id):
        """
        user informations by id
        """
        user = UsersBusiness.get_by_id(id)
        if not user:
            raise NotFound("User not Found!")

        return marshal(user, get_user_serializer())