Beispiel #1
0
def backups_import(request):
    response = HTTPFound(location=request.route_path('backups_index'))

    if 'passwords-file' in request.POST:
        passwords_field = request.POST['passwords-file']
        if passwords_field != '':
            try:
                compressed_data = passwords_field.file.read()
                json_data = uncompress(compressed_data)
            except (IOError, ValueError):
                request.session.flash(
                    _('There was a problem reading your passwords file'),
                    'error')
                return response

            Session.query(Password).filter(
                Password.user == request.user).delete(
                    synchronize_session=False)

            for password_data in json_data:
                if 'secret' in password_data:
                    password = Password(user=request.user, **password_data)
                    Session.add(password)

            n_passwords = len(json_data)
            localizer = get_localizer(request)
            msg = localizer.pluralize(
                _('Congratulations, ${n_passwords} password has been imported'
                  ),
                _('Congratulations, ${n_passwords} passwords have been imported'
                  ),
                n_passwords,
                domain=translation_domain,
                mapping={'n_passwords': n_passwords},
            )
            request.session.flash(msg, 'success')
        else:
            request.session.flash(
                _('The passwords file is required to upload the passwords'),
                'error')
            return response
    else:
        request.session.flash(
            _('The passwords file is required to upload the passwords'),
            'error')
        return response

    return response
def backups_import(request):
    response = HTTPFound(location=request.route_path('backups_index'))

    if 'passwords-file' in request.POST:
        passwords_field = request.POST['passwords-file']
        if passwords_field != '':
            try:
                compressed_data = passwords_field.file.read()
                json_data = uncompress(compressed_data)
            except (IOError, ValueError):
                request.session.flash(
                    _('There was a problem reading your passwords file'),
                    'error')
                return response

            Session.query(Password).filter(
                Password.user == request.user
            ).delete(synchronize_session=False)

            for password_data in json_data:
                if 'secret' in password_data:
                    password = Password(user=request.user, **password_data)
                    Session.add(password)

            n_passwords = len(json_data)
            localizer = get_localizer(request)
            msg = localizer.pluralize(
                _('Congratulations, ${n_passwords} password has been imported'),
                _('Congratulations, ${n_passwords} passwords have been imported'),
                n_passwords,
                domain=translation_domain,
                mapping={'n_passwords': n_passwords},
            )
            request.session.flash(msg, 'success')
        else:
            request.session.flash(
                _('The passwords file is required to upload the passwords'),
                'error')
            return response
    else:
        request.session.flash(
            _('The passwords file is required to upload the passwords'),
            'error')
        return response

    return response
Beispiel #3
0
def backups_import(request):
    response = HTTPFound(location=request.route_path('backups_index'))

    if 'passwords-file' in request.POST:
        passwords_field = request.POST['passwords-file']
        if passwords_field != '':
            try:
                json_data = uncompress(passwords_field.file.read())
                passwords_manager = PasswordsManager(request.db)
                passwords_manager.delete(request.user)
                passwords_manager.create(request.user, json_data)
            except (IOError, ValueError):
                request.session.flash(
                    _('There was a problem reading your passwords file'),
                    'error')
                return response

            n_passwords = len(json_data)
            localizer = get_localizer(request)
            msg = localizer.pluralize(
                _('Congratulations, ${n_passwords} password has been imported'),
                _('Congratulations, ${n_passwords} passwords have been imported'),
                n_passwords,
                domain=translation_domain,
                mapping={'n_passwords': n_passwords},
            )
            request.session.flash(msg, 'success')
        else:
            request.session.flash(
                _('The passwords file is required to upload the passwords'),
                'error')
            return response
    else:
        request.session.flash(
            _('The passwords file is required to upload the passwords'),
            'error')
        return response

    return response
    def test_compress_and_uncompress(self):
        passwords = [{
            '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': [],
        }, {
            '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': [],
        }]

        self.assertEqual(uncompress(compress(passwords)), passwords)
Beispiel #5
0
    def test_compress_and_uncompress(self):
        passwords = [{
            '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': [],
        }, {
            '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': [],
        }]

        self.assertEqual(uncompress(compress(passwords)), passwords)
Beispiel #6
0
    def test_compress_and_uncompress(self):
        passwords = [{'password': '******'}, {'password': '******'}]

        self.assertEqual(uncompress(compress(passwords)), passwords)