pyztk/zk/user.py

41 lines
1.7 KiB
Python
Raw Normal View History

2016-05-25 16:28:55 +07:00
# -*- coding: utf-8 -*-
2018-04-07 07:01:35 +07:00
from struct import pack #, unpack
2016-05-25 16:28:55 +07:00
class User(object):
encoding = 'UTF-8'
2016-05-25 16:28:55 +07:00
def __init__(self, uid, name, privilege, password='', group_id='', user_id='', card=0):
2016-05-25 16:28:55 +07:00
self.uid = uid
2018-04-19 07:22:03 +07:00
self.name = str(name)
2016-05-25 16:28:55 +07:00
self.privilege = privilege
2018-04-19 07:22:03 +07:00
self.password = str(password)
self.group_id = str(group_id)
2016-05-25 16:28:55 +07:00
self.user_id = user_id
self.card = int(card) # 64 int to 40 bit int
@staticmethod
def json_unpack(json):
#validate?
return User(
uid=json['uid'],
name=json['name'],
privilege=json['privilege'],
password=json['password'],
group_id=json['group_id'],
user_id=json['user_id'],
card=json['card']
)
2018-04-07 07:01:35 +07:00
def repack29(self): # with 02 for zk6 (size 29)
return pack("<BHB5s8sIxBhI", 2, self.uid, self.privilege, self.password.encode(User.encoding, errors='ignore'), self.name.encode(User.encoding, errors='ignore'), self.card, int(self.group_id) if self.group_id else 0, 0, int(self.user_id))
def repack73(self): #with 02 for zk8 (size73)
#password 6s + 0x00 + 0x77
# 0,0 => 7sx group id, timezone?
return pack("<BHB8s24sIB7sx24s", 2, self.uid, self.privilege,self.password.encode(User.encoding, errors='ignore'), self.name.encode(User.encoding, errors='ignore'), self.card, 1, str(self.group_id).encode(User.encoding, errors='ignore'), str(self.user_id).encode(User.encoding, errors='ignore'))
2016-06-24 19:00:55 +07:00
def __str__(self):
2018-04-19 07:22:03 +07:00
return '<User>: [uid:{}, name:{} user_id:{}]'.format(self.uid, self.name, self.user_id)
2016-06-12 16:35:02 +07:00
def __repr__(self):
2018-04-30 21:25:43 +07:00
return '<User>: [uid:{}, name:{} user_id:{}]'.format(self.uid, self.name, self.user_id)