add logging in as guest
This commit is contained in:
+36
-11
@@ -26,6 +26,8 @@ from api import ServerConnection
|
|||||||
|
|
||||||
server = ServerConnection()
|
server = ServerConnection()
|
||||||
|
|
||||||
|
guestLogin = False
|
||||||
|
|
||||||
def errorTxt(obj):
|
def errorTxt(obj):
|
||||||
if obj["server"]:
|
if obj["server"]:
|
||||||
return f"Server error: {obj["error"]}"
|
return f"Server error: {obj["error"]}"
|
||||||
@@ -343,10 +345,15 @@ async def mainScreen():
|
|||||||
def exit_(event):
|
def exit_(event):
|
||||||
event.app.exit()
|
event.app.exit()
|
||||||
|
|
||||||
stat = await server.status()
|
if guestLogin:
|
||||||
if stat["type"]=="error" or not stat["response"]["login"]: return
|
name = "[guest]"
|
||||||
name = stat["response"]["name"]
|
else:
|
||||||
|
stat = await server.status()
|
||||||
|
if stat["type"]=="error" or not stat["response"]["login"]: return
|
||||||
|
name = stat["response"]["name"]
|
||||||
|
|
||||||
|
def restart():
|
||||||
|
get_app().exit(result="restart")
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
# Settings -> Accounts -> Log Out
|
# Settings -> Accounts -> Log Out
|
||||||
@@ -466,6 +473,7 @@ async def mainScreen():
|
|||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
async def _updateisettings():
|
async def _updateisettings():
|
||||||
|
if guestLogin: return
|
||||||
res = await server.setisettings("basic",intset)
|
res = await server.setisettings("basic",intset)
|
||||||
if res["type"]=="error":
|
if res["type"]=="error":
|
||||||
if res["server"]:
|
if res["server"]:
|
||||||
@@ -592,13 +600,20 @@ async def mainScreen():
|
|||||||
# Settings Menu
|
# Settings Menu
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
|
acc = HButtonSelect([("Log out",logout),("Change username",changename),("Change password",changepass)])
|
||||||
|
if guestLogin:
|
||||||
|
acc = HSplit([
|
||||||
|
Box(HButtonSelect([("Log out",logout)]),padding=0),
|
||||||
|
Label("You are currently logged in as a guest."),
|
||||||
|
])
|
||||||
|
|
||||||
settings = HSelectLayout(kb,[
|
settings = HSelectLayout(kb,[
|
||||||
HButtonSelect([("Log out",logout),("Change username",changename),("Change password",changepass)]),
|
acc,
|
||||||
|
|
||||||
HSplit([
|
HSplit([
|
||||||
Window(FormattedTextControl(text=showISettings,focusable=False),dont_extend_height=True),
|
Window(FormattedTextControl(text=showISettings,focusable=False),dont_extend_height=True),
|
||||||
Box(HButtonSelect([("Change color depth",changecolor),("Change text encoding",changeenc)]),padding=0),
|
Box(HButtonSelect([("Change color depth",changecolor),("Change text encoding",changeenc),("Apply changes",restart)]),padding=0),
|
||||||
Label("\n\nYou will need to restart or relog to apply any new changes."),
|
Label("\n\nYou will need to restart the interface or relog to apply any new changes."),
|
||||||
])
|
])
|
||||||
],[
|
],[
|
||||||
None,
|
None,
|
||||||
@@ -799,8 +814,14 @@ async def loginCredsScreen():
|
|||||||
def create_handler() -> None:
|
def create_handler() -> None:
|
||||||
get_app().exit(result="create")
|
get_app().exit(result="create")
|
||||||
|
|
||||||
|
def guest_handler() -> None:
|
||||||
|
global guestLogin
|
||||||
|
guestLogin = True
|
||||||
|
get_app().exit(result="guest")
|
||||||
|
|
||||||
login_button = Button(text="Log In", handler=ok_handler, width=16)
|
login_button = Button(text="Log In", handler=ok_handler, width=16)
|
||||||
create_button = Button(text="Create Account", handler=create_handler, width=16)
|
create_button = Button(text="Create Account", handler=create_handler, width=16)
|
||||||
|
guest_button = Button(text="Use Guest", handler=guest_handler, width=16)
|
||||||
exit_button = Button(text="Exit", handler=_return_none, width=16)
|
exit_button = Button(text="Exit", handler=_return_none, width=16)
|
||||||
|
|
||||||
usernameValidator = Validator.from_callable(isValidUsername, error_message='Invalid username')
|
usernameValidator = Validator.from_callable(isValidUsername, error_message='Invalid username')
|
||||||
@@ -835,7 +856,7 @@ async def loginCredsScreen():
|
|||||||
],
|
],
|
||||||
padding=D(preferred=1, max=1),
|
padding=D(preferred=1, max=1),
|
||||||
),
|
),
|
||||||
buttons=[login_button, create_button, exit_button],
|
buttons=[login_button, create_button, guest_button, exit_button],
|
||||||
with_background=True,
|
with_background=True,
|
||||||
)
|
)
|
||||||
app = Application(key_bindings=quitKB, layout=Layout(dialog), **defaultAppSettings())
|
app = Application(key_bindings=quitKB, layout=Layout(dialog), **defaultAppSettings())
|
||||||
@@ -847,8 +868,8 @@ async def loginCredsScreen():
|
|||||||
appres = await app.run_async()
|
appres = await app.run_async()
|
||||||
if type(appres)==tuple:
|
if type(appres)==tuple:
|
||||||
name,pwrd = appres
|
name,pwrd = appres
|
||||||
elif type(appres)==str and appres=="create":
|
elif type(appres)==str:
|
||||||
return "create"
|
return appres
|
||||||
else:
|
else:
|
||||||
await server.disconnect()
|
await server.disconnect()
|
||||||
exit()
|
exit()
|
||||||
@@ -867,7 +888,7 @@ async def logoutScreen():
|
|||||||
if res != "login": return
|
if res != "login": return
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
global intset
|
global intset, guestLogin
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(server.connect(), timeout=10)
|
await asyncio.wait_for(server.connect(), timeout=10)
|
||||||
@@ -888,11 +909,15 @@ async def main():
|
|||||||
await message_dialog(title="Error",text=f"{errorTxt(ires)}\n\nThese settings might not have been sent to the internal server.\nYou will be asked again the next time you log in to your account.").run_async()
|
await message_dialog(title="Error",text=f"{errorTxt(ires)}\n\nThese settings might not have been sent to the internal server.\nYou will be asked again the next time you log in to your account.").run_async()
|
||||||
else:
|
else:
|
||||||
intset = ires["response"]
|
intset = ires["response"]
|
||||||
|
if stat["response"]["login"] or guestLogin:
|
||||||
res = await mainScreen()
|
res = await mainScreen()
|
||||||
if res!="restart":
|
if res!="restart":
|
||||||
if res!="login":
|
if res!="login":
|
||||||
break
|
break
|
||||||
await server.logout()
|
if guestLogin:
|
||||||
|
guestLogin = False
|
||||||
|
else:
|
||||||
|
await server.logout()
|
||||||
else:
|
else:
|
||||||
intset = {"color":4,"encoding":"ascii"}
|
intset = {"color":4,"encoding":"ascii"}
|
||||||
await logoutScreen()
|
await logoutScreen()
|
||||||
|
|||||||
Reference in New Issue
Block a user