# Part C live: the sign-up block on apps whose gate is open. argv: phase app... # check — block file present; a stranger's sign-up is refused (page + API); the rest of the app still answers; # the app page shows the sign-up card with the how-to and the window button # window — the household opens sign-up for 15 minutes; a "family member" signs up; the page says until when # closed — after the window: the block is back, a stranger is refused again import json, secrets, subprocess, sys, time sys.path.insert(0, '.') import ro from ro import w, host from browser import Browser SIGNUP = { # the stranger's / family member's sign-up call, per app "gitea": ("GET", "/user/sign_up", None), "calcom": ("POST", "/api/auth/signup", lambda n: {"username": n, "email": n + "@x.hu", "password": "Xx12345678z!A"}), } def try_signup(app, who): m, p, body = SIGNUP[app] s = Browser(who) b = body(who + secrets.token_hex(3)) if body else None st, text, _ = s.req(f"https://{host(app)}{p}", m, body=b, accept="application/json" if m == "POST" else "text/html") closed = "sign-up is closed" in text or "nem lehet regisztr" in text return st, closed, text[:70].replace("\n", " ") w.login() phase, apps = sys.argv[1], sys.argv[2:] for app in apps: if phase == "check": w.say(app, ro.gstate(app)) st, closed, t = try_signup(app, "stranger") s = Browser("stranger") st2, body2, _ = s.req(f"https://{host(app)}/") w.say(app, f"STRANGER sign-up -> {st} closed-answer={closed} | the app's home page -> {st2} len {len(body2)}") s3 = Browser("stranger-browser") st3, body3, _ = s3.req(f"https://{host(app)}{SIGNUP[app][1]}") w.say(app, f"STRANGER browser on the sign-up address -> {st3} page says closed (hu-ascii 'nem lehet regisztr'): {'nem lehet regisztr' in body3}") page = w.page(f"/apps/{app}") w.say(app, f"APP PAGE: sign-up card {'id=\"signup-card\"' in page} | how-to {'id=\"add-people\"' in page} | window button {'/signup-window' in page}") elif phase == "window": code, d = w.ctl("POST", f"/apps/{app}/signup-window", {}) w.say(app, "HOUSEHOLD opens sign-up for 15 minutes ->", code, str(d)[:90]) time.sleep(3) st, closed, t = try_signup(app, "family") w.say(app, f"a family member signs up inside the window -> {st} closed-answer={closed} {t!r} | {ro.gstate(app)}") page = w.page(f"/apps/{app}") w.say(app, "APP PAGE during the window: says open until:", "nyitva, eddig" in page, "| window button hidden:", "/signup-window" not in page) elif phase == "closed": st, closed, t = try_signup(app, "stranger") w.say(app, f"AFTER the window: stranger sign-up -> {st} closed-answer={closed} | {ro.gstate(app)}")