コード例 #1
0
ファイル: taskLib.py プロジェクト: sudhir512kj/cuntoir
def completeTask(dataDict):
    username = dataDict["username"].strip()
    authCode = dataDict["authCode"].strip()
    taskId = dataDict["id"]
    doneFlag = dataDict["done"]
    if (authLib.checkAuthCode({
            "username": username,
            "authCode": authCode
    }) != 1):
        return (0)
    if (authLib.checkIfPremium(username) != 1):
        return (deleteTask(dataDict))
    db = authLib.dbCon()
    c = db.cursor()
    recurring = getRecurring(taskId)
    if (recurring == 0):
        command = "UPDATE tasks SET done = %s, pushScheduled = 'false' WHERE BINARY username = %s AND id = %s"
        c.execute(command, [doneFlag, username, taskId])
    else:
        recurringTime = recurring
        command = "UPDATE tasks SET dueTime = dueTime + %s, pushScheduled = 'false' WHERE BINARY username = %s AND id = %s"
        c.execute(command, [recurringTime, username, taskId])
    db.commit()
    db.close()
    if (doneFlag == "true"):
        pushLib.completePush(username, taskId)
    return (1)
コード例 #2
0
ファイル: taskLib.py プロジェクト: sudhir512kj/cuntoir
def updatePushable(dataDict):
    username = dataDict["username"]
    taskId = dataDict["id"]
    pushable = "true"
    if (dataDict["pushable"] == "true"):
        pushable = "false"
    if (authLib.checkAuthCode(dataDict) != 1):
        return 0
    if (pushLib.checkPushSubscribed(username) != 1):
        return 2
    if (pushable == "true"):
        db = authLib.dbCon()
        c = db.cursor()
        command = "SELECT title, dueTime FROM tasks WHERE BINARY username = %s AND id = %s"
        c.execute(command, [username, taskId])
        taskInfo = c.fetchall()[0]
        pushLib.schedulePush({
            "username": username,
            "id": taskId,
            "title": taskInfo[0],
            "dueTime": taskInfo[1]
        })
        return 1
    else:
        pushLib.completePush(username, taskId)
        return 1
コード例 #3
0
def clientDeleteCustomer(dataDict):
    username = dataDict["username"]
    if (authLib.checkAuthCode(dataDict) == 0):
        return (0)
    if (authLib.checkIfPremium(username) == 0):
        return (2)
    customerInfo = getCustomerInfo(username)
    stripeId = customerInfo[1]
    print(
        deleteCustomer(username, stripeId, "You're unsubscribed",
                       "Sorry to see you go."))
    return (1)
コード例 #4
0
ファイル: taskLib.py プロジェクト: sudhir512kj/cuntoir
def addTask(dataDict):
    username = dataDict["username"].strip()
    authCode = dataDict["authCode"].strip()
    if (authLib.checkAuthCode({
            "username": username,
            "authCode": authCode
    }) != 1):
        return (0)
    if (dataDict["recurring"] not in [
            "false", "daily", "weekly", "monthly", "quarterly", "yearly"
    ]):
        return (2)
    if (dataDict["recurring"] != "false"
            and authLib.checkIfPremium(username) != 1):
        return (3)
    createTime = str(time.time())
    dataDict["createTime"] = createTime
    dueTime = dataDict["dueTime"]
    description = dataDict["description"].strip()
    done = "false"
    title = dataDict["title"].strip()
    tags = dataDict["tags"]
    hoursBefore = int(dataDict["hoursBefore"])
    recurring = dataDict["recurring"]
    if (pushLib.checkPushSubscribed(username) == 1):
        pushable = dataDict["pushable"]
    else:
        pushable = "false"
    tagString = ""
    for tag in tags.split(","):
        if (tag == ""):
            continue
        tagString += tag.strip() + ","
    tagString = tagString[:-1]
    db = authLib.dbCon()
    c = db.cursor()
    command = "INSERT INTO tasks (username, createTime, dueTime, text, done, title, tags, pushScheduled, notificationHours, recurring) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
    c.execute(command, [
        username, createTime, dueTime, description, done, title, tagString,
        pushable, hoursBefore, recurring
    ])
    db.commit()
    db.close()
    db = authLib.dbCon()
    c = db.cursor()
    command = "SELECT id FROM tasks WHERE BINARY username = %s AND createTime = %s"
    c.execute(command, [username, createTime])
    dataDict["id"] = c.fetchall()[0][0]
    if (pushable == "true" and pushLib.checkPushSubscribed(username) == 1):
        pushLib.schedulePush(dataDict)
    return (1)
