Authsquare extra: Users list + Bruno
This commit is contained in:
		
							parent
							
								
									f4596415b8
								
							
						
					
					
						commit
						9aa2114efb
					
				@ -1,7 +1,7 @@
 | 
				
			|||||||
meta {
 | 
					meta {
 | 
				
			||||||
  name: List
 | 
					  name: List
 | 
				
			||||||
  type: http
 | 
					  type: http
 | 
				
			||||||
  seq: 9
 | 
					  seq: 1
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
post {
 | 
					post {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										28
									
								
								bruno/Authsquare/Extra/Users/List.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								bruno/Authsquare/Extra/Users/List.bru
									
									
									
									
									
										Normal file
									
								
							@ -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"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										8
									
								
								bruno/Authsquare/Extra/Users/folder.bru
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								bruno/Authsquare/Extra/Users/folder.bru
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					meta {
 | 
				
			||||||
 | 
					  name: Users
 | 
				
			||||||
 | 
					  seq: 2
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					auth {
 | 
				
			||||||
 | 
					  mode: inherit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -13,6 +13,12 @@ menu        = {
 | 
				
			|||||||
                "href":"/roles",
 | 
					                "href":"/roles",
 | 
				
			||||||
                "roles":[1,2]
 | 
					                "roles":[1,2]
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                "name":"Users",
 | 
				
			||||||
 | 
					                "target":"_self",
 | 
				
			||||||
 | 
					                "href":"/users",
 | 
				
			||||||
 | 
					                "roles":[1,2]
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                "name":"Register",
 | 
					                "name":"Register",
 | 
				
			||||||
                "target":"_self",
 | 
					                "target":"_self",
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								handler.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								handler.py
									
									
									
									
									
								
							@ -23,6 +23,7 @@ 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.public.roles	as public_roles
 | 
				
			||||||
 | 
					import	modules.public.users	as public_users
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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
 | 
				
			||||||
@ -129,6 +130,15 @@ def index():
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    return public_roles.roles().html(params)
 | 
					    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/<roles>', method=['OPTIONS', 'POST'])
 | 
					@app.route('/api/auth/register/<roles>', method=['OPTIONS', 'POST'])
 | 
				
			||||||
def index(roles):
 | 
					def index(roles):
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
 | 
				
			|||||||
@ -18,16 +18,18 @@ class users:
 | 
				
			|||||||
        APIADDR         = "/api/auth/users/list"
 | 
					        APIADDR         = "/api/auth/users/list"
 | 
				
			||||||
        response        = {}
 | 
					        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;")
 | 
					        self.cursor.execute("BEGIN;")
 | 
				
			||||||
        try:
 | 
					        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 = []
 | 
					            r_profile = []
 | 
				
			||||||
            self.cursor.execute("select auth_profile.id, auth_profile.username, auth_profile.email, auth_profile.phone from auth_profile;")
 | 
					            self.cursor.execute("select auth_profile.id, auth_profile.username, auth_profile.email, auth_profile.phone from auth_profile;")
 | 
				
			||||||
            l1 = self.cursor.fetchall()
 | 
					            l1 = self.cursor.fetchall()
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										37
									
								
								modules/public/users.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								modules/public/users.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 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']
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
							
								
								
									
										5
									
								
								pages/public/users.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								pages/public/users.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/users.js"></script>
 | 
				
			||||||
							
								
								
									
										35
									
								
								static/js/users.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								static/js/users.js
									
									
									
									
									
										Normal file
									
								
							@ -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 => `<li>[${row2.id}] ${row2.name}</li>`).join("");
 | 
				
			||||||
 | 
					                const verificationList = row.verification.map(row2 => `<li>${row2.type}: ${row2.verified}</li>`).join("");
 | 
				
			||||||
 | 
					                itemElement.innerHTML = `
 | 
				
			||||||
 | 
					                    <li>
 | 
				
			||||||
 | 
					                        [${row.id}] ${row.username}<br>
 | 
				
			||||||
 | 
					                        Email: ${row.email}<br>
 | 
				
			||||||
 | 
					                        Phone: ${row.phone}<br>
 | 
				
			||||||
 | 
					                        Roles:
 | 
				
			||||||
 | 
					                        <ul>
 | 
				
			||||||
 | 
					                            ${rolesList}
 | 
				
			||||||
 | 
					                        </ul><br>
 | 
				
			||||||
 | 
					                        Verification:
 | 
				
			||||||
 | 
					                        <ul>
 | 
				
			||||||
 | 
					                            ${verificationList}
 | 
				
			||||||
 | 
					                        </ul>
 | 
				
			||||||
 | 
					                    </li>
 | 
				
			||||||
 | 
					                `;
 | 
				
			||||||
 | 
					                lister.appendChild(itemElement);
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }, "application/json", `Bearer ${token}`
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user