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_in(email, password):
    if '@' in email :
        userdata = database_helper.get_user_by_email(email)
        if userdata != None and userdata[6] == password :
            token = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(36))
            success = database_helper.add_active(token, email)
            if success == True :
                return json.dumps({"success": True, "message": "Successfully signed in.", "data": token})
    return json.dumps({"success": False, "message": "Wrong username or password."})
def sign_in(email, password):
    if '@' in email:
        userdata = database_helper.get_user_by_email(email)
        if userdata != None and userdata[6] == password:
            token = ''.join(
                random.choice(string.ascii_letters + string.digits)
                for _ in range(36))
            success = database_helper.add_active(token, email)
            if success == True:
                return json.dumps({
                    "success": True,
                    "message": "Successfully signed in.",
                    "data": token
                })
    return json.dumps({
        "success": False,
        "message": "Wrong username or password."
    })
Exemple #4
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."
    })
Exemple #5
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."})