Skip to main content

For use in your Centric Engineers tools

Project description

Summary

Use this package with your Centric Engineers tools to acquire user access levels from CentricEngineers.com.

Usage

Single Page Dash App

In a simple single page Dash-Plotly application.

import dash
from dash import dcc, html, Input, Output
from cedashtools.user_access import validation, encryption
from cedashtools.user_access.website import AccessLevel, ToolPayload, ce_validation_url


app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Location(id='url', refresh=False),
    html.Div(id='content'),
])


@app.callback(Output('content', 'children'),
              Input('url', 'search'))
def display_content_based_on_access(search: str):
    # Tool ID provided by centricengineers.com
    tool_id = 'a_tool_id'
    
    # encryption keys can be specified by file path
    encryption.keys.PUBLIC_KEY_FILE_PATH = r'/Path/To/File/Containing/Public_Key'
    encryption.keys.PRIVATE_KEY_FILE_PATH = r'/Path/To/File/Containing/Private_Key'
    
    # get user's access level
    user_id = validation.get_user_id(validation.parse_url_params(search))  # URL vars contain user information
    payload = ToolPayload(user_id, tool_id)
    access_level = validation.get_access_level(ce_validation_url, payload, encryption.keys)
    
    # display content based on access level
    if access_level >= AccessLevel.PRO:
        layout = html.Div([html.H1(["Paid Content"])])
    else:
        layout = html.Div([html.H1(["Free Content"])])
    return layout

Mult-Page Dash App

In a multi-page Dash-Plotly application (using pages).

app.py

import dash
from dash import html, dcc

APP_TITLE = "Dash App"  

app = dash.Dash(
    __name__,
    title=APP_TITLE,
    use_pages=True,  # New in Dash 2.7 - Allows us to register pages
)

app.layout = html.Div([dash.page_container])

server = app.server

if __name__ == '__main__':
    app.run_server(debug=True)

home.py

from dash import html, register_page
from cedashtools.user_access import validation, encryption
from cedashtools.user_access.website import AccessLevel, ToolPayload, ce_validation_url

register_page(
    __name__,
    name='Home',
    path='/'
)


def layout(**url_vars):  # URL vars contain user information
    
    # Tool ID provided by CentricEngineers.com
    tool_id = 'a_tool_id'

    # encryption keys can also be specified by string
    encryption.keys.PUBLIC_KEY_STRING = '-----BEGIN PUBLIC KEY-----FakePublicKey-----END PUBLIC KEY-----'
    encryption.keys.PRIVATE_KEY_STRING = '-----BEGIN PRIVATE KEY-----FakePrivateKey-----END PRIVATE KEY-----'

    # get user's access level
    user_id = validation.get_user_id(url_vars)
    payload = ToolPayload(user_id, tool_id)
    access_level = validation.get_access_level(ce_validation_url, payload, encryption.keys)

    # display content based on access level
    if access_level >= AccessLevel.PRO:
        layout = html.Div([html.H1(["Paid Content"])])
    else:
        layout = html.Div([html.H1(["Free Content"])])
    return layout

Change Log

Version 0.3.0 (10-18-2024)

  • Added cryptography support
  • Refactored API

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cedashtools-0.3.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cedashtools-0.3.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file cedashtools-0.3.0.tar.gz.

File metadata

  • Download URL: cedashtools-0.3.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.15

File hashes

Hashes for cedashtools-0.3.0.tar.gz
Algorithm Hash digest
SHA256 12a68ea4e1c3c8eee1bde5a2fa1f09543b044906e579f5ac7171b7d3baf90344
MD5 4eb03ca5ab6e0c7559dff019fe8f7fa1
BLAKE2b-256 292f22643c8cf1707a4f9e29a1847fac5ae4ff8e4019aa533774a12c9be91f1b

See more details on using hashes here.

File details

Details for the file cedashtools-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: cedashtools-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.15

File hashes

Hashes for cedashtools-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae3784ac27620318cdb40d623487f3dd919a56a3ce63c74d444c7ea131e26046
MD5 66d96fa6a5984b9e16bd0ff3e81f2ff2
BLAKE2b-256 53c7d3f2a4c4ebc70d2101a02adf0070a809795a2b2eed1b04ec76032bc71b69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page