コード例 #1
0
    def save(self, commit=True):
        user = super().save(commit=commit)
        #LDAP用户
        if settings.AUTH_LDAP and user.is_ldap_user:
            ldap_tool = LDAPTool()
            check_user_code, data = ldap_tool.check_user_status(user.username)
            if check_user_code == 200:
                print("更新用户,类型为ldap")
                phone = user.phone
                old = {'mail': data[1].get('mail', '')}
                new = {
                    'mail': [user.email.encode('utf-8')],
                }
                if phone:
                    old = {
                        'mail': data[1].get('mail', ''),
                        'mobile': data[1].get('mobile', '')
                    }
                    new = {
                        'mail': [user.email.encode('utf-8')],
                        'mobile': [phone.encode('utf-8')],
                    }
                status = ldap_tool.ldap_update_user(user.username, old, new)

                if not status:
                    msg = "ldap用户更新失败"
                    messages.add_message(self.request, messages.ERROR, msg)
                else:
                    messages.add_message(self.request, messages.INFO,
                                         "ldap信息更新成功")
        return user
コード例 #2
0
    def save(self, commit=True):
        password = self.cleaned_data.get('password')
        public_key = self.cleaned_data.get('public_key')
        user = super().save(commit=commit)

        is_ldap_user = user.is_ldap_user
        # ldap用户
        username = user.username
        if settings.AUTH_LDAP:
            ldap_tool = LDAPTool()
            check_user_code, data = ldap_tool.check_user_status(username)
            if is_ldap_user and check_user_code == 200:
                print("更新用户,类型为ldap")
                old = {
                    'mail': data[1].get('mail', ''),
                    'mobile': data[1].get('mobile', '')
                }
                new = {
                    'mail': [user.email.encode('utf-8')],
                    'mobile': [user.phone.encode('utf-8')],
                }
                status = ldap_tool.ldap_update_user(username, old, new)
                if status:
                    return user
        # #本地用户
        if password and not is_ldap_user:
            user.set_password(password)
            user.save()
        if public_key:
            user.public_key = public_key
            user.save()
        return user
コード例 #3
0
 def save(self, commit=True):
     password = self.cleaned_data.get('password')
     public_key = self.cleaned_data.get('public_key')
     is_ldap_user = self.cleaned_data.get('is_ldap_user')
     user = super().save(commit=commit)
     # ldap用户
     username = user.username
     if settings.AUTH_LDAP:
         ldap_tool = LDAPTool()
         check_user_code, _ = ldap_tool.check_user_status(username)
         if is_ldap_user and check_user_code == 404:
             print("新增用户,类型为ldap")
             cn = user.username
             mail = user.email
             if password:
                 password = password
             else:
                 password = generate_activation_code(n=1)[0]
             status = ldap_tool.ldap_add_user(cn, mail, username, password)
             if status:
                 msg = "ldap用户创建成功"
                 messages.add_message(self.request, messages.SUCCESS, msg)
                 return user
             else:
                 msg = "ldap用户创建失败"
                 messages.add_message(self.request, messages.ERROR, msg)
     #本地用户
     if password and not is_ldap_user:
         user.set_password(password)
         user.save()
     if public_key:
         user.public_key = public_key
         user.save()
     return user
コード例 #4
0
ファイル: forms.py プロジェクト: jcops/diting
    def save(self, commit=True):
        password = self.cleaned_data.get('password')
        public_key = self.cleaned_data.get('public_key')
        user = super().save(commit=commit)

        is_ldap_user = user.is_ldap_user
        # ldap用户
        username = user.username
        if settings.AUTH_LDAP:
            ldap_tool = LDAPTool()
            check_user_code, data = ldap_tool.check_user_status(username)
            if is_ldap_user and check_user_code == 200:
                print("更新用户,类型为ldap")
                old = {'mail': data[1].get('mail', ''), 'mobile': data[1].get('mobile', '')}
                new = {'mail': [user.email.encode('utf-8')], 'mobile': [user.phone.encode('utf-8')],}
                status = ldap_tool.ldap_update_user(username, old, new)
                if status:
                    return user
        # #本地用户
        if password and not is_ldap_user:
            user.set_password(password)
            user.save()
        if public_key:
            user.public_key = public_key
            user.save()
        return user
コード例 #5
0
ファイル: forms.py プロジェクト: jcops/diting
 def save(self, commit=True):
     password = self.cleaned_data.get('password')
     public_key = self.cleaned_data.get('public_key')
     is_ldap_user = self.cleaned_data.get('is_ldap_user')
     user = super().save(commit=commit)
     # ldap用户
     username = user.username
     if settings.AUTH_LDAP:
         ldap_tool = LDAPTool()
         check_user_code,_ = ldap_tool.check_user_status(username)
         if is_ldap_user and check_user_code == 404:
             print("新增用户,类型为ldap")
             cn = user.username
             mail = user.email
             if password:
                 password = password
             else:
                 password = generate_activation_code(n=1)[0]
             status = ldap_tool.ldap_add_user(cn, mail, username, password)
             if status:
                 msg = "ldap用户创建成功"
                 messages.add_message(self.request, messages.SUCCESS, msg)
                 return user
             else:
                 msg = "ldap用户创建失败"
                 messages.add_message(self.request, messages.ERROR, msg)
     #本地用户
     if password and not is_ldap_user:
         user.set_password(password)
         user.save()
     if public_key:
         user.public_key = public_key
         user.save()
     return user
コード例 #6
0
ファイル: signals_handler.py プロジェクト: zxf-shine/diting
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)
コード例 #7
0
ファイル: forms.py プロジェクト: jcops/diting
    def save(self, commit=True):
        user = super().save(commit=commit)
        #LDAP用户
        if settings.AUTH_LDAP and user.is_ldap_user:
            ldap_tool = LDAPTool()
            check_user_code, data = ldap_tool.check_user_status(user.username)
            if check_user_code == 200:
                print("更新用户,类型为ldap")
                phone = user.phone
                old = {'mail': data[1].get('mail', '')}
                new = {'mail': [user.email.encode('utf-8')], }
                if phone:
                    old = {'mail': data[1].get('mail', ''), 'mobile': data[1].get('mobile', '')}
                    new = {'mail': [user.email.encode('utf-8')], 'mobile': [phone.encode('utf-8')], }
                status = ldap_tool.ldap_update_user(user.username, old, new)

                if not status:
                    msg = "ldap用户更新失败"
                    messages.add_message(self.request, messages.ERROR, msg)
                else:
                    messages.add_message(self.request, messages.INFO, "ldap信息更新成功")
        return user