コード例 #5
0
ファイル: taskLib.py プロジェクト: sudhir512kj/cuntoir
def deleteTask(dataDict):
    username = dataDict["username"].strip()
    authCode = dataDict["authCode"].strip()
    taskId = dataDict["id"]
    if (authLib.checkAuthCode(dataDict) != 1):
        return (0)
    db = authLib.dbCon()
    c = db.cursor()
    command = "DELETE FROM tasks WHERE BINARY username = %s AND id = %s"
    c.execute(command, [username, taskId])
    db.commit()
    db.close()
    pushLib.completePush(username, taskId)
    return (1)
コード例 #6
0
def createCustomer(dataDict):
    username = dataDict["username"]
    if (authLib.checkAuthCode(dataDict) == 0):
        return (0)
    if (authLib.checkIfPremium(username) == 1):
        return (2)
    stripe.api_key = getKey()
    token = dataDict["token"]
    email = dataDict["email"]
    try:
        customer = stripe.Customer.create(description="New Customer",
                                          email=email,
                                          source=token)
        customerId = customer["id"]
        subscription = subscribeCustomer(customerId, username)
    except stripe.error.CardError as e:
        body = e.json_body
        err = body["error"]
        print(err)
        print("HTTP status is: " + str(e.http_status))
        print("Type is: " + str(err["type"]))
        print("Code is: " + str(err["code"]))
        print("Message is: " + str(err["message"]))
        print("Param is: " + str(err["param"]))
        print("Attempting to delete unusable customer")
        try:
            customer.delete()
            print("Customer deleted successfully")
        except:
            print(
                "Customer delete failed, as customer creation failed earlier")
        return (err["message"])
    except:
        return (4)
    db = authLib.dbCon()
    c = db.cursor()
    subId = subscription["id"]
    command = "INSERT INTO stripe (stripeId, email, username, subId) VALUES (%s, %s, %s, %s);"
    c.execute(command, [customerId, email, username, subId])
    db.commit()
    db.close()
    authLib.upgradeToPremium(username)
    taskLib.notifyUser(
        username, "Thanks for Subscribing!",
        "Premium features like archive and push notifications are now available, look for them in the menu"
    )
    return (1)
コード例 #7
0
ファイル: taskLib.py プロジェクト: sudhir512kj/cuntoir
def editTask(dataDict):
    username = dataDict["username"]
    authCode = dataDict["authCode"]
    title = dataDict["title"].strip()
    dueTime = str(dataDict["dueTime"])
    taskId = str(dataDict["id"])
    text = dataDict["description"].strip()
    tags = dataDict["tags"]
    hoursBefore = int(dataDict["hoursBefore"])
    recurring = dataDict["recurring"]
    if (pushLib.checkPushSubscribed(username)):
        pushable = dataDict["pushable"]
    else:
        pushable = "false"
    tagString = ""
    for tag in tags.split(","):
        if (tag == ""):
            continue
        tagString += tag.strip() + ","
    tagString = tagString[:-1]
    if (authLib.checkAuthCode({
            "username": username,
            "authCode": authCode
    }) != 1):
        return (0)
    if (dataDict["recurring"] not in [
            "false", "daily", "weekly", "monthly", "quarterly", "yearly"
    ]):
        return (2)
    if (dataDict["recurring"] != "false"
            and authLib.checkIfPremium(username) != 1):
        return (3)
    db = authLib.dbCon()
    c = db.cursor()
    command = "UPDATE tasks SET title = %s, text = %s, dueTime = %s, tags = %s, done = %s, pushScheduled = %s, notificationHours = %s, recurring = %s WHERE BINARY username = %s AND id = %s"
    c.execute(command, [
        title, text, dueTime, tagString, "false", pushable, hoursBefore,
        recurring, username, taskId
    ])
    db.commit()
    db.close()
    if (pushable == "true" and pushLib.checkPushSubscribed(username)):
        pushLib.schedulePush(dataDict)
    else:
        pushLib.completePush(username, taskId)
    return (1)
