diff --git a/oml/user/api.py b/oml/user/api.py
index cd4befe..dc8790e 100644
--- a/oml/user/api.py
+++ b/oml/user/api.py
@@ -14,6 +14,7 @@ from utils import update_dict
from . import models
import settings
import state
+import tor_request
import logging
logger = logging.getLogger(__name__)
@@ -412,3 +413,27 @@ def getActivity(data):
'''
return state.activity
actions.register(getActivity, cache=False)
+
+def contact(data):
+ '''
+ return {
+ }
+ '''
+ response = {}
+ url = 'http://rnogx24drkbnrxa3.onion/contact'
+ headers = {
+ 'User-Agent': settings.USER_AGENT,
+ }
+ try:
+ data = json.dumps(data).encode()
+ opener = tor_request.get_opener()
+ opener.addheaders = list(zip(headers.keys(), headers.values()))
+ r = opener.open(url, data)
+ error = r.status != 200
+ except:
+ logger.debug('failed to send contact', exc_info=True)
+ error = True
+ if error:
+ response = {'error': True}
+ return response
+actions.register(contact, cache=False)
diff --git a/static/js/contactForm.js b/static/js/contactForm.js
index 06dc17b..16b743f 100644
--- a/static/js/contactForm.js
+++ b/static/js/contactForm.js
@@ -96,6 +96,12 @@ oml.ui.contactForm = function() {
subject: data.subject,
message: data.message,
}, function(result) {
+ var title = Ox._('Message Sent'),
+ content = Ox._('Thanks for your message!
We will get back to you as soon as possible.');
+ if (result.error) {
+ title = Ox._('Error');
+ content = Ox._('Sorry. There was an error sending your message. Please try again later.');
+ }
var $dialog = oml.ui.iconDialog({
buttons: [
Ox.Button({
@@ -104,13 +110,15 @@ oml.ui.contactForm = function() {
}).bindEvent({
click: function() {
$dialog.close();
- $form.values({subject: '', message: ''});
+ if (!result.error) {
+ $form.values({subject: '', message: ''});
+ }
}
})
],
- content: Ox._('Thanks for your message!
We will get back to you as soon as possible.'),
+ content: content,
keys: {enter: 'close', escape: 'close'},
- title: Ox._('Message Sent')
+ title: title
})
.open();
$sendButton.options({