diff --git a/bin/lib/ail_users.py b/bin/lib/ail_users.py index 90d3ae7c..2432af91 100755 --- a/bin/lib/ail_users.py +++ b/bin/lib/ail_users.py @@ -215,14 +215,17 @@ def delete_user_otp(user_id): def get_user_otp_uri(user_id, instance_name): return pyotp.totp.TOTP(get_user_otp_secret(user_id)).provisioning_uri(name=user_id, issuer_name=instance_name) -def get_user_otp_qr_code(user_id, instance_name): - uri = get_user_otp_uri(user_id, instance_name) - qrcode = segno.make_qr(uri) +def create_qr_code(content): + qrcode = segno.make_qr(content) buff = BytesIO() qrcode.save(buff, kind='png', scale=10) return b64encode(buff.getvalue()).decode() # qrcode.save('qrcode.png', scale=10) +def get_user_otp_qr_code(user_id, instance_name): + uri = get_user_otp_uri(user_id, instance_name) + return create_qr_code(uri) + def get_user_hotp_code(user_id): hotp = _get_hotp(get_user_otp_secret(user_id)) counter = get_user_hotp_counter(user_id) diff --git a/var/www/blueprints/settings_b.py b/var/www/blueprints/settings_b.py index 024ecefe..3e1bdb63 100644 --- a/var/www/blueprints/settings_b.py +++ b/var/www/blueprints/settings_b.py @@ -279,7 +279,9 @@ def create_user_post(): edit = False ail_users.api_create_user(admin_id, request.access_route[0], request.user_agent, email, password, org_uuid, role, enable_2_fa) new_user = {'email': email, 'password': str_password, 'org': org_uuid, 'otp': enable_2_fa, 'edited': edit} - return render_template("create_user.html", new_user=new_user, meta={}, all_roles=all_roles, acl_admin=True) + qr_code = ail_users.create_qr_code(password) + return render_template("create_user.html", new_user=new_user, meta={}, qr_code=qr_code, + all_roles=all_roles, acl_admin=True) else: return render_template("create_user.html", all_roles=all_roles, meta={}, acl_admin=True) diff --git a/var/www/templates/settings/create_user.html b/var/www/templates/settings/create_user.html index 96ceea7b..89c5ec19 100644 --- a/var/www/templates/settings/create_user.html +++ b/var/www/templates/settings/create_user.html @@ -39,6 +39,7 @@