Exemplo n.º 1
0
def secret_import(file_name):
    from secret.models import Secret
    from comment.models import DiscussionComment, Proposal
    # imports data
    data = import_csv(file_name)
    
    count = 0
    # creates for each data point
    for row in data:
        #try:
        if len(row) > 1:
            try:
                s = Secret()
                s.id = clean(row[0])
                # data item 2 need to load into comments
                s.title = clean(row[2])
                s.location = clean(row[3])
                s.url = clean(row[4])
                
                comment = DiscussionComment.objects.get(pk=clean(row[1]))
                
                s.created_by = comment.created_by
                s.created_at = datetime.datetime.now()
                s.updated_at = datetime.datetime.now()
                s.save()
                
                p = Proposal()
                p.discussion_comment = comment
                p.secret = s
                p.save()
            except:
                print row[0]
Exemplo n.º 2
0
    def test_encrypt(self):
        v = '1' * 32
        c = ''.join(chr(ord(a) ^ ord(b)) for (a, b) in zip(KEY, v))

        s = Secret()
        s.content = v
        self.assertEqual(s._content, c)

        print
        print 'DEBUG encrypt: c', ''.join('%02x' % ord(i) for i in c)
        print 'DEBUG encrypt: s._content', ''.join('%02x' % ord(i) for i in s._content)
    def validate(self, data):

        # Encrypt plaintext using master key from view
        if data.get('plaintext'):
            s = Secret(plaintext=data['plaintext'])
            s.encrypt(self.context['master_key'])
            data['ciphertext'] = s.ciphertext
            data['hash'] = s.hash

        # Enforce model validation
        super().validate(data)

        return data
Exemplo n.º 4
0
    def save(self):
        is_anony = self.cleaned_data['is_anony']
        is_public = self.cleaned_data['is_public']
        content = self.cleaned_data['content']

        if is_anony or not self.user.is_authenticated():
            new_secret = Secret(content = content,
                            is_public = is_public)
        else:
            new_secret = Secret(author = self.user,
                            content = content,
                            is_public = is_public)
        new_secret.save()
        return new_secret
Exemplo n.º 5
0
def load_link(request):
    global analytics
    form = forms.Secret(request.POST)

    if form.is_valid():
        analytics.secret(Analytics.ACTION_FORM_SECRET, Analytics.LABEL_VALID)
        saved = False

        while not saved:
            id = generate_id()
            secret = get_secret(id)

            if not secret:
                secret = Secret()
                secret.secret = form.cleaned_data['secret']
                secret.id = id
                secret.save()
                saved = True
                secret_link = request.build_absolute_uri() + id
                analytics.secret(Analytics.ACTION_VIEW, Analytics.LABEL_LINK)
    else:
        analytics.secret(Analytics.ACTION_FORM_SECRET, Analytics.LABEL_INVALID)
        secret_link = "Something went wrong"

    display_data = {'secret_link': secret_link}
    return view.display_secret(request,
                               page='secret_link.html',
                               data=display_data,
                               ga_page='secret_link/')
Exemplo n.º 6
0
    def save(self):
        is_anony = self.cleaned_data['is_anony']
        is_public = self.cleaned_data['is_public']
        content = self.cleaned_data['content']

        if is_anony or not self.user.is_authenticated():
            new_secret = Secret(content=content, is_public=is_public)
        else:
            new_secret = Secret(author=self.user,
                                content=content,
                                is_public=is_public)
        new_secret.save()
        return new_secret