Esempio n. 1
0
 def __init__(self, ip, port, clientSocket):
     threading.Thread.__init__(self)
     self.user = User("", ip, port)
     self.ip = ip
     self.port = port
     self.clientSocket = clientSocket
     print("[+] New Get Thread started for " + ip + ":" + str(port))
Esempio n. 2
0
 def __init__(self,ip,port,clientSocket):
     threading.Thread.__init__(self)
     self.user = User("",ip,port)
     self.ip = ip
     self.port = port
     self.clientSocket = clientSocket
     print ("[+] New Get Thread started for "+ip + ":"+str(port))
Esempio n. 3
0
def registerAPI():
    user = User.ParseRegistrationForm(request.form)
    if user.registerUser() == "1":
        return redirect(url_for('.registerPage', error=1))
    if user.registerUser() == "2":
        return redirect(url_for('.registerPage', error=2))
    return redirect(url_for('.loginPage'))
Esempio n. 4
0
def setUserCardID():
    if not IsAuthenticated():
        return "Not authorised", 401
    cardID = request.form.get("cardID")
    userID = session['UserId']
    if cardID == "" or cardID == None:
        return "Error, A card ID cannot be blank", 400
    result = User.addCardId(cardID, userID)
    if result == False:
        return "Error, A card with this ID already exists", 400
    return "success"
Esempio n. 5
0
def loginAPI():
    user = User.ParseFromForm(request.form)
    if not user.IsValid():
        return redirect(url_for('.loginPage', error=1))
    elif not user.TryLogin():
        return redirect(url_for('.loginPage', error=1))
    session['UserId'] = user.Id
    session['Username'] = user.Username
    session['IsAdmin'] = user.IsAdmin()
    return redirect(url_for('.dashboardPage')) if user.IsAdmin() else redirect(
        url_for('.publicDashBoardPage'))
Esempio n. 6
0
 def __init__(self, **kwargs):
     self.Id = int(kwargs.get('Id', 0))
     self.RoomId = int(kwargs.get('RoomId', 0))
     self.UserId = int(kwargs.get('UserId', 0))
     if self.RoomId > 0:
         self.room = Room.TryGetRoomById(self.RoomId)
     else:
         self.room = None
     if self.UserId > 0:
         self.user = User.TryGetUserById(self.UserId)
     else:
         self.user = None
