-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
105 lines (89 loc) · 2.28 KB
/
index.py
File metadata and controls
105 lines (89 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from app import (
os,
time,
app,
dash,
dbc,
dcc,
html,
Input,
Output,
State,
MATCH,
ALL,
ClientsideFunction,
server,
sql
)
from pages import login, howitworks, profile, diary, exercise, utils
from onboarding import steps
navbar = dbc.NavbarSimple(
id='nav-bar-id',
children=[
dbc.NavLink("Exercises", href="/exercise"),
dbc.NavLink("Pain Diary", href="/diary"),
dbc.NavLink("Profile", href="/profile")
],
brand="Resilient.ai",
brand_href="/",
color="light",
dark=False,
sticky='top',
style={'display': 'none'}
)
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
dcc.Store(id='user-id', storage_type='memory'),
navbar,
html.Div(id='page-content'),
html.Div(id='start-button-target'),
html.Div(id='stop-button-target'),
])
def is_valid_user(user):
if user and user.get('email'):
return True
return False
def user_has_profile(user):
if not is_valid_user(user):
return False
user_hash = user.get('user-hash')
sql_statement = f"""
SELECT COUNT(profile_id) FROM profiles
WHERE user_hash = '{user_hash}'
"""
result = sql.select(sql_statement)[0][0]
if result:
return True
return False
@app.callback(Output('page-content', 'children'),
[Input('url', 'pathname'),
Input('user-id', 'data')])
def display_page(pathname, user):
if not is_valid_user(user):
return login.layout
elif not user_has_profile(user):
return steps.layout
elif pathname == '/':
return exercise.layout
elif pathname == '/exercise':
return exercise.layout
elif pathname == '/diary':
return diary.layout
elif pathname == '/profile':
return profile.layout
else:
return '404'
@app.callback(Output('nav-bar-id', 'style'),
[Input('user-id', 'data'),
Input('url', 'pathname')])
def display_page(user, pathname):
if not is_valid_user(user) or not user_has_profile(user):
return {'display': 'none'}
else:
return {'display': 'block'}
if __name__ == '__main__':
app.run_server(
host='0.0.0.0',
port=5000,
debug=True
)