From 2c2c7f645f420b52f1086f6845cb7dfa8dfb3c39 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Sat, 24 Jun 2023 21:42:39 -0300 Subject: Add account management section. It is now possible to enable 2FA on accounts. --- game/core.rpy | 15 +++++ game/soul.rpy | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+) diff --git a/game/core.rpy b/game/core.rpy index e72d013..efc24bb 100644 --- a/game/core.rpy +++ b/game/core.rpy @@ -138,6 +138,21 @@ init -3 python: r=-1 return ifte(r is None, -1, r) + # Calculates a 2FA Token + def calcOTP(key): + if not LEGACY: + key = bytes(key, 'ascii') + msg = struct.pack(">Q", int(time.time()/30)) + h = hmac.new(key, msg, hashlib.sha1).digest() + if LEGACY: + o = ord(h[19]) & 15 + else: + o = (h[19] & 15) + _return = (struct.unpack(">I", h[o:o+4])[0] & 0x7fffffff) % 1000000 + _return = "%06d" % _return + print("TOTP: %s" % _return) + del msg, h, o + return _return ############################################################################# ## Some other stuff diff --git a/game/soul.rpy b/game/soul.rpy index 97ba518..f4d583e 100644 --- a/game/soul.rpy +++ b/game/soul.rpy @@ -3,6 +3,39 @@ # Copyright (C) 2021 Jesusalva # # Distributed under the MIT license, except for Steam parts. +################################################################################# +screen soulmsg(smessage): + zorder 100 + if mySoul is not None: + fixed: + frame: + background Frame("images/default.png", 0, 0) + xalign 0.5 + yalign 0.5 + xminimum 0.85 + xmaximum 0.85 + yminimum 0.8 + ymaximum 0.8 + label "{color=#FFF}%s{/color}" % smessage: + xalign 0.5 + yalign 0.5 + frame: + yalign 0.9 + xalign 0.9 + xmaximum 240 + button: + xmaximum 240 + ymaximum 40 + action Return(None) + fixed: + #add Frame("gui/button/choice_hover_background.png", 0, 0) + text _("OK »"): + color "#000" + xalign 0.5 + yalign 0.5 + + + ################################################################################# screen souldata(): zorder 100 @@ -46,6 +79,18 @@ screen souldata(): action Return("sethome") tooltip _("Sets a homeworld") null height 30 + ## TODO: Linking, Unlinking, 2FA, Password + hbox: + textbutton _("Manage Account"): + background Frame("gui/frame.png", 0, 0) + xysize (300, 40) + action Return("managevault") + tooltip _("Changes your account settings") + #textbutton _("Contact Support"): + # background Frame("gui/frame.png", 0, 0) + # xysize (100, 40) + # action None + # tooltip _("Contacts support staff") ## TODO: Other stuff null height 30 label "{color=#FFF}%s{/color}" % _("Scene Recollection") @@ -97,6 +142,89 @@ screen souldata(): +################################################################################# +screen accountdata(): + zorder 100 + if mySoul is not None: + fixed: + frame: + background Frame("images/default.png", 0, 0) + xalign 0.5 + yalign 0.5 + xminimum 0.85 + xmaximum 0.85 + yminimum 0.8 + ymaximum 0.8 + vbox: + null height 20 + if not persistent.steam: + label "{b}{color=#FFF}%s{/color}{/b}" % _("Account Management") + null height 20 + ## TODO: 2FA, Password, etc (hbox) + hbox: + spacing 5 + textbutton _("Reset password"): + background Frame("gui/frame.png", 0, 0) + xysize (250, 40) + action None + tooltip _("Changes your password") + textbutton _("Reset Two Factor"): + background Frame("gui/frame.png", 0, 0) + xysize (250, 40) + action Return(["2fa", None]) + tooltip _("Enables or disables 2FA") + else: + label "{b}{color=#FFF}%s{/color}{/b}" % _("Steam Account") + + null height 30 + label "{b}{color=#FFF}%s{/color}{/b}" % _("World Management") + null height 30 + ## Link/Unlink + vpgrid: + cols 3 + yspacing 30 + xspacing 10 + draggable True + mousewheel True + scrollbars "vertical" + side_xalign 0.5 + left_margin 60 + xfill True + ymaximum 0.6 + for srv in persistent.serverlist: + ## CR cannot be linked/unlinked + if srv["Name"] in ["The Crossroads", "Crossroads"]: + continue + ## Worlds and options + label "{size=-6}{a=%s}%s{/a}{/size}" % (srv["Link"], srv["Name"]) + textbutton _("Link Account"): + background Frame("gui/frame.png", 0, 0) + xysize (200, 40) + action Return(["link", srv]) + tooltip _("Links an external account to Vault") + textbutton _("Unlink"): + background Frame("gui/frame.png", 0, 0) + xysize (200, 40) + action Return(["unlink", srv]) + tooltip _("Removes a Vault account for manual login") + null height 40 # Padding + frame: + yalign 0.9 + xalign 0.9 + xmaximum 240 + button: + xmaximum 240 + ymaximum 40 + action Return(None) + fixed: + #add Frame("gui/button/choice_hover_background.png", 0, 0) + text _("Return »"): + color "#000" + xalign 0.5 + yalign 0.5 + + + ################################################################################# init python: class ManaSparkle(object): @@ -201,6 +329,51 @@ label sethome: return ################################################################################# +label managevault: + $ vault_loop = True + while vault_loop: + call screen accountdata() + if isinstance(_return, list): + $ _cmd = _return[0] + $ _arg = _return[1] + if _cmd is None: + $ vault_loop = False + elif _cmd == "2fa": + call screen soulmsg(_("{b}Two Factor Authentication{/b}\n\nIf you have two factor authentication enabled, it'll be disabled.\nIf it is disabled, it'll be enabled, and you'll receive an {b}email{/b} with instructions to generate TOTP tokens.\n\nIf enabled, you will not be able to login without the authentication token.")) + call screen confirm(_("{b}Two Factor Authentication{/b}\n\nAre you sure you want to change this setting?"), [SetVariable("_arg", True), Return()], [SetVariable("_arg", False), Return()]) + if _arg: + python: + auth = {"vaultId": vaultId, + "token": vaultToken, + "totp": calcOTP(vaultOTP)} + + ## Make the POST request + r=vault.post(VAULT_HOST+"/toggle2fa", json=auth, timeout=15.0) + if r.status_code != 200: + dat={} + else: + dat=r.json() + if r.status_code == 200: + call screen soulmsg(_("Your 2FA settings were updated.\n\nPlease check your email.")) + elif r.status_code == 400: + call screen soulmsg(_("An error on the client happened and the request was rejected. Are you logged in, and using the latest version?")) + elif r.status_code == 429: + call screen soulmsg(_("You are being rate-limited, and the change was not possible. Please wait a minute before trying again.")) + else: + call screen soulmsg(_("An internal error happened, please report (code: %d)" % r.status_code)) + elif _cmd == "link": + call screen soulmsg(_("Currently, you cannot link external accounts. Keep in mind that if you already have an account, nothing will happen.")) + pass + elif _cmd == "unlink": + call screen soulmsg(_("Currently, you cannot unlink accounts. Keep in mind that if you do not have an account, nothing will happen.")) + pass + else: + $ stdout("%s unrecognized" % _cmd) + else: + $ vault_loop = False + $ del vault_loop + return +################################################################################# label intro: $ RPCUpdate("The Void", "launcher") scene DKBG -- cgit v1.2.3-60-g2f50