Metadata-Version: 2.1
Name: cedashtools
Version: 0.2.0
Summary: For use in your Centric Engineers tools
Author-email: Centric Engineers <admin@centricengineers.com>
License: The MIT License (MIT)
        Copyright © 2024 Centric Engineers
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project-URL: Homepage, https://github.com/CentricEngineers/cedashtools.git
Keywords: Centric Engineers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.32.3
Requires-Dist: tenacity>=9.0.0

# 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.

```python
import dash
from dash import dcc, html, Input, Output
from cedashtools.user_access import validator
from cedashtools.user_access.website import AccessLevel


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'
    
    # run the validator 
    url_vars = validator.parse_url_params(search)  # URL vars contain user information
    access_level = validator.get_access_level(url_vars, tool_id)
    
    # provide access based on the users AccessLevel
    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
```python
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

```python
from dash import html, register_page
from cedashtools.user_access import validator
from cedashtools.user_access.website import AccessLevel

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'
    
    # run the validator on the home page 
    access_level = validator.get_access_level(url_vars, tool_id)
    
    # provide access based on the users AccessLevel
    if access_level == AccessLevel.PRO:
        layout = html.Div([html.H1(["Paid Content"])])
    else:
        layout = html.Div([html.H1(["Free Content"])])
    return layout
```
