From 784bec42fff0789e98b5216614096c9a93650e83 Mon Sep 17 00:00:00 2001 From: BaiJiangjie Date: Tue, 24 Apr 2018 13:00:36 +0800 Subject: [PATCH 1/5] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=99=BB=E5=BD=95,=E9=A6=96=E6=AC=A1=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E4=B8=8D=E9=9C=80=E8=A6=81=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?,=E7=99=BB=E5=BD=95=E5=A4=B1=E8=B4=A5=E6=97=B6=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E9=AA=8C=E8=AF=81=E7=A0=81=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/users/forms.py | 8 ++++++++ apps/users/templates/users/login.html | 2 +- apps/users/views/login.py | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/apps/users/forms.py b/apps/users/forms.py index f6c02ff23..f777e0dd7 100644 --- a/apps/users/forms.py +++ b/apps/users/forms.py @@ -15,6 +15,14 @@ class UserLoginForm(AuthenticationForm): label=_('Password'), widget=forms.PasswordInput, max_length=128, strip=False ) + + +class UserLoginCaptchaForm(AuthenticationForm): + username = forms.CharField(label=_('Username'), max_length=100) + password = forms.CharField( + label=_('Password'), widget=forms.PasswordInput, + max_length=128, strip=False + ) captcha = CaptchaField() diff --git a/apps/users/templates/users/login.html b/apps/users/templates/users/login.html index 13276f6fe..7dd3f5d0a 100644 --- a/apps/users/templates/users/login.html +++ b/apps/users/templates/users/login.html @@ -53,7 +53,7 @@ {% endif %} {% endif %}
- +
diff --git a/apps/users/views/login.py b/apps/users/views/login.py index bb7f58874..7e3d50c8a 100644 --- a/apps/users/views/login.py +++ b/apps/users/views/login.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import os +from django.core.cache import cache from django.shortcuts import render from django.contrib.auth import login as auth_login, logout as auth_logout from django.contrib.auth.mixins import LoginRequiredMixin @@ -43,7 +44,9 @@ __all__ = [ class UserLoginView(FormView): template_name = 'users/login.html' form_class = forms.UserLoginForm + form_class_captcha = forms.UserLoginCaptchaForm redirect_field_name = 'next' + key_prefix = "_LOGIN_INVALID_{}" def get(self, request, *args, **kwargs): if request.user.is_staff: @@ -58,6 +61,21 @@ class UserLoginView(FormView): set_tmp_user_to_cache(self.request, form.get_user()) return redirect(self.get_success_url()) + def form_invalid(self, form): + ip = get_login_ip(self.request) + cache.set(self.key_prefix.format(ip), 1, 3600) + old_form = form + form = self.form_class_captcha(data=form.data) + form._errors = old_form.errors + return super().form_invalid(form) + + def get_form_class(self): + ip = get_login_ip(self.request) + if cache.get(self.key_prefix.format(ip)): + return self.form_class_captcha + else: + return self.form_class + def get_success_url(self): user = get_user_or_tmp_user(self.request) From c37414045b14ad415bb09025bfcc80ecff2c7b6e Mon Sep 17 00:00:00 2001 From: BaiJiangjie Date: Tue, 24 Apr 2018 15:16:05 +0800 Subject: [PATCH 2/5] =?UTF-8?q?[Bugfix]=20=E4=BF=AE=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=88=97=E8=A1=A8=E5=AF=BC=E5=87=BA=EF=BC=8C=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=AF=BC=E5=87=BA=E5=85=A8=E9=83=A8=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/users/templates/users/user_list.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/users/templates/users/user_list.html b/apps/users/templates/users/user_list.html index 0902c3e73..c7c9b8b28 100644 --- a/apps/users/templates/users/user_list.html +++ b/apps/users/templates/users/user_list.html @@ -107,6 +107,9 @@ $(document).ready(function(){ $('.btn_export').click(function () { var users = []; var rows = table.rows('.selected').data(); + if(rows.length===0){ + rows = table.rows().data(); + } $.each(rows, function (index, obj) { users.push(obj.id) }); From 2823d02763faad39b68d418295da865b13c000c5 Mon Sep 17 00:00:00 2001 From: BaiJiangjie Date: Tue, 24 Apr 2018 16:15:04 +0800 Subject: [PATCH 3/5] =?UTF-8?q?[Bugfix]=20=E4=BF=AE=E5=A4=8D=E8=B5=84?= =?UTF-8?q?=E4=BA=A7=E5=88=97=E8=A1=A8=E5=AF=BC=E5=85=A5=EF=BC=8C=E8=B5=84?= =?UTF-8?q?=E4=BA=A7id=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/views/asset.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/assets/views/asset.py b/apps/assets/views/asset.py index 306a26a0a..273323193 100644 --- a/apps/assets/views/asset.py +++ b/apps/assets/views/asset.py @@ -304,7 +304,10 @@ class BulkImportAssetView(AdminUserRequiredMixin, JSONResponseMixin, FormView): if v != '': asset_dict[k] = v - asset = get_object_or_none(Asset, id=asset_dict.pop('id', 0)) + asset = None + asset_id = asset_dict.pop('id', None) + if asset_id: + asset = get_object_or_none(Asset, id=asset_id) if not asset: try: if len(Asset.objects.filter(hostname=asset_dict.get('hostname'))): From 102e1ca97ca38f481f31044f7b6fd8ed500fb84e Mon Sep 17 00:00:00 2001 From: BaiJiangjie Date: Tue, 24 Apr 2018 18:29:14 +0800 Subject: [PATCH 4/5] =?UTF-8?q?[Bugfix]=20=E5=88=9B=E5=BB=BA=E8=B5=84?= =?UTF-8?q?=E4=BA=A7=EF=BC=8C=E8=B5=84=E4=BA=A7=E7=B3=BB=E7=BB=9F=E7=BD=AE?= =?UTF-8?q?=E4=B8=8A=EF=BC=8CRDP:3389?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/templates/assets/asset_create.html | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/assets/templates/assets/asset_create.html b/apps/assets/templates/assets/asset_create.html index eca0f6a03..99703d2e3 100644 --- a/apps/assets/templates/assets/asset_create.html +++ b/apps/assets/templates/assets/asset_create.html @@ -15,9 +15,9 @@ {% csrf_token %}

{% trans 'Basic' %}

{% bootstrap_field form.hostname layout="horizontal" %} + {% bootstrap_field form.platform layout="horizontal" %} {% bootstrap_field form.ip layout="horizontal" %} {% bootstrap_field form.port layout="horizontal" %} - {% bootstrap_field form.platform layout="horizontal" %} {% bootstrap_field form.public_ip layout="horizontal" %} {% bootstrap_field form.domain layout="horizontal" %} @@ -85,6 +85,17 @@ $(document).ready(function () { allowClear: true, templateSelection: format }); + $("#id_platform").change(function (){ + var platform = $("#id_platform option:selected").text(); + var port = 22; + if(platform === 'Windows'){ + port = 3389; + } + if(platform === 'Other'){ + port = null; + } + $("#id_port").val(port); + }); }) {% endblock %} \ No newline at end of file From ea2863a51b46a2b400374fd2c065bc7a54b7210e Mon Sep 17 00:00:00 2001 From: BaiJiangjie Date: Tue, 24 Apr 2018 22:10:52 +0800 Subject: [PATCH 5/5] =?UTF-8?q?[Update]=20=E5=88=9B=E5=BB=BA=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E3=80=81=E8=B5=84=E4=BA=A7=E6=88=90=E5=8A=9F=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF=E5=8F=AF=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/templates/_message.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/templates/_message.html b/apps/templates/_message.html index 9c64a441f..4c37cc138 100644 --- a/apps/templates/_message.html +++ b/apps/templates/_message.html @@ -7,7 +7,7 @@ Your information was incomplete. Please click this link to complete your information. {% endblocktrans %} - +
{% endif %} {% endblock %} @@ -28,7 +28,9 @@ {% for message in messages %}
{{ message|safe }} +
+ {% endfor %} {% endif %}