Skip to content
__init__.py 35.3 KiB
Newer Older
    """
    current_app.logger.info( "Generate the TOTP QRcode" )
    
    if "username" in session:
        qrcode_value = "otpauth://totp/ICNML%20{}?secret={}&issuer=ICNML".format( session[ "username" ], get_secret() )
        qrcode_value = "otpauth://totp/ICNML?secret={}&issuer=ICNML".format( get_secret() )
    
    current_app.logger.debug( "Value: {}".format( qrcode_value ) )
    
    img = qrcode.make( qrcode_value )
    
    temp = StringIO()
    img.save( temp, format = "png" )
    temp.seek( 0 )
    
    return send_file( temp, mimetype = "image/png" )
    
@login_view.route( "/user/config/example_totp_qrcode.png" )
def user_totp_qrcode_example():
    qrcode_value = "otpauth://totp/ICNML%20{}?secret={}&issuer=ICNML".format( "user_name", "secretsecretsecretsecret" )
    
    img = qrcode.make( qrcode_value )
    
    temp = StringIO()
    img.save( temp, format = "png" )
    temp.seek( 0 )
    
    return send_file( temp, mimetype = "image/png" )
@login_view.route( "/user/config/totp" )
@utils.decorator.login_required
def user_totp_config():
    """
        Serve the TOTP configuration page.
    """
    current_app.logger.info( "Serve the TOTP config page" )
    
    return utils.template.my_render_template( 
        "login/users/totp.html",
        secret = get_secret()
    )