Beispiel #1
0
def upload_wordbook(environ):
    dict_from_client = parse_qs(getRequestBody(environ))
    username = dict_from_client['username'][0]
    password = dict_from_client['password'][0]

    dict_for_return = dict(universal_POST_dict)
    if not verifyLogin(username, password):
        dict_for_return['verified'] = False
        dict_for_return['message_str'] = "login failed"
        json_for_return = json.dumps(dict_for_return)
        return json_for_return
    else:
        rows = dict_from_client['wordbook'][0]
        rows = json.loads(rows)
        dbMgr = MmrzSyncDBManager(username)
        dbMgr.createDB()
        dbMgr.pruneDB()
        for row in rows:
            dbMgr.insertDB(row)
        dbMgr.closeDB()

        dict_for_return['verified'] = True
        dict_for_return['message_str'] = "upload done"
        json_for_return = json.dumps(dict_for_return)
        return json_for_return
Beispiel #2
0
def application(environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    write = start_response(status, response_headers)

    dbMgr = MmrzSyncDBManager("USERS")
    dbMgr.create_USERS_DB()
    dbMgr.closeDB()

    path   = environ['PATH_INFO'].replace("/", "")
    method = environ['REQUEST_METHOD']
    params = parse_qs(environ['QUERY_STRING'])

    if method == 'POST':
        post_thing = params.get('post_thing', [0])[0]

        if path == "log_in":
            return log_in(environ)

        if path == "sign_up":
            return sign_up(environ)

        if path == "upload_wordbook":
            return upload_wordbook(environ)

        return json.dumps(universal_POST_dict)

    if method == 'GET':
        req_thing = params.get('req_thing', [0])[0]

        if req_thing == 'version_info':
            return version_info(environ)

        if path == "version_info":
            return version_info(environ)

        if path == "database_info":
            return database_info(environ)

        if path == "download_wordbook":
            return download_wordbook(environ)

        return json.dumps("nothing here")

    return "End of POST/GET"
Beispiel #3
0
def sign_up(environ):
    dict_from_client = parse_qs(getRequestBody(environ))
    username = dict_from_client['username'][0]
    password = dict_from_client['password'][0]

    dict_for_return = dict(universal_POST_dict)
    if isUserNameAvailable(username):
        dbMgr = MmrzSyncDBManager("USERS")
        dbMgr.insert_USERS_DB([username, password])
        dbMgr.closeDB()
        dict_for_return['verified'] = True
        dict_for_return['message_str'] = "Signed up"
    else:
        dict_for_return['verified'] = False
        dict_for_return['message_str'] = "Username not available"

    json_for_return = json.dumps(dict_for_return)
    return json_for_return
Beispiel #4
0
def verifyLogin(username, password):
    dbMgr = MmrzSyncDBManager("USERS")
    users = dict(dbMgr.read_USERS_DB())
    dbMgr.closeDB()
    
    return username in users and password == users[username]
Beispiel #5
0
def isUserNameAvailable(username):
    dbMgr = MmrzSyncDBManager("USERS")
    users = dict(dbMgr.read_USERS_DB())
    dbMgr.closeDB()

    return not username in users
Beispiel #6
0
def database_info(environ):
    dbMgr = MmrzSyncDBManager("wordbook")
    rows = dbMgr.readAllDB()
    dbMgr.closeDB()

    return json.dumps(rows)