Ejemplo n.º 1
0
    def set_user_password_reset_confirmation_code(self, userid):
        """
        Sets user's password reset confirmation code
        """
        user = self.filter(id=userid).first()

        if not user:
            raise ValueError("Unable to find user with userid: %s" % userid)
        code = random_string(PASSWORD_RESET_CONFIRMATION_CODE_LENGTH)
        user.passwordresetconfirmationcode = code
        user.save()
        return code
Ejemplo n.º 2
0
    def set_user_email_confirmation_code(self, userid):
        """
        This will create a new email verification code for the user
        and will set their emailconfirmed = False
        """
        user = self.filter(id=userid).first()

        if not user:
            raise ValueError("Unable to find user with userid: %s" % userid)
        code = random_string(EMAIL_CONFIRMATION_CODE_LENGTH)
        user.emailconfirmationcode = code
        user.emailconfirmed = False
        user.save()
        return code
Ejemplo n.º 3
0
def art(request, booktitle):
    if request.method == "POST":
        book = models.Book.objects.filter(title_url=booktitle).first()
        if not book:
            raise ValueError("Unable to find book with title: %s" % booktitle)
        request_file = request.FILES['art-image']
        art_title = request.POST.get("artTitle", "").strip()
        # Validate data
        if not image_type_valid(request_file.content_type):
            raise ValueError("Unsupported content type")
        elif len(art_title) == 0:
            raise ValueError("Title cannot be empty")
        elif request_file.size > MAX_FILE_SIZE:
            raise ValueError("File cannot be greater than 25MB")

        # Create art
        title_url = string_to_url(request.POST['artTitle'])
        filename, ext = os.path.splitext(request_file.name)
        for _ in range(50):
            # Try 50 times to find a filename
            filename = "art_image__" + random_string(length=80) + ext
            fq_filename = os.path.join(ART_IMAGE_PATH, filename)

            if os.path.exists(fq_filename):
                if _ == 49:
                    raise ValueError("Error saving image")
                else:
                    continue
            else:
                break

        # Save file to disk
        handle_uploaded_image(request_file, fq_filename)

        # If successful then create an Image and assign to user
        art_image = models.Image()
        art_image.imagetype = ART_IMAGE_TYPE
        art_image.relativepath = fq_filename
        art_image.filename = filename
        art_image.save()

        # Create Art model
        art = models.Art()
        art.user = request.user
        art.arttype_id = request.POST['artType']
        art.scene_id = request.POST.get("sceneid")
        art.book = book
        art.image = art_image
        art.title = art_title
        art.title_url = title_url
        art.description = request.POST['artText']
        art.nsfw = request.POST.get('nsfw', "f")[0]
        art.save() 

        #
        # TODO: Need to resize and standardize the iamge with a job
        #

        usertasks.add_point_to_user.delay(request.user.id, "adart")

        art_url = "/book/" + book.title_url + "/art/" + art.title_url;
        data = {
           "status": OK,
           "artURL": art_url,
        }
        return json_response(data)
    else:
        return HttpResponse("Art Page")