layout=dbc.Container([html.Br(),dbc.Container([dcc.Location(id="urlLogin",pathname="/login",refresh=True),html.Div([dbc.Container(html.Img(src="/assets/dash-logo-stripe.svg",className="center"),),dbc.Container(id="loginType",children=[dcc.Input(placeholder="Enter your username",type="text",id="usernameBox",className="form-control",n_submit=0,),html.Br(),dcc.Input(placeholder="Enter your password",type="password",id="passwordBox",className="form-control",n_submit=0,),html.Br(),html.Button(children="Login",n_clicks=0,type="submit",id="loginButton",className="btn btn-primary btn-lg",),html.Br(),],className="form-group",),]),],className="jumbotron",),])################################################################################# LOGIN BUTTON CLICKED / ENTER PRESSED - REDIRECT TO PAGE1 IF LOGIN DETAILS ARE CORRECT################################################################################@callback(Output("urlLogin","pathname"),Input("loginButton","n_clicks"),[State("usernameBox","value"),State("passwordBox","value")],suppress_callback_exceptions=True,)defon_login(n_clicks,username,password):ifn_clicks==0:print("first loaded")else:print("login button clicked with:",username,password)response=dash.callback_context.responseiflogin_user(response,username,password):# JUMP TO INDEX PAGEreturn"/"@callback(Output("usernameBox","className"),[Input("loginButton","n_clicks"),Input("usernameBox","n_submit"),Input("passwordBox","n_submit"),],[State("usernameBox","value"),State("passwordBox","value")],)defupdate_output(n_clicks,usernameSubmit,passwordSubmit,username,password):print("update_output by usernameBox")if(n_clicks>0)or(usernameSubmit>0)or(passwordSubmit>0):ifget_current_user()isNone:response=dash.callback_context.responseiflogin_user(response,username,password):return"form-control"else:return"form-control is-invalid"else:return"form-control is-invalid"else:return"form-control"################################################################################# LOGIN BUTTON CLICKED / ENTER PRESSED - RETURN RED BOXES IF LOGIN DETAILS INCORRECT################################################################################@callback(Output("passwordBox","className"),[Input("loginButton","n_clicks"),Input("usernameBox","n_submit"),Input("passwordBox","n_submit"),],[State("usernameBox","value"),State("passwordBox","value")],)defupdate_output(n_clicks,usernameSubmit,passwordSubmit,username,password):print("in update_output: passwordBox")if(n_clicks>0)or(usernameSubmit>0)or(passwordSubmit)>0:ifget_current_user()isNone:response=dash.callback_context.responseiflogin_user(response,username,password):return"form-control"else:return"form-control is-invalid"else:return"form-control is-invalid"else:return"form-control"
defbuild_blueprints():""" collect all routes by import controller from web/*/controller.py """_dir=os.path.dirname(os.path.abspath(__file__))package_prefix="alpha.web."forpyfileinglob.glob(f"{_dir}/**/controller.py"):sub=pyfile.replace(f"{_dir}/","").replace(".py","").replace("/",".")module_name=package_prefix+subimportlib.import_module(module_name)