You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

60 lines
1.7 KiB

'''
Created on 15.09.2010
@author: Sergey Morozov
'''
import sys, os, cgitb, urlparse, json
from wsgiref.util import application_uri
cgitb.enable()
serverdir = os.path.dirname(__file__)
sys.path.append(serverdir)
sys.path.append(serverdir + os.sep + 'include')
import config
from siphon import user
def application(environ, start_response):
urlBase = urlparse.urljoin(application_uri(environ), '.')
# Read post data
try:
post_length = int(environ['CONTENT_LENGTH'])
post = environ['wsgi.input'].read(post_length)
except KeyError:
post = None
# Parse query string
form = urlparse.parse_qs(environ['QUERY_STRING'], keep_blank_values = True)
try:
form['type'] = form['type'][0]
except KeyError:
form['type'] = None
try:
form['email'] = form['email'][0]
except KeyError:
form['email'] = None
try:
form['password'] = form['password'][0]
except KeyError:
form['password'] = None
u = user(form, post)
if u.status['retval'] == 0:
if form['type'] == 'get':
output = json.dumps(u.getUser())
elif form['type'] == 'set':
output = json.dumps(u.setUser())
elif form['type'] == 'signup':
output = json.dumps(u.signup())
elif form['type'] == 'forgot':
output = json.dumps(u.forgot(urlBase))
else:
output = json.dumps(u.unsupportedFunction())
else:
output = json.dumps(u.status)
status = '200 OK'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return([output])