示例#1
0
    def post(self):
        """
        @api {POST} /threads Create thread
        @apiGroup Thread

        @apiParam (JSON param) {String} name Name of the thread. Has to be unique, must not be a number, length 2-50
        @apiParam (JSON param) {Boolean} private Whether the thread is to be private or not

        @apiSuccessExample {JSON} Success-Response:
            {
                ThreadModel
            }
        """
        args = self.reqparse.parse_args()
        user_id = auth.user_id

        # Validate thread name
        if ThreadVerifications(by="name",
                               value=args.name).check_thread_exists():
            HttpException.throw_409("Thread name already taken")
        elif args.name.isdigit():
            HttpException.throw_422("Thread name must not be a number")
        # Intentional bug with validation between 2 and 60 characters for workshop purposes
        elif not validate_length(2, 60, args.name):
            HttpException.throw_422(
                "Thread name length must be between 2 and 50 characters")

        # Create thread
        thread_model = ThreadsHandler().post(user_id=user_id,
                                             name=args.name,
                                             private=args.private)

        # Return thread
        return thread_model.jsonify()
示例#2
0
    def post(self):
        """
        @api {POST} /signup Signup
        @apiGroup User

        @apiParam (JSON param) {String} username Username. Has to be unique, cannot be a number, length 2-20
        @apiParam (JSON param) {String} password Password. Length 4-20
        @apiParam (JSON param) {String} firstname First name. Length 2-20
        @apiParam (JSON param) {String} lastname Last name. Length 2-50

        @apiSuccessExample {JSON} Success-Response:
            {
                UserModel
            }
        """
        args = self.reqparse.parse_args()

        # Verify username
        if UserVerifications(by="username",
                             value=args.username).check_user_exists():
            HttpException.throw_409("Username already taken")
        elif args.username.isdigit():
            HttpException.throw_422("Username must not be a number")
        elif not validate_length(2, 20, args.username):
            HttpException.throw_422(
                "Username length must be between 2 and 20 characters")
        # Verify password
        elif not validate_length(4, 20, args.password):
            HttpException.throw_422(
                "password length must be between 4 and 20 characters")
        # Verify firstname
        elif not validate_length(2, 20, args.firstname):
            HttpException.throw_422(
                "First name length must be between 2 and 20 characters")
        # Verify lastname
        elif not validate_length(2, 50, args.lastname):
            HttpException.throw_422(
                "Last name length must be between 2 and 50 characters")
        # Register user
        user_model = SignupHandler().post(username=args.username,
                                          password=args.password,
                                          firstname=args.firstname,
                                          lastname=args.lastname)

        return user_model.jsonify()
示例#3
0
 def verify_user_not_invited(self, user_id):
     self.verify_thread_exists()
     if self.check_user_not_invited(user_id=user_id):
         return True
     HttpException.throw_409(
         "User with id '{user_id}' already invited".format(user_id=user_id))
示例#4
0
 def verify_user_not_applied(self, user_id):
     self.verify_thread_exists()
     if self.check_user_not_applied(user_id=user_id):
         return True
     HttpException.throw_409("You have already applied to this thread")