2024-06-17 17:33:29 +07:00
import mysql . connector as mariadb
from mako . template import Template
from config import globalvar , database
2024-06-19 04:36:26 +07:00
from bottle import request
import procedure . session as procedure_session
2024-06-17 12:43:51 +07:00
2024-06-17 17:33:29 +07:00
class home :
2024-06-17 12:43:51 +07:00
def __init__ ( self ) :
2024-06-17 17:33:29 +07:00
self . db_main = mariadb . connect ( * * database . db_main )
self . cursor = self . db_main . cursor ( dictionary = True )
2024-06-19 04:36:26 +07:00
self . user = {
" data " : {
" profile " : {
" username " : None ,
" email " : None ,
" phone " : None ,
" roles " : [ 0 ]
}
}
}
2024-06-17 12:43:51 +07:00
def html ( self , params ) :
2024-06-19 04:36:26 +07:00
active_page = " Home "
allowed_roles = [ 0 , 1 , 2 , 3 ]
beaker_session = request . environ . get ( ' beaker.session ' )
jwt = beaker_session [ " token " ] if " token " in beaker_session else None
2024-06-19 06:53:25 +07:00
self . user = procedure_session . session ( ) . user ( jwt , allowed_roles ) if jwt is not None else self . user
2024-06-19 04:36:26 +07:00
user = self . user [ ' data ' ]
2024-06-19 06:53:25 +07:00
if ' valid ' in user and user [ ' valid ' ] [ ' status ' ] == 0 :
return redirect ( ' /logout ' )
else :
return Template ( params [ " mako " ] [ " website " ] [ ' index ' ] ) . render (
title = globalvar . title ,
header = globalvar . header ,
navbar = Template ( params [ " mako " ] [ " website " ] [ ' navbar ' ] ) . render (
menu = globalvar . menu [ ' public ' ] [ ' navbar ' ] ,
user_roles = user [ ' profile ' ] [ ' roles ' ] ,
active_page = active_page
) ,
footer = Template ( params [ " mako " ] [ " website " ] [ ' footer ' ] ) . render (
copyright = globalvar . copyright ,
) ,
container = Template ( params [ " mako " ] [ " website " ] [ ' container ' ] ) . render (
greeting = f " Welcome to your new web application! This placeholder page is here to let you know that your web framework is successfully set up and ready to go. Now, it ' s time to start building your project. Dive into the documentation to explore the features and capabilities at your disposal. " ,
user = user
)
2024-06-17 12:43:51 +07:00
)