-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.py
72 lines (57 loc) · 1.81 KB
/
index.py
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
from dash import dcc
from dash import html,Input, Output,State, callback
from app1 import app,server
from pages import (
dashboard,
login,
error
)
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
dcc.Store(id='login-status',storage_type='session',data=False),
dcc.Store(id='logout-status',storage_type='session',data=True),
html.Div([
html.Div(id='pageContent')
])
])
################################################################################
# HANDLE PAGE ROUTING - IF USER NOT LOGGED IN, ALWAYS RETURN TO LOGIN SCREEN
################################################################################
@callback(Output('pageContent', 'children'),
[Input('url', 'pathname'),Input('login-status','data'),Input('logout-status','data')])
def displayPage(pathname,login_status,logout_status):
if pathname == '/':
if logout_status:
return login.layout
elif login_status:
return dashboard.layout
elif pathname == '/login':
if logout_status:
return login.layout
elif login_status:
return dashboard.layout
elif pathname == '/logout':
if logout_status:
return login.layout
elif pathname == '/main':
if login_status:
return dashboard.layout
elif logout_status:
return login.layout
else:
return error.layout
@callback(
[Output('url', 'pathname'),Output('logout-status','data')],
[Input('logout-btn','n_clicks')],
[State('logout-status','data')]
)
def logout(n_clicks,status):
if n_clicks > 0:
n_clicks = 0
status = True
return ['/logout',status]
else:
status = False
return ['/main',status]
if __name__ == '__main__':
app.run_server(debug=False)