Beispiel #1
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
Beispiel #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
Beispiel #3
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
Beispiel #4
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