Skip to content

Commit

Permalink
Change "Refresh" to "Edit" 2FA on profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
slightlyskepticalpotat authored and kiritofeng committed Jan 6, 2024
1 parent 19e7a09 commit 18e49e0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dmoj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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 @@ -379,7 +379,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

0 comments on commit 18e49e0

Please sign in to comment.