def remove_friend(pubkey): contactmanager.ContactManager(pubkey).setTrust(0) contactmanager.ContactManager(pubkey).delete_contact() keydb.removekeys.remove_user(pubkey) try: return redirect(request.referrer + '#' + request.form['token']) except TypeError: return Response( "Friend removed, but referrer not set, cannot return to page")
def on_processblocks(api, data=None): if data['type'] != 'pm': return notification_func = notifier.notify data['block'].decrypt() metadata = data['block'].bmetadata signer = bytesconverter.bytes_to_str(data['block'].signer) user = contactmanager.ContactManager(signer, saveUser=False) name = user.get_info("name") if name != 'anonymous' and name != None: signer = name.title() else: signer = signer[:5] if data['block'].decrypted: config.reload() if config.get('mail.notificationSound', True): notification_func = notifier.notification_with_sound if config.get('mail.notificationSetting', True): if not config.get('mail.strangersNotification', True): if not user.isFriend(): return notification_func(title="Onionr Mail - New Message", message="From: %s\n\nSubject: %s" % (signer, metadata['subject']))
def test_encrypt(self): contactPair = crypto.generate() contact = contactmanager.ContactManager(contactPair[0], saveUser=True) encrypted = contact.encrypt('test') decrypted = crypto.encryption.pub_key_decrypt( encrypted, privkey=contactPair[1], encodedData=True).decode() self.assertEqual('test', decrypted)
def add_friend(pubkey): contactmanager.ContactManager(pubkey, saveUser=True).setTrust(1) try: return redirect(request.referrer + '#' + request.form['token']) except TypeError: return Response( "Added, but referrer not set, cannot return to friends page")
def set_info(pubkey, key): data = request.form['data'] contactmanager.ContactManager(pubkey).set_info(key, data) try: return redirect(request.referrer + '#' + request.form['token']) except TypeError: return Response( "Info set, but referrer not set, cannot return to friends page")
def test_contact_get_info(self): contact = c._crypto.generatePubKey()[0] contact = contactmanager.ContactManager(c, contact, saveUser=True) fileLocation = '%s/contacts/%s.json' % (c.dataDir, contact.publicKey) with open(fileLocation, 'w') as contactFile: contactFile.write('{"alias": "bob"}') self.assertEqual(contact.get_info('alias', forceReload=True), 'bob') self.assertEqual(contact.get_info('fail', forceReload=True), None) self.assertEqual(contact.get_info('fail'), None)
def test_contact_set_info(self): contact = c._crypto.generatePubKey()[0] contact = contactmanager.ContactManager(c, contact, saveUser=True) fileLocation = '%s/contacts/%s.json' % (c.dataDir, contact.publicKey) contact.set_info('alias', 'bob') self.assertTrue(os.path.exists(fileLocation)) with open(fileLocation, 'r') as data: data = data.read() data = json.loads(data) self.assertEqual(data['alias'], 'bob')
def list_sentbox(): kv.refresh() sentbox_list = sentboxdb.SentBox(c).listSent() list_copy = list(sentbox_list) deleted = kv.get('deleted_mail') if deleted is None: deleted = [] for x in list_copy: if x['hash'] in deleted: sentbox_list.remove(x) continue x['name'] = contactmanager.ContactManager(c, x['peer'], saveUser=False).get_info('name') return json.dumps(sentbox_list)
def on_processblocks(api, data=None): if data['type'] != 'pm': return data['block'].decrypt() metadata = data['block'].bmetadata signer = bytesconverter.bytes_to_str(data['block'].signer) user = contactmanager.ContactManager(signer, saveUser=False) name = user.get_info("name") if name != 'anonymous' and name != None: signer = name.title() else: signer = signer[:5] if data['block'].decrypted: notifier.notify(title="Onionr Mail - New Message", message="From: %s\n\nSubject: %s" % (signer, metadata['subject']))
def test_delete_contact(self): contact = c._crypto.generatePubKey()[0] contact = contactmanager.ContactManager(c, contact, saveUser=True) fileLocation = '%s/contacts/%s.json' % (c.dataDir, contact.publicKey) self.assertFalse(os.path.exists(fileLocation)) with open(fileLocation, 'w') as contactFile: contactFile.write('{"alias": "test"}') self.assertTrue(os.path.exists(fileLocation)) contact.delete_contact() self.assertFalse(os.path.exists(fileLocation)) try: contact.get_info('alias') except onionrexceptions.ContactDeleted: pass else: self.assertTrue(False) try: contact.set_info('alias', 'test2') except onionrexceptions.ContactDeleted: pass else: self.assertTrue(False)
def test_contact_init_no_save(self): contact = crypto.generate()[0] contact = contactmanager.ContactManager(contact) self.assertFalse(contact.publicKey in keydb.listkeys.list_peers())
def add_friend(pubkey): contactmanager.ContactManager(core.Core(), pubkey, saveUser=True).setTrust(1) return redirect(request.referrer + '#' + request.form['token'])
def test_contact_create(self): contact = c._crypto.generatePubKey()[0] contact = contactmanager.ContactManager(c, contact, saveUser=True) self.assertTrue(contact.publicKey in c.listPeers())
def test_contact_create(self): contact = crypto.generate()[0] contact = contactmanager.ContactManager(contact, saveUser=True) self.assertTrue(contact.publicKey in keydb.listkeys.list_peers())
def test_contact_init_no_save(self): contact = c._crypto.generatePubKey()[0] contact = contactmanager.ContactManager(c, contact) self.assertFalse(contact.publicKey in c.listPeers())
def remove_friend(pubkey): contactmanager.ContactManager(pubkey).setTrust(0) contactmanager.ContactManager(pubkey).delete_contact() keydb.removekeys.remove_user(pubkey) return redirect(request.referrer + '#' + request.form['token'])
def get_info(pubkey, key): retData = contactmanager.ContactManager(core.Core(), pubkey).get_info(key) if retData is None: abort(404) else: return retData
def set_info(pubkey, key): data = request.form['data'] contactmanager.ContactManager(core.Core(), pubkey).set_info(key, data) return redirect(request.referrer + '#' + request.form['token'])
def remove_friend(pubkey): contactmanager.ContactManager(core.Core(), pubkey).setTrust(0) return redirect(request.referrer + '#' + request.form['token'])