コード例 #8
0
ファイル: pushLib.py プロジェクト: sudhir512kj/cuntoir
def addSub(dataDict):
    username = dataDict["username"].strip()
    authCode = dataDict["authCode"].strip()
    if (authLib.checkAuthCode(dataDict) != 1):
        return (0)
    if (authLib.checkIfPremium(username) == 0):
        return (3)
    subInfo = dataDict["subInfo"]
    db = authLib.dbCon()
    c = db.cursor()
    command = "INSERT INTO pushInfo (username, subString, lastReturn) VALUES (%s, %s, %s);"
    c.execute(command, [username, subInfo, "201"])
    command = "UPDATE users SET sendPushes = %s WHERE BINARY username = %s;"
    c.execute(command, ["true", username])
    db.commit()
    db.close()
    return (1)
コード例 #9
0
ファイル: main.py プロジェクト: dfraser74/cuntoir
def handlePostRequest(dataDict):
    returnCode = 0
    for key in dataDict:
        dataDict[key] = dataDict[key].encode("utf-8")
    method = dataDict["method"]
    if (method == "login"):
        returnCode = authLib.createAuthCode(dataDict["username"],
                                            dataDict["userPass"])
    if (method == "createUser"):
        returnCode = authLib.createUser(dataDict)
    if (method == "authUser"):
        returnCode = authLib.checkAuthCode(dataDict)
    if (method == "addTask"):
        returnCode = taskLib.addTask(dataDict)
    if (method == "completeTask"):
        returnCode = taskLib.completeTask(dataDict)
    if (method == "getAll"):
        returnCode = getLib.getAll(dataDict)
    if (method == "editTask"):
        returnCode = taskLib.editTask(dataDict)
    if (method == "getTagged"):
        returnCode = getLib.getTagged(dataDict)
    if (method == "search"):
        returnCode = getLib.search(dataDict)
    if (method == "dateSearch"):
        returnCode = getLib.dateSearch(dataDict)
    if (method == "getTaskDates"):
        returnCode = getLib.getTaskDates(dataDict)
    if (method == "deleteTask"):
        returnCode = taskLib.deleteTask(dataDict)
    if (method == "changePass"):
        returnCode = authLib.changePass(dataDict)
    if (method == "updateSub"):
        returnCode = pushLib.addSub(dataDict)
    if (method == "createCustomer"):
        returnCode = stripeLib.createCustomer(dataDict)
    if (method == "checkPremium"):
        returnCode = authLib.clientCheckIfPremium(dataDict)
    if (method == "clientDeleteCustomer"):
        returnCode = stripeLib.clientDeleteCustomer(dataDict)
    if (method == "updatePushable"):
        returnCode = taskLib.updatePushable(dataDict)
    return (returnCode)
コード例 #10
0
ファイル: getLib.py プロジェクト: sudhir512kj/cuntoir
def getTaskDates(dataDict):
    username = dataDict["username"].strip()
    authCode = dataDict["authCode"].strip()
    sort = dataDict["sort"]
    month = int(dataDict["month"])
    year = int(dataDict["year"])
    auth = authLib.checkAuthCode(dataDict)
    if (auth != 1):
        return (0)
    db = authLib.dbCon()
    c = db.cursor()
    command = "SELECT dueTime FROM tasks WHERE BINARY username = %s AND BINARY done != %s"
    c.execute(command, [username, "true"])
    tasks = c.fetchall()
    tasks = list(tasks)
    returnString = str(month) + ";"
    for task in tasks:
        dueTime = task[0]
        dueTimeString = time.strftime("%d/%m/%Y", time.gmtime(dueTime))
        returnString += (dueTimeString + ",")
    db.close()
    returnString += ";" + str(year)
    return (returnString)
