Ejemplo n.º 1
0
 def get(self):
     query = dict(mch_id=get_current_user().mch_id)
     pager = page_param()
     data = MONGODB.get_db(self.col_name).find(query,
                                               skip=pager.skip,
                                               limit=pager.limit)
     assert data
     return jsonify(DataSchema(many=True).load(data, unknown=INCLUDE))
Ejemplo n.º 2
0
 def put(self):
     query = dict(_id=get_current_user().get_id())
     data = request.get_json()
     assert data
     info = DataSchema(exclude=('_id', ),
                       partial=True).load(data, unknown=INCLUDE)
     return dict(result=str(
         MONGODB.get_db(self.col_name).update_one(query, {
             '$set': info
         }).acknowledged))
Ejemplo n.º 3
0
 def post(self):
     pwd = ChangePasswordParam.get_param()
     user_id = get_current_user().get_id()
     user = MONGODB.get_db(self.col_name).find_one({'_id': user_id},
                                                   {'password': 1})
     if not user:
         raise HandlerException(status_code=500, message='unknown error')
     if not check_password_hash(user['password'], pwd.get('old_password')):
         raise HandlerException(status_code=403,
                                message='error old password')
     result = MONGODB.get_db(self.col_name).update_one({'_id': user_id}, {
         '$set': {
             'password': generate_password_hash(pwd['new_password'])
         }
     })
     if result.modified_count != 1:
         raise HandlerException(status_code=403,
                                message='change password failed')
     return 'ok'
Ejemplo n.º 4
0
 def get(self):
     query = dict(_id=get_current_user().get_id())
     data = MONGODB.get_db(self.col_name).find_one(query)
     assert data
     return DataSchema().load(data, unknown=INCLUDE)
Ejemplo n.º 5
0
 def get(self):
     query = dict(_id=get_current_user().mch_id)
     data = MONGODB.get_db(self.col_name).find_one(query)
     if data is not None:
         data = DataSchema().load(data, unknown=INCLUDE)
     return jsonify(data)
Ejemplo n.º 6
0
 def get(self, _id):
     query = dict(_id=_id, mch_id=get_current_user().mch_id)
     data = MONGODB.get_db(self.col_name).find_one(query)
     assert data, 'not found'
     return DataSchema().load(data, unknown=INCLUDE)