Merge pull request #2394 from jaschaurbach/show-2fa-code

show otp_secret when setting up 2fa
This commit is contained in:
Mouse Reeve 2022-11-19 10:25:15 -08:00 committed by GitHub
commit fdc53d6c60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View file

@ -46,6 +46,29 @@
<div class="columns">
<section class="column is-narrow">
<figure class="m-4" id="qrcode">{{ qrcode | safe }}</figure>
<details class="details-panel box">
<summary>
<span role="heading" aria-level="3" class="title is-6">
{% trans "Use setup key" %}
<span class="details-close icon icon-x" aria-hidden="true"></span>
</span>
</summary>
<dl class="block">
<dt class="has-text-weight-bold mr-5 is-pulled-left">
{% trans "Account name:" %}
</dt>
<dd>
<code>{{ user.username }}</code>
</dd>
<dt class="has-text-weight-bold mr-5 is-pulled-left">
{% trans "Code:" %}
</dt>
<dd>
<code>{{ code | safe }}</code>
</dd>
</dl>
</details>
<div class="field">
<label class="label" for="id_otp">{% trans "Enter the code from your app:" %}</label>
{{ form.otp }}

View file

@ -35,10 +35,12 @@ class Edit2FA(View):
if not form.is_valid():
data = {"form": form}
return TemplateResponse(request, "preferences/2fa.html", data)
data = self.create_qr_code(request.user)
qr_form = forms.Confirm2FAForm()
data = {
"password_confirmed": True,
"qrcode": self.create_qr_code(request.user),
"qrcode": data[0],
"code": data[1],
"form": qr_form,
}
return TemplateResponse(request, "preferences/2fa.html", data)
@ -57,7 +59,10 @@ class Edit2FA(View):
qr_code.add_data(provisioning_url)
qr_code.make(fit=True)
img = qr_code.make_image(attrib={"fill": "black"})
return str(img.to_string(), "utf-8") # to_string() returns a byte string
return [
str(img.to_string(), "utf-8"),
otp_secret,
] # to_string() returns a byte string
@method_decorator(login_required, name="dispatch")