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
8cc09f0e
Commit
8cc09f0e
authored
Sep 06, 2016
by
xiaoyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move login and logout view back to CBV
parent
3c6f50b7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
28 deletions
+50
-28
_user_profile.html
apps/templates/_user_profile.html
+1
-1
urls.py
apps/users/urls.py
+2
-22
views.py
apps/users/views.py
+47
-5
No files found.
apps/templates/_user_profile.html
View file @
8cc09f0e
...
...
@@ -11,7 +11,7 @@
<strong
class=
"font-bold"
>
{{ user.name }}
<span
style=
"color: #8095a8"
></span></strong>
</span>
<span
class=
"text-muted text-xs block"
>
{{ user.get_role_display | default:
{% trans 'User' %}
}}
<b
class=
"caret"
></b>
{{ user.get_role_display | default:
_('User')
}}
<b
class=
"caret"
></b>
</span>
</span>
</a>
...
...
apps/users/urls.py
View file @
8cc09f0e
from
django.conf.urls
import
url
from
django.contrib.auth
import
views
as
auth_views
from
django.utils.translation
import
ugettext
as
_
import
views
import
api
from
users.forms
import
UserLoginForm
app_name
=
'users'
urlpatterns
=
[
url
(
r'^login$'
,
auth_views
.
login
,
{
'template_name'
:
"users/login.html"
,
'authentication_form'
:
UserLoginForm
,
'redirect_authenticated_user'
:
True
},
name
=
'login'
),
url
(
r'^logout$'
,
auth_views
.
logout
,
{
"template_name"
:
"common/flash_message_standalone.html"
,
"extra_context"
:
{
'title'
:
_
(
'Logout success'
),
'messages'
:
_
(
'Logout success, return login page'
),
'redirect_url'
:
'/users/login'
,
'auto_redirect'
:
True
,
}
},
name
=
'logout'
),
url
(
r'^login$'
,
views
.
UserLoginView
.
as_view
(),
name
=
'login'
),
url
(
r'^logout$'
,
views
.
UserLogoutView
.
as_view
(),
name
=
'logout'
),
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 @
8cc09f0e
...
...
@@ -5,27 +5,69 @@ from __future__ import unicode_literals
import
logging
from
django.conf
import
settings
from
django.contrib.auth
import
login
as
auth_login
,
logout
as
auth_logout
from
django.contrib.messages.views
import
SuccessMessageMixin
from
django.db.models
import
Q
from
django.http
import
HttpResponseRedirect
from
django.shortcuts
import
get_object_or_404
,
reverse
from
django.u
rls
import
reverse_lazy
from
django.shortcuts
import
get_object_or_404
,
reverse
,
redirect
from
django.u
tils.decorators
import
method_decorator
from
django.utils.translation
import
ugettext
as
_
from
django.urls
import
reverse_lazy
from
django.views.decorators.cache
import
never_cache
from
django.views.decorators.csrf
import
csrf_protect
from
django.views.decorators.debug
import
sensitive_post_parameters
from
django.views.generic.base
import
TemplateView
from
django.views.generic.list
import
ListView
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
UpdateView
from
django.views.generic.edit
import
CreateView
,
DeleteView
,
UpdateView
,
FormView
from
django.views.generic.detail
import
DetailView
from
common.utils
import
get_object_or_none
from
.models
import
User
,
UserGroup
from
.forms
import
UserAddForm
,
UserUpdateForm
,
UserGroupForm
from
.forms
import
UserAddForm
,
UserUpdateForm
,
UserGroupForm
,
UserLoginForm
from
.utils
import
AdminUserRequiredMixin
,
user_add_success_next
,
send_reset_password_mail
logger
=
logging
.
getLogger
(
'jumpserver.users.views'
)
@method_decorator
(
sensitive_post_parameters
(),
name
=
'dispatch'
)
@method_decorator
(
csrf_protect
,
name
=
'dispatch'
)
@method_decorator
(
never_cache
,
name
=
'dispatch'
)
class
UserLoginView
(
FormView
):
template_name
=
'users/login.html'
form_class
=
UserLoginForm
redirect_field_name
=
'next'
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
if
request
.
user
.
is_staff
:
return
redirect
(
request
.
POST
.
get
(
self
.
redirect_field_name
,
reverse
(
'index'
)))
return
self
.
render_to_response
(
self
.
get_context_data
(
**
kwargs
))
def
form_valid
(
self
,
form
):
auth_login
(
self
.
request
,
form
.
get_user
())
return
redirect
(
self
.
request
.
POST
.
get
(
self
.
redirect_field_name
,
reverse
(
'index'
)))
@method_decorator
(
never_cache
,
name
=
'dispatch'
)
class
UserLogoutView
(
TemplateView
):
template_name
=
'common/flash_message_standalone.html'
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
auth_logout
(
request
)
return
super
(
UserLogoutView
,
self
)
.
get
(
request
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
{
'title'
:
_
(
'Logout success'
),
'messages'
:
_
(
'Logout success, return login page'
),
'redirect_url'
:
reverse
(
'users:login'
),
'auto_redirect'
:
True
,
}
kwargs
.
update
(
context
)
return
super
(
UserLogoutView
,
self
)
.
get_context_data
(
**
kwargs
)
class
UserListView
(
AdminUserRequiredMixin
,
ListView
):
model
=
User
paginate_by
=
settings
.
CONFIG
.
DISPLAY_PER_PAGE
...
...
@@ -56,7 +98,7 @@ class UserAddView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
form_class
=
UserAddForm
template_name
=
'users/user_add.html'
success_url
=
reverse_lazy
(
'users:user-list'
)
success_message
=
_
(
'Create user<a href="
%
s">
%
s</a> success.'
)
success_message
=
_
(
'Create user
<a href="
%
s">
%
s</a> success.'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
UserAddView
,
self
)
.
get_context_data
(
**
kwargs
)
...
...
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