diff --git a/bruno/Authsquare/Extra/Roles/List.bru b/bruno/Authsquare/Extra/Roles/List.bru index dbc45ac..15ab6f3 100644 --- a/bruno/Authsquare/Extra/Roles/List.bru +++ b/bruno/Authsquare/Extra/Roles/List.bru @@ -1,7 +1,7 @@ meta { name: List type: http - seq: 9 + seq: 1 } post { diff --git a/bruno/Authsquare/Extra/Users/List.bru b/bruno/Authsquare/Extra/Users/List.bru new file mode 100644 index 0000000..d88161b --- /dev/null +++ b/bruno/Authsquare/Extra/Users/List.bru @@ -0,0 +1,28 @@ +meta { + name: List + type: http + seq: 2 +} + +post { + url: http://localhost:11000/api/auth/users/: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" + } +} diff --git a/bruno/Authsquare/Extra/Users/folder.bru b/bruno/Authsquare/Extra/Users/folder.bru new file mode 100644 index 0000000..1f2a5d8 --- /dev/null +++ b/bruno/Authsquare/Extra/Users/folder.bru @@ -0,0 +1,8 @@ +meta { + name: Users + seq: 2 +} + +auth { + mode: inherit +} diff --git a/config/navigation.py b/config/navigation.py index 30cdbef..e24d004 100644 --- a/config/navigation.py +++ b/config/navigation.py @@ -13,6 +13,12 @@ menu = { "href":"/roles", "roles":[1,2] }, + { + "name":"Users", + "target":"_self", + "href":"/users", + "roles":[1,2] + }, { "name":"Register", "target":"_self", diff --git a/handler.py b/handler.py index 07f8ada..38a1379 100644 --- a/handler.py +++ b/handler.py @@ -23,6 +23,7 @@ import modules.public.forgot as public_forgot import modules.public.reset as public_reset import modules.public.roles as public_roles +import modules.public.users as public_users import modules.api.auth as api_auth import modules.api.roles as api_auth_roles @@ -128,7 +129,16 @@ def index(): } } return public_roles.roles().html(params) - + +@app.route('/users') +def index(): + params = { + "mako" : { + "website" : template_public.main(directory.page["public"], "users") + } + } + return public_users.users().html(params) + @app.route('/api/auth/register/', method=['OPTIONS', 'POST']) def index(roles): try: diff --git a/modules/api/users.py b/modules/api/users.py index 1b70049..1b6f924 100644 --- a/modules/api/users.py +++ b/modules/api/users.py @@ -18,16 +18,18 @@ class users: APIADDR = "/api/auth/users/list" response = {} - loggorilla.prcss(APIADDR, "Define parameters") - token = params["token" ] - allowed_roles = [1,2] - - loggorilla.prcss(APIADDR, "Account validation") - user_validation = procedure_validation.validation().account(APIADDR, allowed_roles, token) - user = user_validation['data'] - self.cursor.execute("BEGIN;") try: + 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'] + r_profile = [] self.cursor.execute("select auth_profile.id, auth_profile.username, auth_profile.email, auth_profile.phone from auth_profile;") l1 = self.cursor.fetchall() diff --git a/modules/public/users.py b/modules/public/users.py new file mode 100644 index 0000000..51c6841 --- /dev/null +++ b/modules/public/users.py @@ -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 users: + + def __init__(self): + pass + + def html(self, params): + APIADDR = "/users" + + loggorilla.prcss(APIADDR, "Define page parameters") + active_page = "Users" + 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'] + ) + ) diff --git a/pages/public/users.html b/pages/public/users.html new file mode 100644 index 0000000..189df73 --- /dev/null +++ b/pages/public/users.html @@ -0,0 +1,5 @@ + + + + + diff --git a/static/js/users.js b/static/js/users.js new file mode 100644 index 0000000..5541226 --- /dev/null +++ b/static/js/users.js @@ -0,0 +1,35 @@ +var token = document.getElementById("form-token" ).value; +const lister = document.getElementById("lister"); + +sendHttpRequest("/api/auth/users/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(row => { + const itemElement = document.createElement("div"); + const rolesList = row.roles.map(row2 => `
  • [${row2.id}] ${row2.name}
  • `).join(""); + const verificationList = row.verification.map(row2 => `
  • ${row2.type}: ${row2.verified}
  • `).join(""); + itemElement.innerHTML = ` +
  • + [${row.id}] ${row.username}
    + Email: ${row.email}
    + Phone: ${row.phone}
    + Roles: +
    + Verification: + +
  • + `; + lister.appendChild(itemElement); + }); + } + }, "application/json", `Bearer ${token}` +); +