コード例 #11
0
ファイル: getLib.py プロジェクト: sudhir512kj/cuntoir
def getTagged(dataDict):
    username = dataDict["username"].strip()
    authCode = dataDict["authCode"].strip()
    searchTag = dataDict["tag"].strip()
    sort = dataDict["sort"]
    auth = authLib.checkAuthCode(dataDict)
    timeOffset = float(dataDict["timeOffset"])
    if (auth != 1):
        return (0)
    returnString = ""
    db = authLib.dbCon()
    c = db.cursor()
    command = "SELECT * FROM tasks WHERE BINARY username = %s AND BINARY done != %s"
    c.execute(command, [username, "true"])
    tasks = c.fetchall()
    tasks = list(tasks)
    for task in tasks:
        for item in task:
            if (type(item) == StringType):
                item = item.decode("utf-8")
    if (len(tasks) == 0):
        return (2)
    if (sort == "default"):
        tasks.sort(key=lambda x: x[3])
    infoString = "<div class='task' id='infoHeader' style='height:auto;width:auto;'><h2 class='taskTitle'>Tasks tagged with \"" + searchTag + "\" :</h2></div>"
    returnString += infoString
    for task in tasks:
        taskId = str(task[0])
        username = task[1]
        createTime = float(task[2])
        dueTime = float(task[3])
        text = task[4]
        title = task[6]
        tags = task[7]
        pushable = task[8]
        recurring = task[10]
        if (recurring == "false"):
            recurringString = ""
        else:
            recurringString = " <i class='fa fa-repeat' aria-hidden='true'></i>(" + recurring.title(
            ) + ")"
        if ("'" in title):
            title = title.replace("'", "&apos;")
        if ("'" in text):
            text = text.replace("'", "&apos;")
        if (searchTag not in tags.split(",")):
            continue
        if (task[5] == "true"):
            continue
        timeString = time.strftime("%d/%m/%Y %H:%M",
                                   time.gmtime(dueTime - timeOffset))
        dateSearchList = time.strftime(
            "%d/%m/%Y", time.gmtime(dueTime - float(timeOffset))).split("/")
        dateSearchList[1] = str(int(dateSearchList[1]) - 1)
        returnString += "<div class='task' id='" + taskId + "'><h2 class='taskTitle' onclick='openEdit(" + taskId + ");'>" + title + "</h2>"
        if (text != ""):
            returnString += "<div class='taskBody'>" + text + "</div>"
        else:
            returnString += "<div class='taskBody'><span class='italic'>No details</span></div>"
        returnString += "<div class='tagAndDueTimeWrapper'><div class='dueTime' onclick='dateSearch(" + dateSearchList[
            0] + "," + dateSearchList[1] + "," + dateSearchList[
                2] + ");'>" + timeString + recurringString
        returnString += "</div>"
        returnString += "<div class='taskTags'>"
        if (len(tags) < 1):
            returnString += "<span class='noTaskTag'><span class='italic'>No tags</span></span>"
        for tag in tags.split(","):
            if (tag == ""):
                continue
            returnString += "<span class='taskTag' onclick='getTagged(\"" + tag + "\");'>" + tag + "</span>"
        returnString += "</div></div>"
        if (pushable == "true"):
            returnString += "<button type='button' class='notificationToggle' onclick='updatePushable(" + taskId + ",\"true\");'><i class='fa fa-bell' aria-hidden='true'></i></button>"
        else:
            returnString += "<button type='button' class='notificationToggle' onclick='updatePushable(" + taskId + ",\"false\");'><i class='fa fa-bell-o' aria-hidden='true'></i></button>"
        returnString += "<button type='button' class='archiveButton' onclick='completeTaskPost(" + taskId + ");'><i class='fa fa-check-square-o' aria-hidden='true'></i></button>"
        returnString += "</div>"
    if (returnString == infoString):
        return (2)
    returnString += "<div class='task' id='infoFooter' style='height:auto;'><input type='button' id='archiveButton' onclick='getAll();' value='Go Back'></div>"
    return (returnString)
