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():