def get(self):
        mongo_instance = EnglishMongoDB().get_instance()
        db = mongo_instance.atlantic

        cursor = db.find()
        list_cur = list(cursor)
        for idx, doc in enumerate(list_cur):
            doc['_id'] = str(doc['_id'])
            list_cur[idx] = doc
        json_data = json.dumps(list_cur, indent=2)
        return json_data
Esempio n. 2
0
 def post(self):
     json_data = request.get_json(force=True)
     mongo_instance = EnglishMongoDB().get_instance()
     db = mongo_instance.user
     try:
         user = db.find_one({'email': json_data['email']})
     except:
         return {"status": "FAILED"}, 400
     if user and app.flask_bcrypt.check_password_hash(
             user['password'], json_data['password']):
         return {"status": "SUCCESS"}, 200
     else:
         return {"status": "FAILED"}, 401
Esempio n. 3
0
    def post(self):
        json_data = request.get_json(force=True)
        json_data['password'] = app.flask_bcrypt.generate_password_hash(
            json_data['password'])
        json_data['gender'] = int(json_data['gender'])
        json_data['_id'] = json_data['email']

        mongo_instance = EnglishMongoDB().get_instance()
        db = mongo_instance.user
        if db.find({'_id': json_data['_id'].lower()}).count() > 0:
            return {"status": "DUPLICATE"}, 200
        else:
            db.insert_one(json_data)
            return {"status": "SUCCESS"}, 200
Esempio n. 4
0
 def get(self):
     parser = reqparse.RequestParser()
     parser.add_argument('email', type=str)
     args = parser.parse_args()
     mongo_instance = EnglishMongoDB().get_instance()
     db = mongo_instance.user
     user = db.find_one({'email': args['email']})
     if user:
         user_info = {}
         user_info['email'] = user['email']
         user_info['gender'] = user['gender']
         user_info['fullname'] = user['fullName']
         user_info['phone'] = user['phone']
         return user_info, 200
     else:
         return {"status": "FAILED", "description": "user not found!"}, 400
    def get(self, question_id):
        mongo_instance = EnglishMongoDB().get_instance()
        db = mongo_instance.writing_question
        question = db.find_one({'_id': int(question_id)})

        if question:
            q = {}
            q['id'] = question['_id']
            q['question'] = question['question']

            json_str = json.dumps(q, ensure_ascii=False, indent=4, sort_keys=True)
            json_utf8 = json_str.encode('utf-8')
            response = make_response(json_utf8)
            response.headers['Content-Type'] = 'application/json; charset=utf-8'
            response.headers['mimetype'] = 'application/json'
            return q, 200
        else:
            return {'status': 'NOT FOUND'}, 404