Esempio n. 7
0
class ClientThread(threading.Thread):
    def __init__(self, ip, port, clientSocket):
        threading.Thread.__init__(self)
        self.user = User("", ip, port)
        self.ip = ip
        self.port = port
        self.clientSocket = clientSocket
        print("[+] New Get Thread started for " + ip + ":" + str(port))

    def checkUser(self, userName):
        findUser = False
        for us in AllSignInUsers:
            if (us == self.user.userName):
                findUser = True
                break
        return findUser

    def parseInput(self, data):
        if (not data[0:5] <> 'ISNUP') and (self.checkUser(data[5:10])):
            response = "LGINR"
            self.clientSocket.sendall(response)
            return False

        response = ""
        if data[0:5] == 'ISNUP':
            userName = data[5:10]
            self.user.setUserName(userName)
            AllSignInUsers.append(userName)
            response = "SNUPA" + userName
            print 'User Sign Up'
        if data[0:5] == 'ILGIN':
            response = "LGINA"
            #response = "LGINR"
            print 'User Login'
        if data[0:5] == 'ILGOT':
            response = "LGOTA"
            userName = data[5:10]
            AllSignInUsers.remove(userName)
            print 'User Log out'
        if data[0:5] == 'ILSTM':
            response = "LSTMI"
            print 'List Tombala Sessions'
        if data[0:5] == 'IJNTM':
            if (requestSessionUsers.count() > 6):
                response = "JNTMR"
            else:
                response = "JNTMA"
                requestSessionUsers.append(self.user)
            #response = "JNTMR"
            print 'Join a Tombala Session'
        if data[0:5] == 'ICRTM':
            if (requestSessionUsers.count() == 0):
                response = "CRTMA"
                requestSessionUsers.append(self.user)
            else:
                response = "CRTMR"
            #response = "CRTMR"
            print 'Create a Tombala Session'
        if data[0:5] == 'IANCN':
            response = "ANCNA"
            cinkoNumber = data[5:3]
            if cinkoNumber < 1 or cinkoNumber > 3:
                response = "ERRRR"
            else:
                if self.user.ticket.checkCinko(cinkoNumber):
                    #response = "ANCNA"
                    response = ""
                    broadCastCinko(self.user.userName, cinkoNumber)
                else:
                    response = "ANCNR"
            #response = "ANCNR"
            #+check Cinko
            #+2.response is IBRCN username cinkonumber
            print 'Announce Cinko'
        if data[0:5] == 'IANTM':
            tombalaMi = True
            if (self.user.ticket.checkTombala()):
                #response = "ANTMA"
                response = ""
                broadCastTombala(self.user.userName)
            else:
                response = "ANTMR"
            #response = "ANTMR"
            #+check Tombala
            #+2.response is IBRTM username
            #+3.response is IGMFN username
            print 'Say Tombala'
        if data[0:5] == 'ANNMA':
            self.user.setLastNumberApproved(True)
            response = ""
            #in a timer event every 5 miniute, if all user lastNumberApproved is True, then generate a new number
            #            number = generateNumber()
            #            broadCastNumber(number)
            #            print "generate new number"
            print "Announced Number Approved"
        print response
        if (response <> ""):
            self.clientSocket.sendall(response)
            #+User and User Info List

    def run(self):
        while True:
            data = self.clientSocket.recv(1024)
            print data
            if not data:
                break
            self.parseInput(data)
Esempio n. 8
0
            print "Announced Tombala"
        if data[0:5] == "IRQGM":
            out_message = "IRQGM"
            print "Request Tombala Session Card Status"
        if out_message <> "":
            self.sendQueue.put(str(out_message))


sendQueue = Queue.Queue()
screenQueue = Queue.Queue()

s = socket.socket()
host = socket.gethostname()
port = 12345

user = User("", host, port)

s.connect((host, port))

app = ClientDialog(sendQueue, screenQueue, user)

rt = ReadThread("ReadThread", s, screenQueue, app)
wt = WriteThread("WriteThread", s, sendQueue, screenQueue)

rt.start()
wt.start()

app.run()

