pass
def authUserIdPin(self, userId, pin):
+ return self.authUserIdPin_db(userId, pin)
+ #return self.authUserIdPin_file(userId, pin)
+
+ def authUserIdPin_db(self, userId, pin):
+ userId = int(userId)
+
+ try:
+ # Get username (TODO: Store the user ID in the dispense database too)
+ info = pwd.getpwuid(userId)
+ except KeyError:
+ logging.info('getting pin for uid %d: user not in password file'%userId)
+ return False
+
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
+ sock.connect(DISPENSE_ENDPOINT)
+ logging.debug('connected to dispsrv')
+ sockf = sock.makefile()
+ sockf.write("AUTHIDENT\n"); sockf.flush()
+ rsp = sockf.readline()
+ assert "200" in rsp
+ logging.debug('authenticated')
+ sockf.write("PIN_CHECK %s %s\n" % (info.pw_name, pin)); sockf.flush()
+ rsp = sockf.readline()
+ if not "200" in rsp:
+ logging.info('checking pin for uid %d: Server said no - %r' % (userId, rsp))
+ return False
+ #Login Successful
+ logging.info('accepted pin for uid %d \'%s\'' % (userId, info.pw_name))
+ self._userid = userId
+ self._loggedIn = True
+ self._disabled = False
+ self._username = info.pw_name
+ return True
+
+ def authUserIdPin_file(self, userId, pin):
userId = int(userId)
try:
rsp = sockf.readline()
if not "200" in rsp:
logging.info("Rejected card base64:%s" % (card_base64,))
- return False
+ return False
username = rsp.split('=')[1].strip()
logging.info("Accepted card base64:%s for %s" % (card_base64,username,))