summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2021-12-18 17:20:00 -0300
committerJesusaves <cpntb1@ymail.com>2021-12-18 17:20:00 -0300
commit74276cba321ca2dcad511e40821b8562bfed7f7c (patch)
tree65bd9c3e077ea7aa0c48e5225a68f8c111c771c2
parent9e8e0d3ed6913dcda1bb4c7f41c3fe762578861a (diff)
downloadrenpy-74276cba321ca2dcad511e40821b8562bfed7f7c.tar.gz
renpy-74276cba321ca2dcad511e40821b8562bfed7f7c.tar.bz2
renpy-74276cba321ca2dcad511e40821b8562bfed7f7c.tar.xz
renpy-74276cba321ca2dcad511e40821b8562bfed7f7c.zip
Add a single screen login method
-rw-r--r--game/update.rpy13
-rw-r--r--game/vault.rpy203
2 files changed, 214 insertions, 2 deletions
diff --git a/game/update.rpy b/game/update.rpy
index 3a7e37f..30fec18 100644
--- a/game/update.rpy
+++ b/game/update.rpy
@@ -285,8 +285,10 @@ screen register_method():
hbox:
xalign 0.5
spacing 100
- textbutton _("Email Auth") action None#Return(1)
- textbutton _("Pass+2FA Auth") action Return(2)
+ #textbutton _("Email Auth") action None#Return(1)
+ #textbutton _("Pass+2FA Auth") action Return(2)
+ textbutton _("Single Screen") action Return(1)
+ textbutton _("Seamless") action Return(2)
screen register_input(prompt, mask=""):
## Ensure other screens do not get input while this screen is displayed.
@@ -333,12 +335,19 @@ screen notice(prompt):
label register:
$ status_update(" ", 80)
+
if persistent.vmethod is None:
call screen register_method
+ $ persistent.vmethod = _return
else:
$ _return = persistent.vmethod
+
$ status_update(pc=85)
$ method = int(_return)
+
+ if method == 1:
+ jump register_vault
+
$ email=""
while email == "":
call screen register_input(_("Please insert your {b}email{/b}."))
diff --git a/game/vault.rpy b/game/vault.rpy
new file mode 100644
index 0000000..3d6af09
--- /dev/null
+++ b/game/vault.rpy
@@ -0,0 +1,203 @@
+#################################################################################
+# This file is part of Mana Launcher.
+# Copyright (C) 2021 Jesusalva <jesusalva@tmw2.org>
+#
+# Distributed under the MIT license, except for Steam parts.
+#################################################################################
+# This is for Vault accounts
+
+default uedit = {"mail": "", "pasd": "", "totp": ""}
+
+init python:
+ def ueditor_input(key, temp="", tp="str"):
+ #temp=renpy.input("Please insert new value for this variable.\nCurrent value: [variable]")
+ global uedit
+ variable=""
+
+ # Convert input if needed
+ # tp int → convert to int
+ # tp key → Replace the key
+ # tp bool → Toogles the value
+ if tp == "int":
+ try:
+ variable=int(temp)
+ except:
+ renpy.notify("Invalid numeric input")
+ variable=0 # Sorry, but gets bad otherwise
+ else:
+ try:
+ variable=str(temp)
+ except:
+ renpy.notify("Invalid string input")
+
+ # Save input
+ uedit[key] = variable
+ return
+
+ class UEditorInputValue(InputValue):
+ # inpu: str or int
+ def __init__(self, key, placeholder="", inpu="str"):
+ global uedit
+ self.key = key
+ self.variable = uedit[key] or str(placeholder)
+ self.inpu = inpu
+
+ self.default=True
+ self.editable=True
+
+ def get_text(self):
+ try:
+ return str(self.variable)
+ except:
+ traceback.print_exc()
+ return ""
+ #return globals()[self.variable]
+
+ def set_text(self, s):
+ #globals()[self.variable] = s
+ ueditor_input(self.key, s, self.inpu)
+
+ def enter(self):
+ renpy.restart_interaction()
+ #renpy.run(self.Disable())
+ #raise renpy.IgnoreEvent()
+
+
+screen register_vault():
+ ## Ensure other screens do not get input while this screen is displayed.
+ modal True
+ zorder 200
+ style_prefix "confirm"
+ add "gui/overlay/confirm.png"
+ frame:
+ vbox:
+ xalign .5
+ yalign .5
+ spacing 30
+ label _("Welcome to the {b}Mana Launcher{/b}!\n\nIf you do not have an account, one will be created for you."):
+ style "confirm_prompt"
+ xalign 0.5
+
+ null height 24
+
+ hbox:
+ spacing 10
+ label _("Email: ")
+ $ input=Input(
+ value=UEditorInputValue("mail", "a@a.com", "str"),
+ copypaste=True,
+ allow="qwertyuiopasdfghjklçzxcvbnm QWERTYUIOPASDFGHJKLÇZXCVBNM1234567890-+=!(),.:;@",
+ length=52)
+ button:
+ #key_events True
+ action input.enable
+ add input
+
+ null height 12
+ hbox:
+ spacing 10
+ label _("Password: ")
+ $ input=Input(
+ value=UEditorInputValue("pasd", "***", "str"),
+ copypaste=True,
+ allow="qwertyuiopasdfghjklçzxcvbnm QWERTYUIOPASDFGHJKLÇZXCVBNM1234567890-+=!(),.:;@*^",
+ length=52,
+ mask="*")
+ button:
+ #key_events True
+ action input.enable
+ add input
+
+
+ null height 12
+ showif persistent.totp is None:
+ hbox:
+ spacing 10
+ label _("TOTP: ")
+ $ input=Input(
+ value=UEditorInputValue("totp", "000000", "str"),
+ copypaste=True,
+ allow="1234567890",
+ length=6)
+ button:
+ #key_events True
+ action input.enable
+ add input
+
+ # FIXME: Checkboxes
+ # * Remember me
+ # * Disable 2FA/TOTP
+
+ null height 24
+ hbox:
+ xalign 0.5
+ spacing 100
+ textbutton _("OK"):
+ action ifte(len(uedit["pasd"]) >= 4, Return(), None)
+ keysym ['K_KP_ENTER', 'K_RETURN']
+
+label register_vault:
+ call screen register_vault()
+
+ $ status_update(pc=92)
+ if persistent.totp is not None:
+ python:
+ key = base64.b32decode(persistent.totp.encode('utf-8'), True)
+ msg = struct.pack(">Q", int(time.time()/30))
+ h = hmac.new(key, msg, hashlib.sha1).digest()
+ o = ord(h[19]) & 15
+ _return = (struct.unpack(">I", h[o:o+4])[0] & 0x7fffffff) % 1000000
+ _return = "%06d" % _return
+ print("TOTP: %s" % _return)
+ uedit["totp"] = _return
+ del key, msg, h, o
+
+ $ email = uedit["mail"]
+ $ password = uedit["pasd"]
+ $ code2FA = uedit["totp"]
+
+ $ status_update(pc=95)
+ $ data = {"mail": email,
+ "pass": password,
+ "totp": code2FA[:6]
+ }
+ $ r = vault.post(VAULT_HOST+"/user_auth", json=data)
+
+ # Wait for Vault to confirm.
+ if (r.status_code != 200):
+ call screen notice(_("Vault returned error %d\n\nPlease try again later." % r.status_code))
+ return
+
+ # Check if we have success
+ python:
+ try:
+ status_update(pc=98)
+ stdout("Vault result: (%d) %s" % (r.status_code, ifte(config.developer, r.text, "OK")))
+ auth2 = r.json()
+ vaultId = auth2["vaultId"]
+ vaultToken = auth2["token"]
+ except:
+ traceback.print_exc()
+ stdout("Error - Vault result is bad.")
+
+ # Maybe we got a message informing this is a new account?
+ try:
+ if (auth2["status"] == 1):
+ status_update("Creating account and logging in...")
+ renpy.notify("Account created! Check email.")
+ time.sleep(1.0)
+ except:
+ pass
+
+ ############
+ ## Cleanup
+ $ del data
+ $ del code2FA
+ $ del email
+ $ del method
+ if vaultId:
+ $ status_update(_("Success!"), 100)
+ else:
+ $ status_update(_("{color=#F00}Failure!{/color}"), pc=100)
+ return
+