def delete(self, request, *args, **kwargs): pk = kwargs.get('pk') data = {'status': '', 'msg': ''} if settings.AUTH_LDAP: try: ldap_tool = LDAPTool() status = ldap_tool.ldap_delete(pk) user = User.objects.filter(username=pk) if user: #如果该用户是系统用户,删除ldap时候,顺便把系统中用户也删除了 user.delete() if status: msg = "用户:%s 删除成功" % pk rt = 200 else: msg = "用户%s 删除失败" % pk rt = 511 data['msg'] = msg data['status'] = rt except Exception as e: msg = str(e) rt = 500 data['msg'] = msg data['status'] = rt return Response(data=data, status=data['status']) return Response(data=data, status=data['status']) else: data['msg'] = '请系统先支持ldap' data['status'] = 512 return Response(data=data, status=data['status'])
def on_user_delete(sender, **kwargs): username = kwargs['instance'].username if settings.AUTH_LDAP: try: from common.ldapadmin import LDAPTool ldap_tool = LDAPTool() check_user_code, data = ldap_tool.check_user_status(username) if check_user_code != 404: status = ldap_tool.ldap_delete(username) if status: msg = "用户:%s 删除成功" % username logger.info(msg) else: msg = "用户%s 删除失败" % username logger.warning(msg) except Exception as e: msg = str(e) logger.error(msg)