Exemple #1
0
def send_passwords(request, user, preferences_link, backups_link):
    passwords = get_user_passwords(user)
    if not passwords:
        return False

    context = {
        'user': user,
        'preferences_link': preferences_link,
        'backups_link': backups_link,
    }

    today = datetime.date.today()
    attachment = Attachment(get_backup_filename(today), "application/yith",
                            compress(passwords))

    send_email(
        request,
        'yithlibraryserver.backups:templates/email_passwords',
        context,
        "Your Yith Library's passwords",
        [user.email],
        attachments=[attachment],
    )

    return True
Exemple #2
0
def send_passwords(request, user, preferences_link, backups_link):
    passwords = get_user_passwords(user)
    if not passwords:
        return False

    context = {
        'user': user,
        'preferences_link': preferences_link,
        'backups_link': backups_link,
    }

    today = datetime.date.today()
    attachment = Attachment(get_backup_filename(today),
                            "application/yith",
                            compress(passwords))

    send_email(
        request,
        'yithlibraryserver.backups:templates/email_passwords',
        context,
        "Your Yith Library's passwords",
        [user.email],
        attachments=[attachment],
    )

    return True
Exemple #3
0
def backups_export(request):
    passwords = get_user_passwords(request.db, request.user)
    data = compress(passwords)
    response = Response(body=data, content_type='application/yith-library')
    today = datetime.date.today()
    filename = get_backup_filename(today)
    response.content_disposition = 'attachment; filename=%s' % filename
    return response
Exemple #4
0
def backups_export(request):
    passwords = get_user_passwords(request.user)
    data = compress(passwords)
    response = Response(body=data, content_type='application/yith-library')
    today = datetime.date.today()
    filename = get_backup_filename(today)
    response.content_disposition = 'attachment; filename=%s' % filename
    return response
Exemple #5
0
    def test_get_user_passwords_no_passwords(self):
        user = User(first_name='John', last_name='Doe')

        with transaction.manager:
            Session.add(user)
            Session.flush()
            user_id = user.id

        user = Session.query(User).filter(User.id == user_id).one()

        self.assertEqual(get_user_passwords(user), [])
    def test_get_user_passwords_no_passwords(self):
        user = User(first_name='John',
                    last_name='Doe')

        with transaction.manager:
            Session.add(user)
            Session.flush()
            user_id = user.id

        user = Session.query(User).filter(User.id == user_id).one()

        self.assertEqual(get_user_passwords(user), [])
    def test_get_user_passwords(self):
        user_id = self.db.users.insert({
            'first_name': 'John',
            'last_name': 'Doe',
        })
        user = self.db.users.find_one({'_id': user_id})

        self.assertEqual(get_user_passwords(self.db, user), [])

        self.db.passwords.insert({
            'owner': user_id,
            'password': '******',
        })
        self.db.passwords.insert({
            'owner': user_id,
            'password': '******',
        })

        self.assertEqual(get_user_passwords(self.db, user), [{
            'password': '******',
        }, {
            'password': '******',
        }])
Exemple #8
0
    def test_get_user_passwords_some_passwords(self):
        user = User(first_name='John',
                    last_name='Doe',
                    email='*****@*****.**')

        # add some passwords
        password1 = Password(secret='s3cr3t1', user=user)
        password2 = Password(secret='s3cr3t2', user=user)

        with transaction.manager:
            Session.add(user)
            Session.add(password1)
            Session.add(password2)
            Session.flush()
            user_id = user.id

        user = Session.query(User).filter(User.id == user_id).one()

        self.assertEqual(
            get_user_passwords(user),
            [{
                'account': '',
                'creation': datetime.datetime(2014, 2, 23, 8, 0, 0),
                'expiration': None,
                'modification': datetime.datetime(2014, 2, 23, 8, 0, 0),
                'notes': '',
                'secret': 's3cr3t1',
                'service': '',
                'tags': [],
            }, {
                'account': '',
                'creation': datetime.datetime(2014, 2, 23, 8, 0, 0),
                'expiration': None,
                'modification': datetime.datetime(2014, 2, 23, 8, 0, 0),
                'notes': '',
                'secret': 's3cr3t2',
                'service': '',
                'tags': [],
            }])
    def test_get_user_passwords_some_passwords(self):
        user = User(first_name='John',
                    last_name='Doe',
                    email='*****@*****.**')

        # add some passwords
        password1 = Password(secret='s3cr3t1', user=user)
        password2 = Password(secret='s3cr3t2', user=user)

        with transaction.manager:
            Session.add(user)
            Session.add(password1)
            Session.add(password2)
            Session.flush()
            user_id = user.id

        user = Session.query(User).filter(User.id == user_id).one()

        self.assertEqual(get_user_passwords(user), [{
            'account': '',
            'creation': datetime.datetime(2014, 2, 23, 8, 0, 0),
            'expiration': None,
            'modification': datetime.datetime(2014, 2, 23, 8, 0, 0),
            'notes': '',
            'secret': 's3cr3t1',
            'service': '',
            'tags': [],
        }, {
            'account': '',
            'creation': datetime.datetime(2014, 2, 23, 8, 0, 0),
            'expiration': None,
            'modification': datetime.datetime(2014, 2, 23, 8, 0, 0),
            'notes': '',
            'secret': 's3cr3t2',
            'service': '',
            'tags': [],
        }])