def get_cdav_client(request, addressbook, write_support=False): """Instantiate a new CardDAV client.""" return carddav.PyCardDAV(addressbook.url, user=request.user.username, passwd=cryptutils.decrypt( request.session["password"]), write_support=write_support)
def test_decrypt(self): """Decrypt a string""" value = "gAAAAABaXSWk4Via-aYP7diek9MmfknUiEY8szrgxIytdXrbfc"\ "YlbOYiNG01zqkn3a06P1xPXe5XD2SP4UrIvCWzhLs-FO19Cw==" expected_output = "test" output = cryptutils.decrypt(value) self.assertEqual(output, expected_output)
def test_encrypt(self): """Encrypt a string""" value = "test" expected_output = "test" output = cryptutils.encrypt(value) output = cryptutils.decrypt(output) self.assertEqual(output, expected_output)
def save(self, *args, **kwargs): """Create remote cal if necessary.""" super(UserSettings, self).save(*args, **kwargs) if not self.cleaned_data["enable_carddav_sync"]: return abook = self.user.addressbook_set.first() if abook.last_sync: return request = lib_signals.get_request() tasks.create_cdav_addressbook( abook, cryptutils.decrypt(request.session["password"])) if not abook.contact_set.exists(): abook.last_sync = timezone.now() abook.save(update_fields=["last_sync"])
def __call__(cls, **kwargs): key = None if "user" in kwargs: key = kwargs["user"] else: return None if key not in cls.instances: cls.instances[key] = None if "password" in kwargs: kwargs["password"] = decrypt(kwargs["password"]) if cls.instances[key] is None: cls.instances[key] = \ super(ConnectionsManager, cls).__call__(**kwargs) else: cls.instances[key].refresh(key, kwargs["password"]) return cls.instances[key]
def password(self): """Password getter.""" return decrypt(self._password)
def get_backend_from_request(name, request, calendar=None): """Return a backend instance from a request.""" password = decrypt(request.session["password"]) return get_backend( name, request.user.email, password, calendar=calendar)