Пример #1
0
    def createSessionHandle(self, data):

        print "create session: " + self.user
        db = DB_Accesser()
        location = db.Get_Location(data["BeaconState"])

        if db.Get_ActiveSessionFromLocal(
            {"localizationID":
             location["BeaconState"]["localizationID"]}) is not None:
            self.returnInsucess(CREATE_SESSION,
                                "Beacon already has session active...")
            return

        if (location == None):
            self.returnInsucess("No beacon with that ID exists...")

        if (location["BeaconState"]["state"] == "Occupied"):
            self.returnInsucess("There is already a session in that beacon..")

        session = {
            "s_begin": datetime.now().date(),
            "activeFlag": True,
            "localizationID": location["BeaconState"]["localizationID"],
            "s_type": data["SessionConfig"]["type"],
            "permissions": data["SessionConfig"]["permissions"],
            "s_name": data["SessionConfig"]["s_name"]
        }

        sessioninfo = db.Insert_Session(session)

        if sessioninfo == None:
            self.returnInsucess(CREATE_SESSION, "Beacon nonexisting...")
            return

        db.Insert_UserInSession({
            "email": self.user,
            "sessionID": sessioninfo["sessionID"]
        })
        db.Set_SessionAdmin({
            "email": self.user,
            "sessionID": sessioninfo["sessionID"]
        })

        self.sessionIDi = sessioninfo["sessionID"]
        self.updateUsers(sessioninfo["sessionID"])
        self.returnSuccess(CREATE_SESSION, sessioninfo)
        self.sendSharinfFrame(YOURNEWADMIN,
                              {"sessionID": sessioninfo["sessionID"]})
        return
Пример #2
0
    def joinSessionHandle(self, data):

        print "join session: " + self.user + " in session " + chr(
            data["sessionID"])
        db = DB_Accesser()
        sessionid = data["sessionID"]

        pubpriv = db.Get_Session({"sessionID": sessionid})
        pubpriv = pubpriv["SessionConfig"]["type"]

        if (pubpriv == PRIVATE):
            admin = db.Get_SessionAdmin({"sessionID": sessionid})
            admin = admin["email"]
            self.sendSharinfFrame(REQUESTJOINSESSION, {
                "sessionID": sessionid,
                "email": self.user
            },
                                  usr=admin)
            responseframe = self.getSharinfFrame(admin)

            if responseframe.data == INSUCESS:
                self.returnInsucess(JOIN_SESSION, "Administrar didnt accept")
                return

        result = db.Insert_UserInSession({
            "email": self.user,
            "sessionID": sessionid
        })

        if result is True:
            self.sessionIDi = sessionid
            self.updateUsers(sessionid)
            self.returnSuccess(JOIN_SESSION)
        else:
            self.returnInsucess(
                JOIN_SESSION,
                "It was not possible to join sesion probably beacause session does not exists or you are already there..."
            )

        return