Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change "Refresh" to "Edit" 2FA on profile page #2271

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dmoj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

path('2fa/', two_factor.TwoFactorLoginView.as_view(), name='login_2fa'),
path('2fa/enable/', two_factor.TOTPEnableView.as_view(), name='enable_2fa'),
path('2fa/refresh/', two_factor.TOTPRefreshView.as_view(), name='refresh_2fa'),
path('2fa/edit/', two_factor.TOTPEditView.as_view(), name='edit_2fa'),
path('2fa/disable/', two_factor.TOTPDisableView.as_view(), name='disable_2fa'),
path('2fa/webauthn/attest/', two_factor.WebAuthnAttestationView.as_view(), name='webauthn_attest'),
path('2fa/webauthn/assert/', two_factor.WebAuthnAttestView.as_view(), name='webauthn_assert'),
Expand Down
12 changes: 6 additions & 6 deletions judge/views/two_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TOTPEnableView(TOTPView):
title = gettext_lazy('Enable Two-factor Authentication')
form_class = TOTPEnableForm
template_name = 'registration/totp_enable.html'
is_refresh = False
is_edit = False

def get(self, request, *args, **kwargs):
profile = self.profile
Expand All @@ -76,9 +76,9 @@ def post(self, request, *args, **kwargs):
def get_context_data(self, **kwargs):
context = super(TOTPEnableView, self).get_context_data(**kwargs)
context['totp_key'] = self.request.session['totp_enable_key']
context['scratch_codes'] = [] if self.is_refresh else json.loads(self.profile.scratch_codes)
context['scratch_codes'] = [] if self.is_edit else json.loads(self.profile.scratch_codes)
context['qr_code'] = self.render_qr_code(self.request.user.username, context['totp_key'])
context['is_refresh'] = self.is_refresh
context['is_edit'] = self.is_edit
context['is_hardcore'] = settings.DMOJ_2FA_HARDCORE
return context

Expand Down Expand Up @@ -106,9 +106,9 @@ def render_qr_code(cls, username, key):
return 'data:image/png;base64,' + base64.b64encode(buf.getvalue()).decode('ascii')


class TOTPRefreshView(TOTPEnableView):
title = gettext_lazy('Refresh Two-factor Authentication')
is_refresh = True
class TOTPEditView(TOTPEnableView):
title = gettext_lazy('Edit Two-factor Authentication')
is_edit = True

def check_skip(self):
return not self.profile.is_totp_enabled
Expand Down
4 changes: 2 additions & 2 deletions templates/registration/totp_enable.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
<span class="fullwidth">{{ form.totp_or_scratch_code }}</span>
</div>
<button style="margin-top: 0.5em" class="button" type="submit">
{%- if is_refresh -%}
{{ _('Refresh Two Factor Authentication') }}
{%- if is_edit -%}
{{ _('Edit Two Factor Authentication') }}
{%- else -%}
{{ _('Enable Two Factor Authentication') }}
{%- endif -%}
Expand Down
2 changes: 1 addition & 1 deletion templates/user/edit-profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
<a href="{{ url('disable_2fa') }}"
class="button inline-button">{{ _('Disable') }}</a>
{% endif %}
<a href="{{ url('refresh_2fa') }}" class="button inline-button">{{ _('Refresh') }}</a>
<a href="{{ url('edit_2fa') }}" class="button inline-button">{{ _('Edit') }}</a>
</div>
<div class="block-header grayed">
{{ _('Scratch codes:') }}
Expand Down