Beispiel #1
0
        def save(self, **args):
            try:
                try:
                   self.PIN = str(int(self.PIN))
                except:
                   raise Exception(_(u'人员编号只能为数字'))
                if int(self.PIN) == 0:
                    raise Exception(_(u'人员编号不能为0'))

                self.PIN = format_pin(self.PIN)

                tmp = Employee.all_objects.filter(PIN__exact=self.PIN)

                if len(tmp) > 0 and tmp[0].id != self.id:   #编辑状态
                    raise Exception(_(u'人员编号: %s 已存在') % self.PIN)
                
               
                if self.Card:#新增或编缉了卡号时
                    tmpcard = Employee.all_objects.filter(Card=self.Card)
                    if tmpcard and tmpcard[0].id != self.id:#此处主要用于批量发卡重复卡号的处理
                        tmpcard[0].Card = ''
                        tmpcard[0].save(force_update=True)#清空原有的,新的写入
                    
                    
                #emp = Employee.objects.filter(id=self.pk)
                #对密码进行加密
                if self.Password!="" or None:
                    if len(tmp) !=0:
                        if tmp[0].Password == self.Password:
                            pass
                        else:
                            self.Password = encrypt(self.Password)
                    else:
                        self.Password = encrypt(self.Password)
    
                super(Employee, self).save(**args)
                installed_apps = settings.INSTALLED_APPS
                if self.Card :#新增或编缉了卡号时
                    IssueCard = self.__class__.issuecard_set.related.model
                    tmp_issuecare = IssueCard.objects.filter(UserID=self, cardno=self.Card)
                    if not tmp_issuecare:
                        issuecard = IssueCard()
                        issuecard.UserID = self
                        issuecard.cardno = self.Card
                        issuecard.issuedate = datetime.datetime.now().strftime("%Y-%m-%d")
                        issuecard.save()

                    if "mysite.att" in installed_apps and (len(tmp)==0 or (tmp and tmp[0].Card!=self.Card)):#zkeco+zktime
                        from mysite.iclock.models.model_cmmdata import adj_user_cmmdata
                        adj_user_cmmdata(self, [], self.attarea.all())
                            #sync_set_user(self.search_device_byuser(), [self])
            except Exception, e:
                    import traceback; traceback.print_exc();
                    raise e
Beispiel #2
0
def check_pwd(request):
    from base.crypt import encrypt
    try:
        old_pwd = request.POST.get("old_pwd")
        p_device = request.POST.get("device")
        p_door_no = request.POST.get("door_no")
        field = request.POST.get("field")
        if not p_door_no:  #通讯密码
            device = Device.objects.filter(id=p_device)
            old_pwd = encrypt(old_pwd)
            if device:
                if old_pwd == device[0].comm_pwd:
                    state = True
                else:
                    state = False
        else:
            acc_door = AccDoor.objects.filter(device=p_device,
                                              door_no=p_door_no)
            state = acc_door and acc_door[0].check_password(
                old_pwd, acc_door[0].__getattribute__(field)) or False

        if state == True: return HttpResponse("ok")
        else: return HttpResponse("error")
    except:
        import traceback
        traceback.print_exc()
Beispiel #3
0
def check_old_commpwd(request):
    from base.crypt import encrypt
    old_commpwd = request.POST.get("old_commpwd")
    device = request.POST.get("device")
    iclock = Device.objects.filter(id=device)
    if encrypt(old_commpwd
               ) == iclock[0].comm_pwd or old_commpwd == iclock[0].comm_pwd:
        return HttpResponse("ok")
    else:
        return HttpResponse("error")
Beispiel #4
0
def check_old_commpwd(request):
    from base.crypt import encrypt

    old_commpwd = request.POST.get("old_commpwd")
    device = request.POST.get("device")
    iclock = Device.objects.filter(id=device)
    if encrypt(old_commpwd) == iclock[0].comm_pwd or old_commpwd == iclock[0].comm_pwd:
        return HttpResponse("ok")
    else:
        return HttpResponse("error")
