Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
0b406b69
Commit
0b406b69
authored
Sep 03, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add captch login using
parent
6f0cfd23
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
51 additions
and
15 deletions
+51
-15
settings.py
apps/jumpserver/settings.py
+4
-0
urls.py
apps/jumpserver/urls.py
+1
-9
field.html
apps/templates/captcha/field.html
+13
-0
hidden_field.html
apps/templates/captcha/hidden_field.html
+1
-0
image.html
apps/templates/captcha/image.html
+5
-0
text_field.html
apps/templates/captcha/text_field.html
+7
-0
forms.py
apps/users/forms.py
+1
-1
forget_password.html
apps/users/templates/users/forget_password.html
+2
-2
login.html
apps/users/templates/users/login.html
+14
-2
urls.py
apps/users/urls.py
+0
-1
views.py
apps/users/views.py
+3
-0
No files found.
apps/jumpserver/settings.py
View file @
0b406b69
...
...
@@ -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'
apps/jumpserver/urls.py
View file @
0b406b69
...
...
@@ -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
)
...
...
apps/templates/captcha/field.html
0 → 100644
View file @
0b406b69
{{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>
\ No newline at end of file
apps/templates/captcha/hidden_field.html
0 → 100644
View file @
0b406b69
<input
id=
"{{id}}_0"
name=
"{{name}}_0"
type=
"hidden"
value=
"{{key}}"
/>
apps/templates/captcha/image.html
0 → 100644
View file @
0b406b69
{% 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 %}
\ No newline at end of file
apps/templates/captcha/text_field.html
0 → 100644
View file @
0b406b69
<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>
apps/users/forms.py
View file @
0b406b69
...
...
@@ -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
):
...
...
apps/users/templates/users/forget_password.html
View file @
0b406b69
...
...
@@ -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"
>
...
...
apps/users/templates/users/login.html
View file @
0b406b69
...
...
@@ -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>
...
...
apps/users/urls.py
View file @
0b406b69
...
...
@@ -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'
),
...
...
apps/users/views.py
View file @
0b406b69
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment