From c4880a9c59c4e5daaab4dc3bec898cf411a18ee8 Mon Sep 17 00:00:00 2001 From: "Fanani M. Ihsan" Date: Wed, 25 May 2016 12:02:56 +0700 Subject: [PATCH] update user command string --- zk/base.py | 11 +++++++++-- zk/const.py | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/zk/base.py b/zk/base.py index 1bf9e8f..133f9b6 100644 --- a/zk/base.py +++ b/zk/base.py @@ -202,9 +202,16 @@ class ZK(object): else: return cmd_response - def set_user(self, uid, privilege, password='', name='', card_num=chr(1), group='', timezone='', user_id=''): + def set_user(self, uid, name, password='', privilege=0, grup_id='', user_id=''): command = const.CMD_USER_WRQ - command_string = pack('sss8s28ss7sx8s16s', chr(uid % 256), chr(uid >> 8), chr(privilege), password, name, card_num, group, user_id, timezone ) + + uid = chr(uid % 256) + chr(uid >> 8) + + if privilege not in [const.USER_DEFAULT, const.USER_ADMIN]: + privilege = const.USER_DEFAULT + privilege = chr(privilege) + + command_string = pack('2sc6s30sc8s24s', uid, privilege, password, name, chr(0), grup_id, user_id) cmd_response = self.__send_command(command=command, command_string=command_string, response_size=1024) cmd_response['data'] = '' if cmd_response.get('status'): diff --git a/zk/const.py b/zk/const.py index 8b24dfa..d085adf 100644 --- a/zk/const.py +++ b/zk/const.py @@ -93,6 +93,9 @@ EF_VERIFY = (1<<7)# be real-time to verify fingerprint EF_FPFTR = (1<<8)# be real-time capture fingerprint minutia EF_ALARM = (1<<9)# Alarm signal +USER_DEFAULT = 0 +USER_ADMIN = 14 + ''' Follow is data type sign (attendance record, fingerprint) FCT_ATTLOG (U8)1 Attendance record