add logging in as guest
This commit is contained in:
+32
-7
@@ -26,6 +26,8 @@ from api import ServerConnection
|
||||
|
||||
server = ServerConnection()
|
||||
|
||||
guestLogin = False
|
||||
|
||||
def errorTxt(obj):
|
||||
if obj["server"]:
|
||||
return f"Server error: {obj["error"]}"
|
||||
@@ -343,10 +345,15 @@ async def mainScreen():
|
||||
def exit_(event):
|
||||
event.app.exit()
|
||||
|
||||
if guestLogin:
|
||||
name = "[guest]"
|
||||
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
|
||||
@@ -466,6 +473,7 @@ async def mainScreen():
|
||||
# ------------------------------------------------------------
|
||||
|
||||
async def _updateisettings():
|
||||
if guestLogin: return
|
||||
res = await server.setisettings("basic",intset)
|
||||
if res["type"]=="error":
|
||||
if res["server"]:
|
||||
@@ -592,13 +600,20 @@ async def mainScreen():
|
||||
# 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,[
|
||||
HButtonSelect([("Log out",logout),("Change username",changename),("Change password",changepass)]),
|
||||
acc,
|
||||
|
||||
HSplit([
|
||||
Window(FormattedTextControl(text=showISettings,focusable=False),dont_extend_height=True),
|
||||
Box(HButtonSelect([("Change color depth",changecolor),("Change text encoding",changeenc)]),padding=0),
|
||||
Label("\n\nYou will need to restart or relog to apply any new changes."),
|
||||
Box(HButtonSelect([("Change color depth",changecolor),("Change text encoding",changeenc),("Apply changes",restart)]),padding=0),
|
||||
Label("\n\nYou will need to restart the interface or relog to apply any new changes."),
|
||||
])
|
||||
],[
|
||||
None,
|
||||
@@ -799,8 +814,14 @@ async def loginCredsScreen():
|
||||
def create_handler() -> None:
|
||||
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)
|
||||
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)
|
||||
|
||||
usernameValidator = Validator.from_callable(isValidUsername, error_message='Invalid username')
|
||||
@@ -835,7 +856,7 @@ async def loginCredsScreen():
|
||||
],
|
||||
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,
|
||||
)
|
||||
app = Application(key_bindings=quitKB, layout=Layout(dialog), **defaultAppSettings())
|
||||
@@ -847,8 +868,8 @@ async def loginCredsScreen():
|
||||
appres = await app.run_async()
|
||||
if type(appres)==tuple:
|
||||
name,pwrd = appres
|
||||
elif type(appres)==str and appres=="create":
|
||||
return "create"
|
||||
elif type(appres)==str:
|
||||
return appres
|
||||
else:
|
||||
await server.disconnect()
|
||||
exit()
|
||||
@@ -867,7 +888,7 @@ async def logoutScreen():
|
||||
if res != "login": return
|
||||
|
||||
async def main():
|
||||
global intset
|
||||
global intset, guestLogin
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(server.connect(), timeout=10)
|
||||
@@ -888,10 +909,14 @@ 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()
|
||||
else:
|
||||
intset = ires["response"]
|
||||
if stat["response"]["login"] or guestLogin:
|
||||
res = await mainScreen()
|
||||
if res!="restart":
|
||||
if res!="login":
|
||||
break
|
||||
if guestLogin:
|
||||
guestLogin = False
|
||||
else:
|
||||
await server.logout()
|
||||
else:
|
||||
intset = {"color":4,"encoding":"ascii"}
|
||||
|
||||
Reference in New Issue
Block a user