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:
parent
7b27752176
commit
b45683f51b
1 changed files with 29 additions and 16 deletions
|
@ -11,24 +11,37 @@ import random
|
||||||
import ast
|
import ast
|
||||||
|
|
||||||
|
|
||||||
def cooktheticket(ticket, action, target):
|
|
||||||
if ticket == "aaa":
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
class Auth:
|
allowed = (
|
||||||
def POST(self):
|
('jon','pass1'),
|
||||||
# '{"username":"fff", "password":"azerty"}'
|
('tom','pass2')
|
||||||
data = json.loads(web.data().decode('utf-8'))
|
)
|
||||||
print(data["username"])
|
|
||||||
# Test Login
|
|
||||||
|
|
||||||
# If true generate an ticket
|
|
||||||
# use date and ip
|
class Index:
|
||||||
i = web.input(ticket='aaa')
|
def GET(self):
|
||||||
web.setcookie('ticket', i.ticket, 3600)
|
if web.ctx.env.get('HTTP_AUTHORIZATION') is not None:
|
||||||
return
|
return 'This is the index page'
|
||||||
|
else:
|
||||||
|
raise web.seeother('/login')
|
||||||
|
|
||||||
|
class Login:
|
||||||
|
def GET(self):
|
||||||
|
auth = web.ctx.env.get('HTTP_AUTHORIZATION')
|
||||||
|
authreq = False
|
||||||
|
if auth is None:
|
||||||
|
authreq = True
|
||||||
|
else:
|
||||||
|
auth = re.sub('^Basic ','',auth)
|
||||||
|
username,password = base64.decodestring(auth).split(':')
|
||||||
|
if (username,password) in allowed:
|
||||||
|
raise web.seeother('/')
|
||||||
|
else:
|
||||||
|
authreq = True
|
||||||
|
if authreq:
|
||||||
|
web.header('WWW-Authenticate','Basic realm="Auth HyperProxmox API"')
|
||||||
|
web.ctx.status = '401 Unauthorized'
|
||||||
|
return
|
||||||
|
|
||||||
""" CLASS MONGO CACHE """
|
""" CLASS MONGO CACHE """
|
||||||
class General_Search:
|
class General_Search:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue