chg: [create user] new account qr code

This commit is contained in:
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): 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) 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): def create_qr_code(content):
uri = get_user_otp_uri(user_id, instance_name) qrcode = segno.make_qr(content)
qrcode = segno.make_qr(uri)
buff = BytesIO() buff = BytesIO()
qrcode.save(buff, kind='png', scale=10) qrcode.save(buff, kind='png', scale=10)
return b64encode(buff.getvalue()).decode() return b64encode(buff.getvalue()).decode()
# qrcode.save('qrcode.png', scale=10) # 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): def get_user_hotp_code(user_id):
hotp = _get_hotp(get_user_otp_secret(user_id)) hotp = _get_hotp(get_user_otp_secret(user_id))
counter = get_user_hotp_counter(user_id) counter = get_user_hotp_counter(user_id)

View file

@ -279,7 +279,9 @@ def create_user_post():
edit = False edit = False
ail_users.api_create_user(admin_id, request.access_route[0], request.user_agent, email, password, org_uuid, role, enable_2_fa) 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} 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: else:
return render_template("create_user.html", all_roles=all_roles, meta={}, acl_admin=True) return render_template("create_user.html", all_roles=all_roles, meta={}, acl_admin=True)

View file

@ -39,6 +39,7 @@
<div class="card-body"> <div class="card-body">
<p>User: {{new_user['email']}}</p> <p>User: {{new_user['email']}}</p>
<p>Password: {{new_user['password']}}</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> <a href="{{url_for('settings_b.users_list')}}" class="btn btn-primary"><i class="fas fa-eye-slash"></i> Hide</a>
</div> </div>
</div> </div>