Esempio n. 1
0
def sign_in():
    email = request.form["email"]
    password = request.form["password"]
    if '@' in email :
        userdata = database_helper.get_user_by_email(email)
        if userdata != None and userdata[6] == password :
            ws = websockets.get(email, None)
            if ws != None :
                if not ws["websocket"].closed :
                    ws["websocket"].send(json.dumps({"messagetype": "forcedLogout", "message": "Forced logout: User signed in from other location."}))
                    websockets[email]['websocket'].close(1000, "Another user logged in")
                database_helper.remove_active(database_helper.get_active_by_email(email))
                #del websockets[email]
                
            if database_helper.get_active_by_email(email) != None :
                database_helper.remove_active_by_email(email)
                
            print "sign_in(): Generating token."
            token = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(36))
            success = database_helper.add_active(token, email)
            print "sign_in(): database_helper.add_active(token, email) = " + str(success)
            if success == True :
                update_user_count()
                return json.dumps({"success": True, "message": "Successfully signed in.", "data": token})
    return json.dumps({"success": False, "message": "Wrong username or password."})
Esempio n. 2
0
def sign_in():
    email = request.form["email"]
    password = request.form["password"]
    if '@' in email:
        userdata = database_helper.get_user_by_email(email)
        if userdata != None and userdata[6] == password:
            ws = websockets.get(email, None)
            if ws != None:
                if not ws["websocket"].closed:
                    ws["websocket"].send(
                        json.dumps({
                            "messagetype":
                            "forcedLogout",
                            "message":
                            "Forced logout: User signed in from other location."
                        }))
                    websockets[email]['websocket'].close(
                        1000, "Another user logged in")
                database_helper.remove_active(
                    database_helper.get_active_by_email(email))
                #del websockets[email]

            if database_helper.get_active_by_email(email) != None:
                database_helper.remove_active_by_email(email)

            print "sign_in(): Generating token."
            token = ''.join(
                random.choice(string.ascii_letters + string.digits)
                for _ in range(36))
            success = database_helper.add_active(token, email)
            print "sign_in(): database_helper.add_active(token, email) = " + str(
                success)
            if success == True:
                update_user_count()
                return json.dumps({
                    "success": True,
                    "message": "Successfully signed in.",
                    "data": token
                })
    return json.dumps({
        "success": False,
        "message": "Wrong username or password."
    })
def sign_out(token):
    ret = database_helper.remove_active(token)
    if ret:
        return json.dumps({
            "success": True,
            "message": "Successfully signed out."
        })
    else:
        return json.dumps({
            "success": False,
            "message": "You are not signed in."
        })
Esempio n. 4
0
def sign_out():
    token = request.form["token"]
    email = database_helper.get_active(token)
    ret = database_helper.remove_active(token)
    
    if email != None :
        if websockets.get(email, None) != None :
            websockets[email]['websocket'].close(1000, "You've signed out")
        if ret :
            update_user_count()
            return json.dumps ({"success": True, "message": "Successfully signed out."})
    else :
        return json.dumps ({"success": False, "message": "You are not signed in."})
Esempio n. 5
0
def sign_out(token):
    email = database_helper.get_active(token)
    ret = database_helper.remove_active(token)
    
    if email != None :
        if websockets.get(email, None) != None :
            print "sign_out(): releasing sema for [" + email + "]"
            websockets[email].sema.release()
            del websockets[email]
        if ret :
            return json.dumps ({"success": True, "message": "Successfully signed out."})
    else :
        return json.dumps ({"success": False, "message": "You are not signed in."})
Esempio n. 6
0
def sign_in(email, password):
    if '@' in email :
        userdata = database_helper.get_user_by_email(email)
        if userdata != None and userdata[6] == password :
            ws = websockets.get(email, None)
            if ws != None :
                ws["websocket"].send(json.dumps({"messagetype": "forcedLogout", "message": "Forced logout: User signed in from other location."}))
                database_helper.remove_active(database_helper.get_active_by_email(email))
                print "sign_in(): releasing sema for [" + email + "]"
                ws["sema"].release()
                del websockets[email]
                
            if database_helper.get_active_by_email(email) != None :
                database_helper.remove_active_by_email(email)
                
            print "sign_in(): Generating token."
            token = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(36))
            success = database_helper.add_active(token, email)
            print "sign_in(): database_helper.add_active(token, email) = " + str(success)
            if success == True :
                return json.dumps({"success": True, "message": "Successfully signed in.", "data": token})
    return json.dumps({"success": False, "message": "Wrong username or password."})
Esempio n. 7
0
def sign_out():
    token = request.form["token"]
    email = database_helper.get_active(token)
    ret = database_helper.remove_active(token)

    if email != None:
        if websockets.get(email, None) != None:
            websockets[email]['websocket'].close(1000, "You've signed out")
        if ret:
            update_user_count()
            return json.dumps({
                "success": True,
                "message": "Successfully signed out."
            })
    else:
        return json.dumps({
            "success": False,
            "message": "You are not signed in."
        })
def sign_out(token):
    ret = database_helper.remove_active(token)
    if ret :
        return json.dumps ({"success": True, "message": "Successfully signed out."})
    else :
        return json.dumps ({"success": False, "message": "You are not signed in."})