Add deltachat credentials page with QR code, update translation strings

This commit is contained in:
Ana Custura 2026-03-31 12:46:38 +01:00
parent 585458986f
commit eeb387d694
6 changed files with 147 additions and 59 deletions

View file

@ -1,3 +1,6 @@
import io
import re
from app import app
from flask import render_template, flash, redirect, url_for, send_file
from app.forms import LoginForm, SettingsForm, Step1Form, Step2Form, Step3Form, Step4Form
@ -25,7 +28,10 @@ RASPAP_INSTALLED = os.path.exists("/var/www/html/raspap")
def gen_username() -> str:
words = top_n_list("en", 5000)
prefix = random.randint(1000, 9999)
return f"{random.choice(words)}{random.choice(words)}{prefix}"
word1 = re.sub(r'[^a-zA-Z ]', '', random.choice(words))
word2 = re.sub(r'[^a-zA-Z ]', '', random.choice(words))
print(word1, word2)
return f"{word1}{word2}{prefix}"
def gen_password() -> str:
characters = string.ascii_letters + string.digits
@ -346,15 +352,17 @@ def messaging():
return render_template('messaging.html', get_setting=get_setting)
@app.route("/deltachat_credentials", methods=["POST"])
def generate_random_deltachat_credentials():
def deltachat_credentials():
ip = app.config['BUTTERBOX_DEFAULT_IP']
username = gen_username()
password = gen_password()
flash(f"Username: {username}")
flash(f"Password: {password}")
flash(f"IP: {ip}")
return redirect(url_for("messaging"))
hostname = f"{get_setting('butterbox_hostname')}.local"
dclink = f"dclogin:{username}@{hostname}/?p={password}&v=1&ih={ip}&ip=143&sh={ip}&sp=25&is=plain&ss=plain&sc=3"
img = qrcode.make(dclink)
file_object = io.BytesIO()
img.save(file_object, 'PNG')
base64img = "data:image/png;base64," + base64.b64encode(file_object.getvalue()).decode('ascii')
return render_template('deltachat_creds.html',dclink=dclink, base64img=base64img, get_setting=get_setting)
@app.route('/share')
def share():

View file

@ -0,0 +1,24 @@
{% extends "base.html" %}
{% block content %}
<h1 class="title is-large butter-title">{{ _('Secure Messenger Account') }}</h1>
<div class="block">
<div class="block">
<p>{{ _('Scan the following QR code with a device where DeltaChat is installed:') }}</p>
</div>
<img src="{{ base64img }}"/>
</div>
<div class="block">
<div class="block"><p class="">{{ _('If your device does not have a camera, select "Create new profile" in DeltaChat, choose "Use Other Server" and find "Paste from clipboard", to paste the following link') }}:</p></div>
<pre>{{ dclink}}</pre>
</div>
<div class="block"></div>
<form action="{{ url_for('deltachat_credentials') }}" method="post">
<button type="submit" class="button is-link is-fullwidth block">
<p>{{ _("Generate new credentials") }} </p>
</button>
</form>
{% endblock %}

View file

@ -4,14 +4,14 @@
<h1 class="title is-large butter-title">{{ _('Secure Messenger') }}</h1>
<div class="block">
<p> {{ _("To use secure messaging, install Delta Chat and then return to this page to create your local offline account.")}}</p>
<p> {{ _("To use secure messaging, install Delta Chat and then create your local offline account.")}}</p>
</div>
<a href="{{ url_for('static', filename='DeltaChat_2.35.0_APKPure.apk') }}"><button class="button is-link is-fullwidth block">
<p>{{ _("Step 1") }}<br> {{ _("Download and install") }}</p>
</button>
</a>
<div class="block"></div>
<form action="{{ url_for('generate_random_deltachat_credentials') }}" method="post">
<form action="{{ url_for('deltachat_credentials') }}" method="post">
<button type="submit" class="button is-link is-fullwidth block">
<p>{{ _("Step 2") }} <br> {{ _("Create offline account") }} </p>
</button>