Authsquare extra: Roles list + Bruno
This commit is contained in:
parent
04d65a09f4
commit
eab02c9e7a
28
bruno/Authsquare/Extra/Roles/List.bru
Normal file
28
bruno/Authsquare/Extra/Roles/List.bru
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
meta {
|
||||||
|
name: List
|
||||||
|
type: http
|
||||||
|
seq: 9
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
url: http://localhost:11000/api/auth/roles/:alder
|
||||||
|
body: none
|
||||||
|
auth: none
|
||||||
|
}
|
||||||
|
|
||||||
|
params:path {
|
||||||
|
alder: list
|
||||||
|
}
|
||||||
|
|
||||||
|
headers {
|
||||||
|
Authorization: Bearer xx.xx.xx
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"roles":[2],
|
||||||
|
"email":"user2@domain.com",
|
||||||
|
"username":"admin2",
|
||||||
|
"password":"mypassword"
|
||||||
|
}
|
||||||
|
}
|
8
bruno/Authsquare/Extra/Roles/folder.bru
Normal file
8
bruno/Authsquare/Extra/Roles/folder.bru
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
meta {
|
||||||
|
name: Roles
|
||||||
|
seq: 1
|
||||||
|
}
|
||||||
|
|
||||||
|
auth {
|
||||||
|
mode: inherit
|
||||||
|
}
|
8
bruno/Authsquare/Extra/folder.bru
Normal file
8
bruno/Authsquare/Extra/folder.bru
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
meta {
|
||||||
|
name: Extra
|
||||||
|
seq: 8
|
||||||
|
}
|
||||||
|
|
||||||
|
auth {
|
||||||
|
mode: inherit
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
meta {
|
meta {
|
||||||
name: Logout
|
name: Logout
|
||||||
type: http
|
type: http
|
||||||
seq: 8
|
seq: 9
|
||||||
}
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
|
@ -8,9 +8,9 @@ menu = {
|
|||||||
"roles":[0,1,2,3]
|
"roles":[0,1,2,3]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name":"Dashboard",
|
"name":"Roles",
|
||||||
"target":"_self",
|
"target":"_self",
|
||||||
"href":"/dashboard",
|
"href":"/roles",
|
||||||
"roles":[1,2]
|
"roles":[1,2]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
11
handler.py
11
handler.py
@ -22,6 +22,8 @@ import modules.public.login as public_login
|
|||||||
import modules.public.forgot as public_forgot
|
import modules.public.forgot as public_forgot
|
||||||
import modules.public.reset as public_reset
|
import modules.public.reset as public_reset
|
||||||
|
|
||||||
|
import modules.public.roles as public_roles
|
||||||
|
|
||||||
import modules.api.auth as api_auth
|
import modules.api.auth as api_auth
|
||||||
import modules.api.roles as api_auth_roles
|
import modules.api.roles as api_auth_roles
|
||||||
import modules.api.users as api_auth_users
|
import modules.api.users as api_auth_users
|
||||||
@ -118,6 +120,15 @@ def index():
|
|||||||
else:
|
else:
|
||||||
redirect('/')
|
redirect('/')
|
||||||
|
|
||||||
|
@app.route('/roles')
|
||||||
|
def index():
|
||||||
|
params = {
|
||||||
|
"mako" : {
|
||||||
|
"website" : template_public.main(directory.page["public"], "roles")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return public_roles.roles().html(params)
|
||||||
|
|
||||||
@app.route('/api/auth/register/<roles>', method=['OPTIONS', 'POST'])
|
@app.route('/api/auth/register/<roles>', method=['OPTIONS', 'POST'])
|
||||||
def index(roles):
|
def index(roles):
|
||||||
try:
|
try:
|
||||||
|
@ -48,17 +48,19 @@ class roles:
|
|||||||
APIADDR = "/api/auth/roles/list"
|
APIADDR = "/api/auth/roles/list"
|
||||||
response = {}
|
response = {}
|
||||||
|
|
||||||
loggorilla.prcss(APIADDR, "Define parameters")
|
|
||||||
token = params["token" ]
|
|
||||||
allowed_roles = [1,2] # Roles list is public or not?
|
|
||||||
|
|
||||||
loggorilla.prcss(APIADDR, "Account validation")
|
|
||||||
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles, token)
|
|
||||||
user = user_validation['data']
|
|
||||||
|
|
||||||
self.cursor.execute("BEGIN;")
|
self.cursor.execute("BEGIN;")
|
||||||
try:
|
try:
|
||||||
self.cursor.execute("select auth_roles.id, auth_roles.name, (select count(*) from auth_profile_roles apr where apr.roles = auth_roles.id) AS `count` from auth_roles;")
|
loggorilla.prcss(APIADDR, "Extract the Authorization token from Header")
|
||||||
|
auth_header = request.get_header('Authorization')
|
||||||
|
token = auth_header.split(' ')[1]
|
||||||
|
loggorilla.prcss(APIADDR, "Define parameters")
|
||||||
|
allowed_roles = [1,2] # Roles list is public or not?
|
||||||
|
|
||||||
|
loggorilla.prcss(APIADDR, "Account validation")
|
||||||
|
user_validation = procedure_validation.validation().account(APIADDR, allowed_roles, token)
|
||||||
|
user = user_validation['data']
|
||||||
|
|
||||||
|
self.cursor.execute("select auth_roles.id, auth_roles.name, (select count(*) from auth_profile_roles apr where apr.roles = auth_roles.id) AS `count` from auth_roles order by auth_roles.id;")
|
||||||
r_roles = self.cursor.fetchall()
|
r_roles = self.cursor.fetchall()
|
||||||
response["status" ] = "success"
|
response["status" ] = "success"
|
||||||
response["desc" ] = "data collected"
|
response["desc" ] = "data collected"
|
||||||
|
37
modules/public/roles.py
Normal file
37
modules/public/roles.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
from mako.template import Template
|
||||||
|
from config import globalvar, navigation
|
||||||
|
from scripts import loggorilla
|
||||||
|
|
||||||
|
import procedure.validation as procedure_validation
|
||||||
|
|
||||||
|
class roles:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def html(self, params):
|
||||||
|
APIADDR = "/roles"
|
||||||
|
|
||||||
|
loggorilla.prcss(APIADDR, "Define page parameters")
|
||||||
|
active_page = "Roles"
|
||||||
|
allowed_roles = [1,2]
|
||||||
|
|
||||||
|
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 = navigation.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(
|
||||||
|
token = user['token']
|
||||||
|
)
|
||||||
|
)
|
5
pages/public/roles.html
Normal file
5
pages/public/roles.html
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<input type="hidden" id="form-token" value="${token}">
|
||||||
|
<ul id="lister"></ul>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="/js/carrack.js"></script>
|
||||||
|
<script type="text/javascript" src="/js/roles.js"></script>
|
19
static/js/roles.js
Normal file
19
static/js/roles.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
var token = document.getElementById("form-token" ).value;
|
||||||
|
const lister = document.getElementById("lister");
|
||||||
|
|
||||||
|
sendHttpRequest("/api/auth/roles/list", "POST", null,
|
||||||
|
function (error, response) {
|
||||||
|
if (error) console.error("Error:", error);
|
||||||
|
else {
|
||||||
|
console.log("JSON Response:", response);
|
||||||
|
const ls = JSON.parse(response);
|
||||||
|
|
||||||
|
ls.data.forEach(data => {
|
||||||
|
const postElement = document.createElement("div");
|
||||||
|
postElement.innerHTML = `<li>[${data.id}] ${data.name} - Total user(s): ${data.count}</li>`;
|
||||||
|
lister.appendChild(postElement);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, "application/json", `Bearer ${token}`
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user