コード例 #12
0
ファイル: getLib.py プロジェクト: sudhir512kj/cuntoir
def getAll(dataDict):
    username = dataDict["username"].strip()
    authCode = dataDict["authCode"].strip()
    sort = dataDict["sort"]
    doneFlag = dataDict["archived"]
    timeOffset = dataDict["timeOffset"]
    if (doneFlag == "true" and authLib.checkIfPremium(username) == 0):
        return (3)
    if (doneFlag == "false"):
        buttonText = "<i class='fa fa-check-square-o' aria-hidden='true'></i>"
        buttonVal = "class='archiveButton'"
        onClick = "completeTaskPost"
    if (doneFlag == "true"):
        buttonText = "<i class='fa fa-reply' aria-hidden='true'></i>"
        buttonVal = "class='restoreButton'"
        onClick = "restoreTaskPost"
    auth = authLib.checkAuthCode(dataDict)
    if (auth != 1):
        return (0)
    returnString = ""
    db = authLib.dbCon()
    c = db.cursor()
    command = "SELECT * FROM tasks WHERE BINARY username = %s AND BINARY done = %s"
    c.execute(command, [username, doneFlag])
    tasks = c.fetchall()
    tasks = list(tasks)
    if (len(tasks) == 0):
        return (2)
    if (sort == "default"):
        tasks.sort(key=lambda x: x[3])
    if (sort == "createTime"):
        tasks.sort(key=lambda x: x[2], reverse=True)
    if (doneFlag == "true"):
        returnString += "<div class='task' style='height:auto;' id='infoHeader'><h2 style='margin:auto;'>Archived Tasks:</h2></div>"
    for task in tasks:
        #        print(task)
        taskId = str(task[0])
        username = task[1]
        createTime = float(task[2])
        dueTime = float(task[3])
        text = task[4]
        title = task[6]
        tags = task[7]
        pushable = task[8]
        recurring = task[10]
        if (recurring == "false"):
            recurringString = ""
        else:
            recurringString = " <i class='fa fa-repeat' aria-hidden='true'></i>(" + recurring.title(
            ) + ")"
        if ("'" in title):
            title = title.replace("'", "&apos;")
        if ("'" in text):
            text = text.replace("'", "&apos;")
        timeString = time.strftime("%d/%m/%Y %H:%M",
                                   time.gmtime(dueTime - float(timeOffset)))
        dateSearchList = time.strftime(
            "%d/%m/%Y", time.gmtime(dueTime - float(timeOffset))).split("/")
        dateSearchList[1] = str(int(dateSearchList[1]) - 1)
        returnString += "<div class='task' id='" + taskId + "'><h2 class='taskTitle' onclick='openEdit(" + taskId + ");'>" + title + "</h2>"
        if (text != ""):
            returnString += "<div class='taskBody'>" + text + "</div>"
        else:
            returnString += "<div class='taskBody'><span class='italic'>No details</span></div>"
        returnString += "<div class='tagAndDueTimeWrapper'><div class='dueTime' onclick='dateSearch(" + dateSearchList[
            0] + "," + dateSearchList[1] + "," + dateSearchList[
                2] + ");'>" + timeString + recurringString
        returnString += "</div>"
        returnString += "<div class='taskTags'>"
        if (len(tags) < 1):
            returnString += "<span class='noTaskTag'><span class='italic'>No tags</span></span>"
        for tag in tags.split(","):
            if (tag == ""):
                continue
            returnString += "<span class='taskTag' onclick='getTagged(\"" + tag + "\");'>" + tag + "</span>"
        returnString += "</div></div>"
        returnString += "<button type='button' " + buttonVal + " onclick='" + onClick + "(" + taskId + ");'>" + buttonText + "</button>"
        if (doneFlag == "true"):
            returnString += "<button type='button' class='deleteButton' onclick='deleteTask(" + taskId + ");'><i class='fa fa-times' aria-hidden='true'></i></button>"
        else:
            if (pushable == "true"):
                returnString += "<button type='button' class='notificationToggle' onclick='updatePushable(" + taskId + ",\"true\");'><i class='fa fa-bell' aria-hidden='true'></i></button>"
            else:
                returnString += "<button type='button' class='notificationToggle' onclick='updatePushable(" + taskId + ",\"false\");'><i class='fa fa-bell-o' aria-hidden='true'></i></button>"
        returnString += "</div>"
    if (doneFlag == "true"):
        returnString += "<div class='task' id='infoFooter' style='height:auto;'><input type='button' id='archiveButton' onclick='getAll();' value='Go Back'></div>"
    return (returnString)