+ if not self.isLoggedIn():
+ return False
+ if DISPSRV_MIFARE:
+ card_base64 = base64.b64encode(cardId)
+ logging.info('Enrolling card %s to uid %s (%s)' % (cardId, self._userId, self._username))
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
+ sock.connect(DISPENSE_ENDPOINT)
+ sock.write("AUTHIDENT\n")
+ rsp = sock.readline()
+ assert "200" in rsp
+ sock.write("SETEUSER %s\n", self._username)
+ rsp = sock.readline()
+ assert "200" in rsp
+ sock.write("CARD_ADD %s\n", card_base64)
+ rsp = sock.readline()
+ if "200" in rsp:
+ return True
+ else:
+ return False
+ else:
+ if get_uid(cardId) != None:
+ return False
+ else:
+ logging.info('Enrolling card %s to uid %s (%s)' % (cardId, self._userId, self._username))
+ set_card_id(self._userId, cardId)
+ return True