mirror of https://github.com/jumpserver/jumpserver
Add captch login using
parent
6f0cfd23c1
commit
0b406b6988
|
@ -303,3 +303,7 @@ BROKER_URL = 'redis://%(password)s%(host)s:%(port)s/3' % {
|
|||
}
|
||||
|
||||
CELERY_RESULT_BACKEND = BROKER_URL
|
||||
|
||||
# Captcha settings, more see https://django-simple-captcha.readthedocs.io/en/latest/advanced.html
|
||||
CAPTCHA_IMAGE_SIZE = (75, 33)
|
||||
CAPTCHA_FOREGROUND_COLOR = '#001100'
|
||||
|
|
|
@ -20,22 +20,14 @@ from django.views.generic.base import TemplateView
|
|||
from django.http import HttpResponseRedirect
|
||||
|
||||
|
||||
# def view(request, **kwargs):
|
||||
# if kwargs:
|
||||
# print kwargs
|
||||
# return HttpResponseRedirect('/' + kwargs["module"] + '/' + kwargs["version"] + '/' + kwargs["api"])
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^captcha/', include('captcha.urls')),
|
||||
url(r'^$', TemplateView.as_view(template_name='base.html'), name='index'),
|
||||
url(r'^(api/)?users/', include('users.urls')),
|
||||
url(r'^assets/', include('assets.urls')),
|
||||
url(r'^terminal/', include('webterminal.urls')),
|
||||
]
|
||||
|
||||
#urlpatterns += [
|
||||
# url(r'^api/users/', include('users.api_urls')),
|
||||
#]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
{{image}}{{hidden_field}}{{text_field}}
|
||||
|
||||
<script>
|
||||
function refresh_captcha() {
|
||||
$.getJSON("{% url "captcha-refresh" %}",
|
||||
function (result) {
|
||||
$('.captcha').attr('src', result['image_url']);
|
||||
$('#id_captcha_0').val(result['key'])
|
||||
})
|
||||
}
|
||||
$('.captcha').click(refresh_captcha)
|
||||
</script>
|
|
@ -0,0 +1 @@
|
|||
<input id="{{id}}_0" name="{{name}}_0" type="hidden" value="{{key}}" />
|
|
@ -0,0 +1,4 @@
|
|||
{% load i18n %}
|
||||
{% spaceless %}
|
||||
{% if audio %}<a title="{% trans "Play CAPTCHA as audio file" %}" href="{{audio}}">{% endif %}<img src="{{image}}" alt="captcha" class="captcha" />{% if audio %}</a>{% endif %}
|
||||
{% endspaceless %}
|
|
@ -0,0 +1,7 @@
|
|||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<input autocomplete="off" id="{{id}}_1" class="form-control" name="{{name}}_1" type="text" />
|
||||
<span class="red-fonts" id="captcha-error" style="display: none">验证码错误</span>
|
||||
</div>
|
||||
</div>
|
||||
</br>
|
|
@ -10,7 +10,7 @@ from .models import User, UserGroup
|
|||
class UserLoginForm(forms.Form):
|
||||
username = forms.CharField(label='用户名', max_length=100)
|
||||
password = forms.CharField(label='密码', widget=forms.PasswordInput, max_length=100)
|
||||
# captcha = CaptchaField()
|
||||
captcha = CaptchaField()
|
||||
|
||||
|
||||
class UserAddForm(ModelForm):
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<title>INSPINIA | Forgot password</title>
|
||||
<link rel="shortcut icon" href="{% static "img/facio.ico" %}" type="image/x-icon">
|
||||
<title>忘记密码</title>
|
||||
|
||||
{% include '_head_css_js.html' %}
|
||||
<link href="{% static "css/jumpserver.css" %}" rel="stylesheet">
|
||||
|
|
|
@ -10,6 +10,14 @@
|
|||
{% include '_head_css_js.html' %}
|
||||
<link href="{% static "css/jumpserver.css" %}" rel="stylesheet">
|
||||
<script src="{% static "js/jumpserver.js" %}"></script>
|
||||
<style>
|
||||
.captcha {
|
||||
float: right;
|
||||
}
|
||||
#id_captcha_1 {
|
||||
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="gray-bg">
|
||||
|
@ -43,7 +51,9 @@
|
|||
<form class="m-t" role="form" method="post" action="{% url 'users:login' %}">
|
||||
{% csrf_token %}
|
||||
{% if form.errors %}
|
||||
<p class="red-fonts">{{ form.errors }}</p>
|
||||
{% if 'captcha' in form.errors %}
|
||||
<p class="red-fonts">验证码错误</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if errors %}
|
||||
<p class="red-fonts">{{ errors }}</p>
|
||||
|
@ -54,6 +64,9 @@
|
|||
<div class="form-group">
|
||||
<input type="password" class="form-control" name="{{ form.password.html_name }}" placeholder="Password" required="">
|
||||
</div>
|
||||
<div>
|
||||
{{ form.captcha }}
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary block full-width m-b">Login</button>
|
||||
|
||||
<a href="{% url 'users:forget-password' %}">
|
||||
|
@ -78,7 +91,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -10,7 +10,6 @@ app_name = 'users'
|
|||
urlpatterns = [
|
||||
url(r'^login$', views.UserLoginView.as_view(), name='login'),
|
||||
url(r'^logout$', views.UserLogoutView.as_view(), name='logout'),
|
||||
url(r'^captcha/', include('captcha.urls')),
|
||||
url(r'^password/forget$', views.UserForgetPasswordView.as_view(), name='forget-password'),
|
||||
url(r'^password/forget/sendmail-success$',
|
||||
views.UserForgetPasswordSendmailSuccessView.as_view(), name='forget-password-sendmail-success'),
|
||||
|
|
|
@ -42,6 +42,9 @@ class UserLoginView(FormView):
|
|||
|
||||
def post(self, request, *args, **kwargs):
|
||||
form = self.get_form()
|
||||
if not form.is_valid():
|
||||
return self.form_invalid(form)
|
||||
|
||||
username = form['username'].value()
|
||||
password = form['password'].value()
|
||||
|
||||
|
|
Loading…
Reference in New Issue