Fix token login
This commit is contained in:
parent
299016c965
commit
4eacd8c13b
|
@ -2,8 +2,8 @@ global select
|
|||
import select
|
||||
global time
|
||||
import time
|
||||
global binascii
|
||||
import binascii
|
||||
global codecs
|
||||
import codecs
|
||||
|
||||
global clientLoopIn
|
||||
def clientLoopIn(self):
|
||||
|
@ -51,13 +51,12 @@ def clientLoopIn(self):
|
|||
q = queue.Queue()
|
||||
setClientData(self.cID,"queue",q)
|
||||
setClientData(self.cID,"active",False)
|
||||
token = os.urandom(tokenLength)
|
||||
token = codecs.encode(os.urandom(tokenLength),"hex")
|
||||
setClientData(self.cID,"token",token)
|
||||
|
||||
if cmd[0] == "token":
|
||||
if not authenticate(args["user"],args["user-password"]): return
|
||||
with clientDataLock:
|
||||
setClientData(self.cID,"active",True)
|
||||
with clientsLock:
|
||||
for client in clients:
|
||||
if getClientData(client,"type") != "token": continue
|
||||
|
@ -65,9 +64,10 @@ def clientLoopIn(self):
|
|||
if getClientData(client,"active") != True: continue
|
||||
setClientData(client,"active",False)
|
||||
getClientData(client,"queue").put(None)
|
||||
setClientData(self.cID,"active",True)
|
||||
|
||||
ttimeout = time.monotonic()
|
||||
self.connection.sendall(binascii.hexlify(token))
|
||||
self.connection.sendall(token)
|
||||
self.connection.close()
|
||||
ttimeout = tokenTimeout - (time.monotonic() - ttimeout)
|
||||
if ttimeout <= 0: return
|
||||
|
@ -83,13 +83,13 @@ def clientLoopIn(self):
|
|||
else:
|
||||
tokenAuthed = False
|
||||
with clientDataLock:
|
||||
args["token"] = bytes.fromhex(args["token"])
|
||||
args["token"] = args["token"].encode("ascii")
|
||||
with clientsLock:
|
||||
for client in clients:
|
||||
if getClientData(client,"type") != "token": continue
|
||||
if getClientData(client,"args")["user"] != args["user"]: continue
|
||||
if getClientData(client,"active") != True: continue
|
||||
if getClientData(client,"token") != token: return
|
||||
if getClientData(client,"token") != args["token"]: return
|
||||
tokenAuthed = True
|
||||
break
|
||||
if not tokenAuthed: return
|
||||
|
|
Loading…
Reference in New Issue