Implementing account validation on all public pages

This commit is contained in:
Dita Aji Pratama 2024-08-13 18:02:49 +07:00
parent c0efe31a0f
commit a440a32ad6
7 changed files with 204 additions and 204 deletions

View File

@ -1,6 +1,9 @@
from mako.template import Template
from config import globalvar
from bottle import request
from bottle import redirect, abort
from scripts import loggorilla
import procedure.validation as procedure_validation
class forgot:
@ -8,19 +11,22 @@ class forgot:
pass
def html(self, params):
APIADDR = "/forgot"
loggorilla.prcss(APIADDR, "Define page parameters")
active_page = "Forgot"
user_roles = [0]
beaker_session = request.environ.get('beaker.session')
jwt = beaker_session["token"] if "token" in beaker_session else None
if jwt is not None:
return redirect('/')
else:
allowed_roles = [0]
loggorilla.prcss(APIADDR, "Account validation")
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
user = user_validation['data']
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_roles,
user_roles = user['profile']['roles'],
active_page = active_page
),
footer = Template(params["mako"]["website"]['footer']).render(

View File

@ -1,36 +1,26 @@
import mysql.connector as mariadb
from mako.template import Template
from config import globalvar, database
from bottle import request
from config import globalvar
from bottle import redirect, abort
from scripts import loggorilla
import procedure.session as procedure_session
import procedure.validation as procedure_validation
class home:
def __init__(self):
self.db_main = mariadb.connect(**database.db_main)
self.cursor = self.db_main.cursor(dictionary=True)
self.user = {
"data":{
"profile":{
"username":None,
"email":None,
"phone":None,
"roles":[0]
}
}
}
pass
def html(self, params):
APIADDR = "/"
loggorilla.prcss(APIADDR, "Define page parameters")
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
self.user = procedure_session.session().user(jwt, allowed_roles) if jwt is not None else self.user
user = self.user['data']
if 'valid' in user and user['valid']['status'] == 0:
return redirect('/logout')
else:
loggorilla.prcss(APIADDR, "Account validation")
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
user = user_validation['data']
return Template(params["mako"]["website"]['index']).render(
title = globalvar.title,
header = globalvar.header,

View File

@ -1,6 +1,9 @@
from mako.template import Template
from config import globalvar
from bottle import request
from bottle import redirect, abort
from scripts import loggorilla
import procedure.validation as procedure_validation
class login:
@ -8,19 +11,22 @@ class login:
pass
def html(self, params):
APIADDR = "/login"
loggorilla.prcss(APIADDR, "Define page parameters")
active_page = "Login"
user_roles = [0]
beaker_session = request.environ.get('beaker.session')
jwt = beaker_session["token"] if "token" in beaker_session else None
if jwt is not None:
return redirect('/')
else:
allowed_roles = [0]
loggorilla.prcss(APIADDR, "Account validation")
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
user = user_validation['data']
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_roles,
user_roles = user['profile']['roles'],
active_page = active_page
),
footer = Template(params["mako"]["website"]['footer']).render(

View File

@ -1,33 +1,26 @@
from mako.template import Template
from config import globalvar
from bottle import request
from bottle import redirect, abort
from scripts import loggorilla
import procedure.session as procedure_session
import procedure.validation as procedure_validation
class notme:
def __init__(self):
self.user = {
"data":{
"profile":{
"username":None,
"email":None,
"phone":None,
"roles":[0]
}
}
}
pass
def html(self, params):
active_page = None
APIADDR = "/notme"
loggorilla.prcss(APIADDR, "Define page parameters")
active_page = "Not Me"
allowed_roles = [0,1,2,3]
beaker_session = request.environ.get('beaker.session')
jwt = beaker_session["token"] if "token" in beaker_session else None
self.user = procedure_session.session().user(jwt, allowed_roles) if jwt is not None else self.user
user = self.user['data']
if 'valid' in user and user['valid']['status'] == 0:
return redirect('/logout')
else:
loggorilla.prcss(APIADDR, "Account validation")
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
user = user_validation['data']
return Template(params["mako"]["website"]['index']).render(
title = globalvar.title,
header = globalvar.header,

View File

@ -1,6 +1,9 @@
from mako.template import Template
from config import globalvar
from bottle import request
from bottle import redirect, abort
from scripts import loggorilla
import procedure.validation as procedure_validation
class register:
@ -8,20 +11,23 @@ class register:
pass
def html(self, params):
roles = params["roles"]
APIADDR = "/register"
loggorilla.prcss(APIADDR, "Define page parameters")
active_page = "Register"
user_roles = [0]
beaker_session = request.environ.get('beaker.session')
jwt = beaker_session["token"] if "token" in beaker_session else None
if jwt is not None:
return redirect('/')
else:
allowed_roles = [0]
roles = params["roles"]
loggorilla.prcss(APIADDR, "Account validation")
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
user = user_validation['data']
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_roles,
user_roles = user['profile']['roles'],
active_page = active_page
),
footer = Template(params["mako"]["website"]['footer']).render(

View File

@ -1,6 +1,9 @@
from mako.template import Template
from config import globalvar
from bottle import request
from bottle import redirect, abort
from scripts import loggorilla
import procedure.validation as procedure_validation
class reset:
@ -8,19 +11,22 @@ class reset:
pass
def html(self, params):
APIADDR = "/reset"
loggorilla.prcss(APIADDR, "Define page parameters")
active_page = "Reset"
user_roles = [0]
beaker_session = request.environ.get('beaker.session')
jwt = beaker_session["token"] if "token" in beaker_session else None
if jwt is not None:
return redirect('/')
else:
allowed_roles = [0]
loggorilla.prcss(APIADDR, "Account validation")
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
user = user_validation['data']
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_roles,
user_roles = user['profile']['roles'],
active_page = active_page
),
footer = Template(params["mako"]["website"]['footer']).render(

View File

@ -1,33 +1,26 @@
from mako.template import Template
from config import globalvar
from bottle import request
from bottle import redirect, abort
from scripts import loggorilla
import procedure.session as procedure_session
import procedure.validation as procedure_validation
class verify:
def __init__(self):
self.user = {
"data":{
"profile":{
"username":None,
"email":None,
"phone":None,
"roles":[0]
}
}
}
pass
def html(self, params):
active_page = None
allowed_roles = [0,1,2,3]
beaker_session = request.environ.get('beaker.session')
jwt = beaker_session["token"] if "token" in beaker_session else None
self.user = procedure_session.session().user(jwt, allowed_roles) if jwt is not None else self.user
user = self.user['data']
if 'valid' in user and user['valid']['status'] == 0:
return redirect('/logout')
else:
APIADDR = "/verify"
loggorilla.prcss(APIADDR, "Define page parameters")
active_page = "Verify"
allowed_roles = [0]
loggorilla.prcss(APIADDR, "Account validation")
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles)
user = user_validation['data']
return Template(params["mako"]["website"]['index']).render(
title = globalvar.title,
header = globalvar.header,