Example #1
0
    def waitSerial(self):
        rd = self.serial.read(1)
        rd = array.array('B', rd)
        print rd
        if rd[0] == 0x01:
            #This is an auth/info request
            cksum = self.serial.read(4)
            userString = str(cksum)
            print userString
            print self.users
            if userString in self.users:
                print "Found user."
                self.users[userString]["bank"]  # use this to get the total.
                totalAmount = self.bank.getBalance(
                    self.users["userString"]["bank"])
                name = self.users[userString]["quest"]
                self.serial.write("X".encode("ascii"))  # success.
                self.serial.flush()
                print self.serial.read(1)
                tAmount = struct.pack(">I", totalAmount)[2:]
                self.serial.write(tAmount)  # success.
                self.serial.write(bytes([len(name)]))  # success.
                self.serial.write(name.encode("ascii"))
                self.serial.flush()
            else:
                print 'nfound'
                self.serial.write("Y".encode(
                    "ascii"))  # No such user, we should expect an auth.
                self.serial.flush()
                print self.serial.read(1)
        elif rd[0] == 0x02:  #new user
            #Read chksum
            cksum = self.serial.read(4)  # Read the 4 byte checksum
            userString = str(cksum)
            #self.users[userString]={'bank':"bla"} # we need an account number from the Bank module.
            print "Enrolled user with userString: " + userString
            lenQuest = self.serial.read(1)
            lenQuest = array.array('B', lenQuest)

            x = int(lenQuest[0])  # sent as byte.
            qID = self.serial.read(x)
            questUser = str(qID)
            self.users[userString] = getUser(questUser)
            #self.users[userString]["quest"]=questUser
            print "Quest " + questUser
            #Send an email, get real name.
            server = smtplib.SMTP('smtp.gmail.com:587')
            server.starttls()
            server.login(username, password)
            server.sendmail(
                fromaddr, questUser + '@uwaterloo.ca',
                "Welcome to the WatCoin bank! Your personalized destination address is "
                + self.bank.getAccountAddress(questUser) +
                ". Please reply to this email with your desired recepient address."
            )
            server.quit()

        elif rd[0] == 0x03:
            #withdraw money
            cksum = self.serial.read(4)  # Read the 4 byte checksum
            userString = str(cksum)
            bID = self.users[userString]["bank"]
            amount = self.serial.read(2)
            realAmount = struct.unpack(">H", amount)
            print "Sending " + str(int(realAmount[0])) + " from " + bID
            self.bank.transferCoins(str(int(realAmount[0])), bID,
                                    self.users[userString]["sendTo"])
        else:
            print "Dde"
            exit()
Example #2
0
		while digit!='#':
			while digit==None:
				digit=keypd.getKey()
			if digit=="#":
				break
			digit=str(digit)
			s.write(digit.encode("ASCII"))
			amt=amt+digit
			digit=None
			time.sleep(0.2)
		s.write("\r Withdraw:\n".encode("ASCII"))
		s.write(amt.encode("ASCII"))
		bnk.transferCoins(str(int(amt)),users[x]["bank"],users[x]["sendTo"])
		time.sleep(5)
	else:
		s.write("@".encode("ASCII"))
		questUser=s.readline()
		questUser=questUser.rstrip()
		users[x]=getUser(questUser)
		userMap[questUser]=x
		s.write("\rCheck your email\nfor instructions!\n")
		server = smtplib.SMTP('smtp.gmail.com:587')
		server.starttls()
		server.login(username,password)
		server.sendmail(fromaddr, questUser+'@uwaterloo.ca', "Welcome to the WatCoin bank! Your personalized destination address is "+bnk.getAccountAddress(questUser)+". Please reply to this email with your desired recepient address.")
		server.quit()
		time.sleep(2)

	# Bank steps.
	
Example #3
0
def waitSerial():
	global serialBoard
	global bnk
	global users
	global userMap
	rd=serialBoard.read(1)
	rd=array.array('B', rd)
	print rd
	if rd[0]==0x01:
		#This is an auth/info request
		cksum=serialBoard.read(4)
		userString=str(cksum)
		print userString
		print users
		if userString in users:
			print "Found user."
			users[userString]["bank"] # use this to get the total.
			totalAmount=bnk.getBalance(users[userString]["bank"])
			name=users[userString]["quest"]
			serialBoard.write("X".encode("ascii")) # success.
			serialBoard.flush()
			print serialBoard.read(1)
			tAmount=struct.pack(">I", totalAmount)[2:]
			serialBoard.write(tAmount) # success.
			serialBoard.write(bytes([len(name)])) # success.
			serialBoard.write(name.encode("ascii"));
			serialBoard.flush()
		else:
			print 'nfound'
			serialBoard.write("Y".encode("ascii")) # No such user, we should expect an auth.
			serialBoard.flush()
			print serialBoard.read(1)
	elif rd[0]==0x02: #new user
		#Read chksum
		cksum=serialBoard.read(4) # Read the 4 byte checksum
		userString=str(cksum)
		#users[userString]={'bank':"bla"} # we need an account number from the Bank module. 
		print "Enrolled user with userString: "+userString
		lenQuest = serialBoard.read(1)
		lenQuest = array.array('B', lenQuest)
		print "here"
		x=int(lenQuest[0]) # sent as byte.
		print x
		qID=serialBoard.read(x)
		print qID
		questUser=str(qID)
		users[userString]=getUser(questUser)
		userMap[questUser]=userString
		#users[userString]["quest"]=questUser
		print "Quest "+questUser
		#Send an email, get real name.
		server = smtplib.SMTP('smtp.gmail.com:587')
		server.starttls()
		server.login(username,password)
		server.sendmail(fromaddr, questUser+'@uwaterloo.ca', "Welcome to the WatCoin bank! Your personalized destination address is "+bnk.getAccountAddress(questUser)+". Please reply to this email with your desired recepient address.")
		server.quit()
	elif rd[0]==0x03:
		#withdraw money
		cksum=serialBoard.read(4) # Read the 4 byte checksum
		userString=str(cksum)
		bID=users[userString]["bank"]
		amount=serialBoard.read(2)
		realAmount=struct.unpack(">H", amount)
		print "Sending "+str(int(realAmount[0]))+" from " +bID
		bnk.transferCoins(str(int(realAmount[0])),bID,users[userString]["sendTo"])
	else:
		print "Dde"
		exit()
Example #4
0
            if digit == "#":
                break
            digit = str(digit)
            s.write(digit.encode("ASCII"))
            amt = amt + digit
            digit = None
            time.sleep(0.2)
        s.write("\r Withdraw:\n".encode("ASCII"))
        s.write(amt.encode("ASCII"))
        bnk.transferCoins(str(int(amt)), users[x]["bank"], users[x]["sendTo"])
        time.sleep(5)
    else:
        s.write("@".encode("ASCII"))
        questUser = s.readline()
        questUser = questUser.rstrip()
        users[x] = getUser(questUser)
        userMap[questUser] = x
        s.write("\rCheck your email\nfor instructions!\n")
        server = smtplib.SMTP('smtp.gmail.com:587')
        server.starttls()
        server.login(username, password)
        server.sendmail(
            fromaddr, questUser + '@uwaterloo.ca',
            "Welcome to the WatCoin bank! Your personalized destination address is "
            + bnk.getAccountAddress(questUser) +
            ". Please reply to this email with your desired recepient address."
        )
        server.quit()
        time.sleep(2)

    # Bank steps.