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):
fields
=
[
"two_factor_secret"
,
]
class
DisableTwoFactorForm
(
ModelForm
):
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
):
class
TwoFactorConfirmationForm
(
forms
.
Form
):
confirmation_code
=
forms
.
CharField
(
label
=
_
(
'Confirmation code'
),
help_text
=
_
(
"Get the code from your authenticator to disable "
...
...
@@ -1696,7 +1676,7 @@ class TwoFactorAuthForm(forms.Form):
def
__init__
(
self
,
user
,
*
args
,
**
kwargs
):
self
.
user
=
user
super
(
TwoFactor
Auth
Form
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
TwoFactor
Confirmation
Form
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
clean_confirmation_code
(
self
):
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
from
..forms
import
(
CircleAuthenticationForm
,
MyProfileForm
,
UserCreationForm
,
UnsubscribeForm
,
UserKeyForm
,
CirclePasswordChangeForm
,
ConnectCommandForm
,
UserListSearchForm
,
UserEditForm
,
TwoFactorForm
,
DisableTwoFactorForm
,
TwoFactorAuthForm
,
UserListSearchForm
,
UserEditForm
,
TwoFactorForm
,
TwoFactorConfirmationForm
,
)
from
..models
import
Profile
,
GroupProfile
,
ConnectCommand
from
..tables
import
(
...
...
@@ -590,21 +589,31 @@ class EnableTwoFactorView(LoginRequiredMixin, UpdateView):
return
ctx
class
DisableTwoFactorView
(
LoginRequiredMixin
,
UpdateView
):
model
=
Profile
form_class
=
DisableTwoFactorForm
class
DisableTwoFactorView
(
LoginRequiredMixin
,
FormView
):
form_class
=
TwoFactorConfirmationForm
template_name
=
"dashboard/disable-two-factor.html"
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
():
raise
PermissionDenied
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
):
form_class
=
TwoFactor
Auth
Form
form_class
=
TwoFactor
Confirmation
Form
template_name
=
"registration/two-factor-login.html"
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