1
0
Fork 0
mirror of https://github.com/ThomasGsp/HyperProxmox.git synced 2025-03-09 15:40:18 +00:00

Init auth API system

This commit is contained in:
Tlams 2018-03-24 23:08:47 +00:00
parent 7b27752176
commit b45683f51b

View file

@ -11,23 +11,36 @@ import random
import ast import ast
def cooktheticket(ticket, action, target):
if ticket == "aaa": allowed = (
return True ('jon','pass1'),
('tom','pass2')
)
class Index:
def GET(self):
if web.ctx.env.get('HTTP_AUTHORIZATION') is not None:
return 'This is the index page'
else: else:
return False raise web.seeother('/login')
class Auth: class Login:
def POST(self): def GET(self):
# '{"username":"fff", "password":"azerty"}' auth = web.ctx.env.get('HTTP_AUTHORIZATION')
data = json.loads(web.data().decode('utf-8')) authreq = False
print(data["username"]) if auth is None:
# Test Login authreq = True
else:
# If true generate an ticket auth = re.sub('^Basic ','',auth)
# use date and ip username,password = base64.decodestring(auth).split(':')
i = web.input(ticket='aaa') if (username,password) in allowed:
web.setcookie('ticket', i.ticket, 3600) raise web.seeother('/')
else:
authreq = True
if authreq:
web.header('WWW-Authenticate','Basic realm="Auth HyperProxmox API"')
web.ctx.status = '401 Unauthorized'
return return
""" CLASS MONGO CACHE """ """ CLASS MONGO CACHE """