chg: [create user] new account qr code

otp
terrtia 2024-09-13 09:47:08 +02:00
parent d5b048d4b4
commit 7a67e3043f
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
3 changed files with 10 additions and 4 deletions

View File

@ -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)

View File

@ -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)

View File

@ -39,6 +39,7 @@
<div class="card-body">
<p>User: {{new_user['email']}}</p>
<p>Password: {{new_user['password']}}</p>
<img src="data:image/png;base64, {{ qr_code }}">
<a href="{{url_for('settings_b.users_list')}}" class="btn btn-primary"><i class="fas fa-eye-slash"></i> Hide</a>
</div>
</div>