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
b8bebc9b
Commit
b8bebc9b
authored
Sep 02, 2016
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'api' of code.simcu.com:jumpserver/jumpserver into api
parents
2c112558
90ca5a8b
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
17 deletions
+38
-17
settings.py
apps/jumpserver/settings.py
+1
-0
forms.py
apps/users/forms.py
+2
-8
login.html
apps/users/templates/users/login.html
+6
-6
urls.py
apps/users/urls.py
+3
-2
views.py
apps/users/views.py
+26
-1
No files found.
apps/jumpserver/settings.py
View file @
b8bebc9b
...
...
@@ -61,6 +61,7 @@ INSTALLED_APPS = [
'rest_framework'
,
'rest_framework.authtoken'
,
'bootstrapform'
,
'captcha'
,
# 'django.contrib.admin',
'django.contrib.auth'
,
'django.contrib.contenttypes'
,
...
...
apps/users/forms.py
View file @
b8bebc9b
...
...
@@ -2,21 +2,15 @@
from
django.forms
import
ModelForm
from
django
import
forms
from
captcha.fields
import
CaptchaField
from
.models
import
User
,
UserGroup
# class UserLoginForm(ModelForm):
# class Meta:
# model = User
# fields = [
# "email", "password"
# ]
class
UserLoginForm
(
forms
.
Form
):
username
=
forms
.
CharField
(
label
=
'用户名'
,
max_length
=
100
)
password
=
forms
.
CharField
(
label
=
'密码'
,
widget
=
forms
.
PasswordInput
,
max_length
=
100
)
# captcha = CaptchaField()
class
UserAddForm
(
ModelForm
):
...
...
apps/users/templates/users/login.html
View file @
b8bebc9b
...
...
@@ -43,13 +43,16 @@
<form
class=
"m-t"
role=
"form"
method=
"post"
action=
"{% url 'users:login' %}"
>
{% csrf_token %}
{% if form.errors %}
<p
class=
"red-fonts"
>
用户名/密码 不正确, 请重试
</p>
<p
class=
"red-fonts"
>
{{ form.errors }}
</p>
{% endif %}
{% if errors %}
<p
class=
"red-fonts"
>
{{ errors }}
</p>
{% endif %}
<div
class=
"form-group"
>
<input
type=
"text"
class=
"form-control"
name=
"
username
"
placeholder=
"Username"
required=
""
>
<input
type=
"text"
class=
"form-control"
name=
"
{{ form.username.html_name }}
"
placeholder=
"Username"
required=
""
>
</div>
<div
class=
"form-group"
>
<input
type=
"password"
class=
"form-control"
name=
"
password
"
placeholder=
"Password"
required=
""
>
<input
type=
"password"
class=
"form-control"
name=
"
{{ form.password.html_name }}
"
placeholder=
"Password"
required=
""
>
</div>
<button
type=
"submit"
class=
"btn btn-primary block full-width m-b"
>
Login
</button>
...
...
@@ -58,12 +61,9 @@
</a>
<p
class=
"text-muted text-center"
>
{#
<small>
Do not have an account?
</small>
#}
</p>
{#
<a
class=
"btn btn-sm btn-white btn-block"
href=
"register.html"
>
Create an account
</a>
#}
</form>
<p
class=
"m-t"
>
{#
<small>
Inspinia we app framework base on Bootstrap 3
©
2014
</small>
#}
</p>
</div>
</div>
...
...
apps/users/urls.py
View file @
b8bebc9b
from
django.conf.urls
import
url
from
django.conf.urls
import
url
,
include
from
django.contrib.auth
import
views
as
auth_views
import
views
...
...
@@ -7,8 +7,9 @@ import api
app_name
=
'users'
urlpatterns
=
[
url
(
r'^login$'
,
auth_views
.
login
,
{
'template_name'
:
'users/login.html'
}
,
name
=
'login'
),
url
(
r'^login$'
,
views
.
UserLoginView
.
as_view
()
,
name
=
'login'
),
url
(
r'^logout$'
,
auth_views
.
logout
,
{
'template_name'
:
'users/login.html'
},
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 @
b8bebc9b
...
...
@@ -4,7 +4,7 @@ from __future__ import unicode_literals
import
logging
from
django.shortcuts
import
get_object_or_404
,
reverse
,
render
,
Http404
from
django.shortcuts
import
get_object_or_404
,
reverse
,
render
,
Http404
,
redirect
from
django.http
import
HttpResponseRedirect
from
django.urls
import
reverse_lazy
from
django.db.models
import
Q
...
...
@@ -15,6 +15,7 @@ from django.views.generic.detail import DetailView
from
django.contrib.messages.views
import
SuccessMessageMixin
from
django.conf
import
settings
from
django.http
import
HttpResponseRedirect
from
django.contrib.auth
import
views
as
auth_view
,
authenticate
,
login
from
common.utils
import
get_object_or_none
...
...
@@ -26,6 +27,30 @@ from .utils import AdminUserRequiredMixin, ssh_key_gen, user_add_success_next, s
logger
=
logging
.
getLogger
(
'jumpserver.users.views'
)
class
UserLoginView
(
FormView
):
template_name
=
'users/login.html'
form_class
=
UserLoginForm
redirect_field_name
=
'next'
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
if
self
.
request
.
user
.
is_staff
:
return
redirect
(
request
.
GET
.
get
(
self
.
redirect_field_name
,
reverse
(
'index'
)))
return
super
(
UserLoginView
,
self
)
.
get
(
request
,
*
args
,
**
kwargs
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
form
=
self
.
get_form
()
username
=
form
[
'username'
]
.
value
()
password
=
form
[
'password'
]
.
value
()
user
=
authenticate
(
username
=
username
,
password
=
password
)
if
user
is
None
:
kwargs
.
update
({
'errors'
:
'账号密码不正确'
})
return
self
.
get
(
request
,
*
args
,
**
kwargs
)
login
(
request
,
user
)
return
redirect
(
request
.
GET
.
get
(
self
.
redirect_field_name
,
reverse
(
'index'
)))
class
UserListView
(
AdminUserRequiredMixin
,
ListView
):
model
=
User
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
...
...
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