Beispiel #5
0
    def data_valid(self, sendtype):  #此处只有编辑的情况
        tmp = AccDoor.objects.filter(door_name=self.door_name.strip())
        if tmp and tmp[0] != self:  #新增时(该名称的记录已存在且不是编辑)
            raise Exception(_(u'门名称设置重复!'))

        if self.card_intervaltime:
            if self.card_intervaltime > 10 or self.card_intervaltime < 0:
                raise Exception(_(u"刷卡间隔范围为0-10秒"))

        if self.door_sensor_status != 0:
            if self.sensor_delay <= 0 or self.sensor_delay > 254:
                raise Exception(_(u"门磁延时范围为1-254秒"))

            if self.sensor_delay and self.sensor_delay <= self.lock_delay:
                raise Exception(_(u"门磁延时需大于锁驱动时长"))

        if self.lock_delay < 0 or self.lock_delay > 254:
            raise Exception(_(u"锁驱动时长范围为0-254秒"))  #255为常开   远程开关门也取此值

        if self.force_pwd:
            from mysite.personnel.models import Employee
            emps = Employee.objects.all()  #系统里所有的,不需要权限过滤
            password_existed = [
                e.Password for e in emps
            ]  #[int(d.force_pwd) for d in doors if d.force_pwd]
            if self.force_pwd in password_existed or encrypt(
                    self.force_pwd) in password_existed:  #不含‘’
                raise Exception(_(u"胁迫密码不能与任意人员密码相同"))
            accdoor = AccDoor.objects.filter(id=self.pk)
            p1 = re.compile(r'^([0-9]+)$')
            if (accdoor[0].force_pwd != self.force_pwd) and (not p1.match(
                    self.force_pwd)):
                raise Exception(_(u"胁迫密码必须为整数"))

        if self.supper_pwd:
            #                print self.supper_pwd,'---super'
            #                if self.supper_pwd == self.force_pwd or self.encrypt_password(self.supper_pwd)==self.force_pwd:
            #                    raise Exception(_(u"紧急状态密码不能和胁迫密码相同"))
            accdoor = AccDoor.objects.filter(id=self.pk)
            p2 = re.compile(r'^([0-9]+)$')
            if (accdoor[0].supper_pwd != self.supper_pwd) and (not p2.match(
                    self.supper_pwd)):
                raise Exception(_(u"紧急状态密码必须为整数"))
Beispiel #6
0
    def data_valid(self, sendtype):  # 此处只有编辑的情况
        tmp = AccDoor.objects.filter(door_name=self.door_name.strip())
        if tmp and tmp[0] != self:  # 新增时(该名称的记录已存在且不是编辑)
            raise Exception(_(u"门名称设置重复!"))

        if self.card_intervaltime:
            if self.card_intervaltime > 10 or self.card_intervaltime < 0:
                raise Exception(_(u"刷卡间隔范围为0-10秒"))

        if self.door_sensor_status != 0:
            if self.sensor_delay <= 0 or self.sensor_delay > 254:
                raise Exception(_(u"门磁延时范围为1-254秒"))

            if self.sensor_delay and self.sensor_delay <= self.lock_delay:
                raise Exception(_(u"门磁延时需大于锁驱动时长"))

        if self.lock_delay < 0 or self.lock_delay > 254:
            raise Exception(_(u"锁驱动时长范围为0-254秒"))  # 255为常开   远程开关门也取此值

        if self.force_pwd:
            from mysite.personnel.models import Employee

            emps = Employee.objects.all()  # 系统里所有的,不需要权限过滤
            password_existed = [e.Password for e in emps]  # [int(d.force_pwd) for d in doors if d.force_pwd]
            if self.force_pwd in password_existed or encrypt(self.force_pwd) in password_existed:  # 不含‘’
                raise Exception(_(u"胁迫密码不能与任意人员密码相同"))
            accdoor = AccDoor.objects.filter(id=self.pk)
            p1 = re.compile(r"^([0-9]+)$")
            if (accdoor[0].force_pwd != self.force_pwd) and (not p1.match(self.force_pwd)):
                raise Exception(_(u"胁迫密码必须为整数"))

        if self.supper_pwd:
            #                print self.supper_pwd,'---super'
            #                if self.supper_pwd == self.force_pwd or self.encrypt_password(self.supper_pwd)==self.force_pwd:
            #                    raise Exception(_(u"紧急状态密码不能和胁迫密码相同"))
            accdoor = AccDoor.objects.filter(id=self.pk)
            p2 = re.compile(r"^([0-9]+)$")
            if (accdoor[0].supper_pwd != self.supper_pwd) and (not p2.match(self.supper_pwd)):
                raise Exception(_(u"紧急状态密码必须为整数"))
Beispiel #7
0
def check_pwd(request):
    from base.crypt import encrypt
    try:
        old_pwd = request.POST.get("old_pwd")
        p_device = request.POST.get("device")
        p_door_no = request.POST.get("door_no")
        field = request.POST.get("field")
        if not p_door_no:  #通讯密码
            device = Device.objects.filter(id=p_device)
            old_pwd = encrypt(old_pwd)
            if device:
                if old_pwd == device[0].comm_pwd:
                    state = True
                else:
                    state = False
        else:
            acc_door = AccDoor.objects.filter(device=p_device,door_no=p_door_no)
            state = acc_door and acc_door[0].check_password(old_pwd,acc_door[0].__getattribute__(field)) or False
            
        if state == True:return HttpResponse("ok")
        else:return HttpResponse("error")
    except:
        import traceback
        traceback.print_exc()
Beispiel #8
0
 def encrypt_password(self, password):
     return encrypt(password)
Beispiel #9
0
        def data_valid(self, sendtype):
            '''
            服务器端验证
            '''
            import re
            try:
               self.PIN = str(int(self.PIN))
            except:
               raise Exception(_(u'人员编号只能为数字'))
            if int(self.PIN) == 0:
                raise Exception(_(u'人员编号不能为0'))
            orgcard = self.Card

            if len(self.PIN) > settings.PIN_WIDTH:
                raise Exception(_(u'%(f)s 人员编号长度不能超过%(ff)s位') % {"f":self.PIN, "ff":settings.PIN_WIDTH})
            self.PIN = format_pin(self.PIN)

            tmp = Employee.objects.filter(PIN__exact=self.PIN)
            if len(tmp) > 0 and tmp[0].id != self.id:   #编辑状态
                raise Exception(_(u'人员编号: %s 已存在') % self.PIN)
            
            if self.identitycard:
                self.__class__.can_restore=True
                tmpid = Employee.objects.filter(identitycard__exact=self.identitycard, isblacklist__exact=1)
                self.__class__.can_restore=False
                if len(tmpid) > 0 :   #编辑状态
                    raise Exception(_(u'%s 已存在黑名单中!') % self.identitycard)

            if self.set_valid_time == True:
                if not self.acc_startdate or not self.acc_enddate:
                    raise Exception(_(u'您已选择设置门禁有效时间,请填写开始日期和结束日期'))
                if self.acc_startdate > self.acc_enddate:
                    raise Exception(_(u'门禁有效时间的开始日期不能大于结束日期'))

            if self.Password:
                if 'mysite.iaccess' in settings.INSTALLED_APPS:
                    from mysite.iaccess.models import AccDoor
                    doors = AccDoor.objects.all()#系统里所有的,不需要权限过滤
                    force_pwd_existed = [d.force_pwd for d in doors]#[int(d.force_pwd) for d in doors if d.force_pwd]
                    from base.crypt import encrypt
                    #由于胁迫密码已经加密,须将人员密码加密后再进行比较
                    if self.Password in force_pwd_existed or encrypt(self.Password) in force_pwd_existed:#不含‘’
                        raise Exception(_(u"人员密码不能与任意门禁胁迫密码相同"))
                p = re.compile(r'^[0-9]+$')
                if not self.pk:#新增时
                    if not p.match(self.Password):
                        raise Exception(_(u"人员密码必须为整数"))
                else:
                    emp = Employee.objects.filter(pk=self.pk)
                    if emp[0].Password == self.Password and not emp[0].Password.isdigit():
                        pass    
                    elif not p.match(self.Password):
                        raise Exception(_(u"人员密码必须为整数"))
        
            if self.Birthday and self.Birthday>datetime.datetime.now().date():
                raise Exception(_(u"生日日期错误"))
            tmpre = re.compile('^[0-9]+$')
            #print self.Card
            if self.Card and not tmpre.search(orgcard):
                raise Exception(_(u'卡号不正确'))
            
            if self.Card:
                tmpcard = Employee.objects.filter(Card=self.Card)
                if tmpcard and tmpcard[0].id != self.id:#用于前端表单验证
                    raise Exception(_(u'卡号已存在,如果确认将重新发卡,请先清除该卡原持卡人 %s') % tmpcard[0])
Beispiel #10
0
 def encrypt_password(self, password):
     return encrypt(password)