Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
509c7ce7
authored
Aug 09, 2016
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: reuse copypasted form
parent
21207ef7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
29 deletions
+18
-29
circle/dashboard/forms.py
+2
-22
circle/dashboard/views/user.py
+16
-7
No files found.
circle/dashboard/forms.py
View file @
509c7ce7
...
@@ -1668,27 +1668,7 @@ class TwoFactorForm(ModelForm):
...
@@ -1668,27 +1668,7 @@ class TwoFactorForm(ModelForm):
fields
=
[
"two_factor_secret"
,
]
fields
=
[
"two_factor_secret"
,
]
class
DisableTwoFactorForm
(
ModelForm
):
class
TwoFactorConfirmationForm
(
forms
.
Form
):
confirmation_code
=
forms
.
CharField
(
label
=
_
(
'Confirmation code'
),
help_text
=
_
(
"Get the code from your authenticator to disable "
"two-factor authentication."
))
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
DisableTwoFactorForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'two_factor_secret'
]
.
initial
=
None
class
Meta
:
model
=
Profile
fields
=
(
'two_factor_secret'
,
'confirmation_code'
,
)
def
clean_confirmation_code
(
self
):
totp
=
pyotp
.
TOTP
(
self
.
instance
.
two_factor_secret
)
if
not
totp
.
verify
(
self
.
cleaned_data
.
get
(
'confirmation_code'
)):
raise
ValidationError
(
_
(
"Invalid confirmation code."
))
class
TwoFactorAuthForm
(
forms
.
Form
):
confirmation_code
=
forms
.
CharField
(
confirmation_code
=
forms
.
CharField
(
label
=
_
(
'Confirmation code'
),
label
=
_
(
'Confirmation code'
),
help_text
=
_
(
"Get the code from your authenticator to disable "
help_text
=
_
(
"Get the code from your authenticator to disable "
...
@@ -1696,7 +1676,7 @@ class TwoFactorAuthForm(forms.Form):
...
@@ -1696,7 +1676,7 @@ class TwoFactorAuthForm(forms.Form):
def
__init__
(
self
,
user
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
user
,
*
args
,
**
kwargs
):
self
.
user
=
user
self
.
user
=
user
super
(
TwoFactor
Auth
Form
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
TwoFactor
Confirmation
Form
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
clean_confirmation_code
(
self
):
def
clean_confirmation_code
(
self
):
totp
=
pyotp
.
TOTP
(
self
.
user
.
profile
.
two_factor_secret
)
totp
=
pyotp
.
TOTP
(
self
.
user
.
profile
.
two_factor_secret
)
...
...
circle/dashboard/views/user.py
View file @
509c7ce7
...
@@ -50,8 +50,7 @@ from vm.models import Instance, InstanceTemplate
...
@@ -50,8 +50,7 @@ from vm.models import Instance, InstanceTemplate
from
..forms
import
(
from
..forms
import
(
CircleAuthenticationForm
,
MyProfileForm
,
UserCreationForm
,
UnsubscribeForm
,
CircleAuthenticationForm
,
MyProfileForm
,
UserCreationForm
,
UnsubscribeForm
,
UserKeyForm
,
CirclePasswordChangeForm
,
ConnectCommandForm
,
UserKeyForm
,
CirclePasswordChangeForm
,
ConnectCommandForm
,
UserListSearchForm
,
UserEditForm
,
TwoFactorForm
,
DisableTwoFactorForm
,
UserListSearchForm
,
UserEditForm
,
TwoFactorForm
,
TwoFactorConfirmationForm
,
TwoFactorAuthForm
,
)
)
from
..models
import
Profile
,
GroupProfile
,
ConnectCommand
from
..models
import
Profile
,
GroupProfile
,
ConnectCommand
from
..tables
import
(
from
..tables
import
(
...
@@ -590,21 +589,31 @@ class EnableTwoFactorView(LoginRequiredMixin, UpdateView):
...
@@ -590,21 +589,31 @@ class EnableTwoFactorView(LoginRequiredMixin, UpdateView):
return
ctx
return
ctx
class
DisableTwoFactorView
(
LoginRequiredMixin
,
UpdateView
):
class
DisableTwoFactorView
(
LoginRequiredMixin
,
FormView
):
model
=
Profile
form_class
=
TwoFactorConfirmationForm
form_class
=
DisableTwoFactorForm
template_name
=
"dashboard/disable-two-factor.html"
template_name
=
"dashboard/disable-two-factor.html"
success_url
=
reverse_lazy
(
"dashboard.views.profile-preferences"
)
success_url
=
reverse_lazy
(
"dashboard.views.profile-preferences"
)
def
get_
object
(
self
,
queryset
=
None
):
def
get_
profile
(
self
,
queryset
=
None
):
if
self
.
request
.
user
.
is_anonymous
():
if
self
.
request
.
user
.
is_anonymous
():
raise
PermissionDenied
raise
PermissionDenied
return
self
.
request
.
user
.
profile
return
self
.
request
.
user
.
profile
def
get_form_kwargs
(
self
):
kwargs
=
super
(
DisableTwoFactorView
,
self
)
.
get_form_kwargs
()
kwargs
[
'user'
]
=
self
.
request
.
user
return
kwargs
def
form_valid
(
self
,
form
):
profile
=
self
.
get_profile
()
profile
.
two_factor_secret
=
""
profile
.
save
()
return
super
(
DisableTwoFactorView
,
self
)
.
form_valid
(
form
)
class
TwoFactorLoginView
(
FormView
):
class
TwoFactorLoginView
(
FormView
):
form_class
=
TwoFactor
Auth
Form
form_class
=
TwoFactor
Confirmation
Form
template_name
=
"registration/two-factor-login.html"
template_name
=
"registration/two-factor-login.html"
def
dispatch
(
self
,
*
args
,
**
kwargs
):
def
dispatch
(
self
,
*
args
,
**
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