def post(self, request, *args, **kwargs): password = request.POST.get('password') password_confirm = request.POST.get('password-confirm') token = request.GET.get('token') if password != password_confirm: return self.get(request, errors=_('Password not same')) user = User.validate_reset_token(token) if not user: return self.get(request, errors=_('Token invalid or expired')) # 重置LDAP用户密码 from django.conf import settings if settings.AUTH_LDAP and user.is_ldap_user: from common.ldapadmin import LDAPTool ldap_tool = LDAPTool() username = user.username status = ldap_tool.ldap_update_password(username, new_password=password) if status: print("ldap用户:%s 密码修改成功" % username) else: return self.get(request, errors="密码更新失败,可能是弱类型") else: user.reset_password(password) return HttpResponseRedirect(reverse('users:reset-password-success'))
def post(self, request, *args, **kwargs): password = request.POST.get('password') password_confirm = request.POST.get('password-confirm') token = request.GET.get('token') if password != password_confirm: return self.get(request, errors=_('Password not same')) user = User.validate_reset_token(token) if not user: return self.get(request, errors=_('Token invalid or expired')) # 重置LDAP用户密码 from django.conf import settings if settings.AUTH_LDAP and user.is_ldap_user: from common.ldapadmin import LDAPTool ldap_tool = LDAPTool() username = user.username status = ldap_tool.ldap_update_password(username, new_password=password) if status: print("ldap用户:%s 密码修改成功" % username) else: return self.get(request, errors="密码更新失败,可能是弱类型") else: user.reset_password(password) return HttpResponseRedirect(reverse('users:reset-password-success'))
def save(self): username = self.instance.username password = self.cleaned_data['new_password'] self.instance.set_password(password) self.instance.save() # ldap用户 if settings.AUTH_LDAP and self.instance.is_ldap_user: ldap_tool = LDAPTool() status = ldap_tool.ldap_update_password(username, new_password=password) if status: return self.instance return self.instance
def save(self): username = self.instance.username password = self.cleaned_data['new_password'] self.instance.set_password(password) self.instance.save() # ldap用户 if settings.AUTH_LDAP and self.instance.is_ldap_user: ldap_tool = LDAPTool() status = ldap_tool.ldap_update_password(username, new_password=password) if status: return self.instance return self.instance