Exemple #1
0
def postMessage():
    if request.method == 'POST':
        token = request.form['token']
        content = request.form['content']
        toEmail = request.form['toEmail']

        if database_helper.userSignedIn(token):
            if database_helper.userExists(toEmail):
                if database_helper.postMessage(token, content, toEmail):
                    print "userviewing dict: " + str(usersViewing)
                    for user in usersViewing:  # fix this for later
                        #print "usersviewing[user]: " + str(usersViewing[user])
                        #if usersViewing[user] == toEmail:
                        print "getting: " + str(wsDict.get(user))
                        wsDict.get(user).send("updateWall")
                    return json.dumps({
                        "success": True,
                        "message": "Message posted."
                    })
                else:
                    return json.dumps({
                        "success": False,
                        "message": "Failed to post message"
                    })
            else:
                return json.dumps({
                    "success": False,
                    "message": "Nu such user."
                })
        else:
            return json.dumps({
                "success": False,
                "message": "You are not signed in"
            })
Exemple #2
0
def getUserData(token, userEmail):
    if database_helper.userSignedIn(token):
        if database_helper.userExists(userEmail):
            currentEmail = database_helper.getEmail(token)
            if not currentEmail == userEmail:
                print "inte samma så ökar"
                database_helper.incrementViews(userEmail)
            print "wsdict: " + str(wsDict)
            print "userviewdict : " + str(usersViewing)
            for user in usersViewing:
                wsDict.get(user).send("updateWall")
            userData = database_helper.getUserData(userEmail)
            usersViewing[currentEmail] = userEmail
            return json.dumps({
                "success": True,
                "message": "User data retrieved.",
                "data": userData
            })
        else:
            return json.dumps({"success": False, "message": "Nu such user."})
    else:
        return json.dumps({
            "success": False,
            "message": "You are not signed in."
        })
Exemple #3
0
def postMessage():
    if request.method == 'POST':
        token = request.form['token']
        content = request.form['content']
        toEmail = request.form['toEmail']

        if database_helper.userSignedIn(token):
            if database_helper.userExists(toEmail):
                if database_helper.postMessage(token, content, toEmail):
                    return json.dumps({
                        "success": True,
                        "message": "Message posted."
                    })
                else:
                    return json.dumps({
                        "success": False,
                        "message": "Failed to post message"
                    })
            else:
                return json.dumps({
                    "success": False,
                    "message": "Nu such user."
                })
        else:
            return json.dumps({
                "success": False,
                "message": "You are not signed in"
            })
Exemple #4
0
def generateToken():
    letters = "abcdefghiklmnopqrstuvwwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
    token = ''.join(random.choice(letters) for _ in range(len(str(letters))))
    if not database_helper.userSignedIn(token):
        return token
    else:
        print "Token already exists. Re-generating..."
        return generateToken()
Exemple #5
0
def getMessages(token, userEmail):
    if database_helper.userSignedIn(token):
        if database_helper.userExists(userEmail):
            messages = database_helper.getMessages(userEmail)
            return json.dumps({
                "success": True,
                "message": "User messages retrieved.",
                "data": messages
            })
        else:
            return json.dumps({"success": False, "message": "Nu such user."})
    else:
        return json.dumps({
            "success": False,
            "message": "You are not signed in."
        })
Exemple #6
0
def getUserData(token, userEmail):
    if database_helper.userSignedIn(token):
        if database_helper.userExists(userEmail):
            userData = database_helper.getUserData(userEmail)
            return json.dumps({
                "Success": True,
                "message": "User data retrieved.",
                "data": userData
            })
        else:
            return json.dumps({"Success": False, "message": "Nu such user."})
    else:
        return json.dumps({
            "Success": False,
            "message": "You are not signed in."
        })
Exemple #7
0
def signIn():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        if database_helper.checkPassword(email, password):
            token = generateToken()
            if database_helper.userSignedIn(token):
                print "duplicate users!!!"
            database_helper.signInUser(token, email)
            updateCounter()
            print "updateCounter() was run"
            return json.dumps({
                "success": True,
                "message": "Successfully signed in.",
                "data": token
            })
        else:
            return json.dumps({
                "success": False,
                "message": "Wrong username or password."
            })