rt.join()
wt.join()
Esempio n. 9
0
class ClientThread(threading.Thread):
    def __init__(self,ip,port,clientSocket):
        threading.Thread.__init__(self)
        self.user = User("",ip,port)
        self.ip = ip
        self.port = port
        self.clientSocket = clientSocket
        print ("[+] New Get Thread started for "+ip + ":"+str(port))

    def checkUser(self,userName):
        findUser = False
        for us in AllSignInUsers:
            if (us == self.user.userName):
                findUser = True
                break
        return findUser

    def parseInput(self,data):
        if (not data[0:5] <> 'ISNUP') and (self.checkUser(data[5:10])):
            response = "LGINR"
            self.clientSocket.sendall(response)
            return False

        response = ""
        if data[0:5] == 'ISNUP':
            userName = data[5:10]
            self.user.setUserName(userName)
            AllSignInUsers.append(userName)
            response = "SNUPA" + userName
            print 'User Sign Up'
        if data[0:5] == 'ILGIN':
            response = "LGINA"
            #response = "LGINR"
            print 'User Login'
        if data[0:5] == 'ILGOT':
            response = "LGOTA"
            userName = data[5:10]
            AllSignInUsers.remove(userName)
            print 'User Log out'
        if data[0:5] == 'ILSTM':
            response = "LSTMI"
            print 'List Tombala Sessions'
        if data[0:5] == 'IJNTM':
            if (requestSessionUsers.count() > 6):
                response = "JNTMR"
            else:
                response = "JNTMA"
                requestSessionUsers.append(self.user)
            #response = "JNTMR"
            print 'Join a Tombala Session'
        if data[0:5] == 'ICRTM':
            if (requestSessionUsers.count() == 0):
                response = "CRTMA"
                requestSessionUsers.append(self.user)
            else:
                response = "CRTMR"
            #response = "CRTMR"
            print 'Create a Tombala Session'
        if data[0:5] == 'IANCN':
            response = "ANCNA"
            cinkoNumber = data[5:3]
            if cinkoNumber < 1 or cinkoNumber > 3:
                response = "ERRRR"
            else:
                if self.user.ticket.checkCinko(cinkoNumber):
                    #response = "ANCNA"
                    response = ""
                    broadCastCinko(self.user.userName,cinkoNumber)
                else:
                    response = "ANCNR"
            #response = "ANCNR"
            #+check Cinko
            #+2.response is IBRCN username cinkonumber
            print 'Announce Cinko'
        if data[0:5] == 'IANTM':
            tombalaMi = True
            if (self.user.ticket.checkTombala()):
                #response = "ANTMA"
                response = ""
                broadCastTombala(self.user.userName)
            else:
                response = "ANTMR"
            #response = "ANTMR"
            #+check Tombala
            #+2.response is IBRTM username
            #+3.response is IGMFN username
            print 'Say Tombala'
        if data[0:5] == 'ANNMA':
            self.user.setLastNumberApproved(True)
            response = ""
            #in a timer event every 5 miniute, if all user lastNumberApproved is True, then generate a new number
#            number = generateNumber()
#            broadCastNumber(number)
#            print "generate new number"
            print "Announced Number Approved"
        print response
        if (response <> ""):
            self.clientSocket.sendall(response)
            #+User and User Info List

    def run(self):
        while True:
            data = self.clientSocket.recv(1024)
            print data
            if not data:
                break
            self.parseInput(data)
Esempio n. 10
0
def ShowWelcomeMsg():
	lcd.clear()
	lcd.text("Welcome {}".format(access_right.user.Username),1)

#---------------------------------------------------------------------------------

ShowDefault()

while continue_reading:
	(status,TagType) = mfrc522.MFRC522_Request(mfrc522.PICC_REQIDL)
	if status == mfrc522.MI_OK:
		(status,uid) = mfrc522.MFRC522_Anticoll()
		print("New card detected! UID of card is {}".format(uid))
		if access_right == None:
			access_user = User.TryGetUserByCardId(uid)
			if access_user != None:
				access_right = AccessRight(RoomId = room.Id,UserId = access_user.Id)
				if not access_right.HasAccessRight():
					access_right = None
			md.DisarmDetector = access_right != None
			lcd.clear()
			if access_right == None:
				lcd.text("Card rejected!",1)
				lcd.text("Please try again!",2)
				if access_user != None:
					Invalid_al = AccessLog(RoomId = room.Id,UserId = access_user.Id,IsValid = False)
					Invalid_al.TryAdd()
				sleep(3)
				ShowDefault()
			else:
Esempio n. 11
0
def roomAccessRightsPage():
    return redirectIfNotLoginAndRender('room_access_rights.html',
                                       users=User.GetUsers(),
                                       rooms=Room.GetAllRooms())
Esempio n. 12
0
def publicDashBoardPage():
    return redirectIfNotLoginAndRender(
        'publicDashboard.html',
        user=User.TryGetUserById(session['UserId']),
        rooms=Room.GetAllRooms()) if not session['IsAdmin'] else redirect(
            url_for('.dashboardPage'))
Esempio n. 13
0
def manageApprovalsPage():
    return redirectIfNotLoginAndRender('manage_approvals.html',
                                       users=User.GetUsers(),
                                       rooms=Room.GetAllRooms())