コード例 #1
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def put_detail(self, collection, pk):
     """Updates whole document."""
     collection = self.get_collection(collection)
     if '_id' in request.json:
         # we are ignoring id fields of bundle,
         # because _id field is immutable
         del request.json['_id']
     collection.update({"_id": ObjectId(pk)}, request.json)
     response.status = 202
     return jsonify(request.json)
コード例 #2
0
 def put_detail(self, collection, pk):
     """Updates whole document."""
     collection = self.get_collection(collection)
     if '_id' in request.json:
         # we are ignoring id fields of bundle,
         # because _id field is immutable
         del request.json['_id']
     collection.update({"_id": ObjectId(pk)}, request.json)
     response.status = 202
     return jsonify(request.json)
コード例 #3
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def authenticate(self):
     collection = self.connection['users']
     username = request.json.get('username')
     password = request.json.get('password')
     hasher = hashlib.md5()
     hasher.update(password)
     user = collection.find_one({
         'username': username,
         'password': hasher.hexdigest(),
     }) or abort(400, 'Wrong username or password')
     access_token = str(uuid.uuid4())
     self.connection['access_tokens'].insert({
         'access_token': access_token,
         'user_id': user.get('id')})
     user.pop('password')
     user.update({'access_token': access_token})
     return jsonify(user)
コード例 #4
0
ファイル: auth.py プロジェクト: yutiansut/kule
 def authenticate(self):
     collection = self.connection['users']
     username = request.json.get('username')
     password = request.json.get('password')
     hasher = hashlib.md5()
     hasher.update(password)
     user = collection.find_one({
         'username': username,
         'password': hasher.hexdigest(),
     }) or abort(400, 'Wrong username or password')
     access_token = str(uuid.uuid4())
     self.connection['access_tokens'].insert({
         'access_token': access_token,
         'user_id': user.get('id')
     })
     user.pop('password')
     user.update({'access_token': access_token})
     return jsonify(user)
コード例 #5
0
    def get_list(self, collection):
        """Returns paginated objects."""
        collection = self.get_collection(collection)
        limit = int_or_default(request.query.limit, 20)
        offset = int_or_default(request.query.offset, 0)
        query = self.get_query()
        cursor = collection.find(query)

        meta = {
            "limit": limit,
            "offset": offset,
            "total_count": cursor.count(),
        }

        objects = cursor.skip(offset).limit(limit)
        objects = map(self.get_bundler(collection), objects)

        return jsonify({"meta": meta, "objects": objects})
コード例 #6
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def register(self):
     collection = self.connection['users']
     password = request.json.get('password')
     username = request.json.get('username')
     email = request.json.get('email')
     if not username or not password:
         abort(400, 'Please give an username and password')
     if collection.find_one({'username': username}):
         abort(400, 'A user with that username already exists')
     if collection.find_one({'email': email}):
         abort(400, 'A user with that email already exists')
     hasher = hashlib.md5()
     hasher.update(password)
     response.status = 201
     return jsonify({"_id": collection.insert({
         'username': request.json.get('username'),
         'email': request.json.get('email'),
         'password': hasher.hexdigest()
     })})
コード例 #7
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
    def get_list(self, collection):
        """Returns paginated objects."""
        collection = self.get_collection(collection)
        limit = int_or_default(request.query.limit, 20)
        offset = int_or_default(request.query.offset, 0)
        query = self.get_query()
        cursor = collection.find(query)

        meta = {
            "limit": limit,
            "offset": offset,
            "total_count": cursor.count(),
        }

        objects = cursor.skip(offset).limit(limit)
        objects = map(self.get_bundler(collection), objects)

        return jsonify({"meta": meta,
                        "objects": objects})
コード例 #8
0
ファイル: auth.py プロジェクト: yutiansut/kule
 def register(self):
     collection = self.connection['users']
     password = request.json.get('password')
     username = request.json.get('username')
     email = request.json.get('email')
     if not username or not password:
         abort(400, 'Please give an username and password')
     if collection.find_one({'username': username}):
         abort(400, 'A user with that username already exists')
     if collection.find_one({'email': email}):
         abort(400, 'A user with that email already exists')
     hasher = hashlib.md5()
     hasher.update(password)
     response.status = 201
     return jsonify({
         "_id":
         collection.insert({
             'username': request.json.get('username'),
             'email': request.json.get('email'),
             'password': hasher.hexdigest()
         })
     })
コード例 #9
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def error(self, error, message=None):
     """Returns the error response."""
     return jsonify({"error": error.status_code,
                     "message": error.body or message})
コード例 #10
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def post_list(self, collection):
     """Creates new document"""
     collection = self.get_collection(collection)
     inserted = collection.insert(request.json)
     response.status = 201
     return jsonify({"_id": inserted})
コード例 #11
0
ファイル: allPythonContent.py プロジェクト: Mondego/pyreco
 def get_detail(self, collection, pk):
     """Returns a single document."""
     cursor = self.get_collection(collection)
     data = cursor.find_one({"_id": ObjectId(pk)}) or abort(404)
     return jsonify(self.get_bundler(cursor)(data))
コード例 #12
0
 def error(self, error, message=None):
     """Returns the error response."""
     return jsonify({
         "error": error.status_code,
         "message": error.body or message
     })
コード例 #13
0
 def post_list(self, collection):
     """Creates new document"""
     collection = self.get_collection(collection)
     inserted = collection.insert(request.json)
     response.status = 201
     return jsonify({"_id": inserted})
コード例 #14
0
 def get_detail(self, collection, pk):
     """Returns a single document."""
     cursor = self.get_collection(collection)
     data = cursor.find_one({"_id": ObjectId(pk)}) or abort(404)
     return jsonify(self.get_bundler(cursor)(data))