Ejemplo n.º 1
0
Archivo: handlers.py Proyecto: Wdeil/x
    def post(self):
        response = {}
        admin_id = yield self.admin_author()
        if not admin_id:
            self.set_status(401)
            response['msg'] = "Auth deny"
            self.write(response)
            return
        
        content = str(self.get_body_argument("content", ''))
        if not content:
            self.set_status(400)
            response['msg'] = "Malformed Request"
            self.write(response)
            return

        board_id = shortid_generate()
        date = datetime.datetime.utcnow().isoformat()

        board_res = yield self.db.boards.insert({'id': board_id, 'date': date, 'content': content})
        if not board_res:
            self.set_status(404)
            response['msg'] = "Board Create Error"
            self.write(response)
            return

        response['msg'] = "Board Create Success"
        self.write(response)
        return
Ejemplo n.º 2
0
Archivo: handlers.py Proyecto: Wdeil/x
    def post(self):
        response = {}
        admin_id = yield self.admin_author()
        if not admin_id:
            self.set_status(401)
            response['msg'] = "Auth deny"
            self.write(response)
            return
        
        category = str(self.get_body_argument("category", ''))
        title = str(self.get_body_argument("title", ''))
        description = str(self.get_body_argument("description", ''))
        value = int(self.get_body_argument("value", 0))
        flag = str(self.get_body_argument("flag", ''))
        if not category or not title or not description or not value or not flag:
            self.set_status(400)
            response['msg'] = "Malformed Request"
            self.write(response)
            return
        
        challenge_id = shortid_generate()
        challenge = {'id': challenge_id, 'category': category, 'title': title, 'description': description, 'value': value, 'flag': flag, 'files': False, 'hidden': False}
        
        files = self.request.files
        if files:
            challenge['files'] = True
        for filelist in files:
            for afile in files[filelist]:
                filename = secure_filename(afile.get('filename', ''))
                if not len(filename):
                    continue
                md5hash = hashlib.md5(os.urandom(64)).hexdigest()
                if not os.path.exists(os.path.join(os.path.normpath(self.settings.get("static_path")), 'uploads', md5hash)):
                    os.makedirs(os.path.join(os.path.normpath(self.settings.get("static_path")), 'uploads', md5hash))
                location = os.path.join(os.path.normpath(self.settings.get("static_path")).split('/')[-1], 'uploads', md5hash, filename)
                with open(location, 'w') as f:
                    f.write(afile.get('body', ''))
                file_res = yield self.db.files.insert({'chalid': challenge_id, 'location': location})
                if not file_res:
                    self.set_status(404)
                    response['msg'] = "File Create Error."
                    self.write(response)
                    return

        try:
            result = yield self.db.challenges.insert(challenge)
        except Exception as e:
            # add log here
            self.set_status(404)
            response['msg'] = "Challenge Create Error."
            self.write(response)
            return
        if result:
            self.set_status(201)
            response['msg'] = "Challenge Create Success"
            self.write(response)
            return
Ejemplo n.º 3
0
Archivo: handlers.py Proyecto: Wdeil/x
    def post(self):
        response = {}
        username = str(self.get_body_argument("username", ''))
        password = str(self.get_body_argument("password", ''))
        email = str(self.get_body_argument("email", ''))
        coutry = str(self.get_body_argument("coutry", ''))
        if not check_uname_passwd(username, password) or not check_email(email):
            self.set_status(400)
            response['msg'] = "The type of username or password or email is error"
            self.write(response)
            return

        user_id = shortid_generate()
        passwd = passwd_hash(str(password))
        user = {'id': user_id, 'username': str(username), 'password': passwd, 'email': str(email), 'coutry': coutry, 'admin_auth': False, 'score': 0, 'banned': False}
        db_uname, db_email = yield [self.db.users.find({'username': str(username)}).count(), self.db.users.find({'email': str(email)}).count()]
        if db_uname or db_email:
            self.set_status(400)
            if db_email and db_uname:
                response['msg'] = "The email and username have exited"
            elif db_email:
                response['msg'] = "The email have exited"
            else:
                response['msg'] = "The username have exited"
            self.write(response)
            return

        try:
            result = yield self.db.users.insert(user)
        except Exception as e:
            # add log here
            self.set_status(404)
            response['msg'] = "Register Error."
            self.write(response)
            return
        if result:
            self.set_status(201)
            response['msg'] = "Register Success"
            self.write(response)
            return
        else:
            self.set_status(404)
            response['msg'] = "Register Error"
            self.write(response)
            return