Files
ManikandanandClaude Opus 5.5 ce9bdbd974 Sign-in page redesign and Portal roles Super Admin / Admin / Viewer
Sign-in: brand panel, show / hide password, Caps Lock warning, moving
background, tab icon. Roles: Super Admin manages Admins and Viewers,
Admin manages Viewers only (and can Start / Stop, see Sign-ins), Viewer
sees claims and Runs only. create_tables.sql moves an old table.
71 test files, 1220 tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 13:45:44 +05:30

60 lines
2.2 KiB
Python

"""
Add a Portal User from this PC — the way the first Super Admin is made,
when nobody can sign in to the Portal yet, and the only way to make any
Super Admin (spec 2026-10-22 Stage 2, EEWA-32; roles 2026-10-27).
python tools\\add_portal_user.py (asks for everything)
python tools\\add_portal_user.py asha "Super Admin" "Asha R"
The password is typed hidden and twice; it is never shown, logged or
passed on the command line. Needs `tools\\sql\\create_tables.sql` run once
(CV_PortalUser / CV_PortalSignIn) and RESULTS_DB_CONN in .env.
"""
# Run standalone from the project root: python tools\add_portal_user.py
import sys as _sys
from pathlib import Path as _Path
_ROOT = _Path(__file__).resolve().parent.parent
_sys.path.insert(0, str(_ROOT / "src"))
_sys.path.insert(0, str(_ROOT))
for _s in (_sys.stdout, _sys.stderr):
try:
_s.reconfigure(encoding="utf-8", errors="replace")
except Exception:
pass
import sys
import getpass
from ecw_bot import settings as cfg
from web.users import Accounts, ROLES, SqlUserStore, UserError
def main(argv) -> int:
username = argv[0] if argv else input("Username: ").strip()
role = argv[1] if len(argv) > 1 else (
input(f"Role ({' / '.join(ROLES)}) [Super Admin]: ").strip()
or "Super Admin")
name = argv[2] if len(argv) > 2 else input("Name shown on the Portal: ")
password = getpass.getpass("Password (10+ characters, hidden): ")
if getpass.getpass("Password again: ") != password:
print("[USER] The two passwords are not the same — nothing added")
return 2
accounts = Accounts(SqlUserStore(cfg.RESULTS_DB_CONN))
try:
user = accounts.create_user(username, name, role, password)
except UserError as exc:
print(f"[USER] {exc} — nothing added")
return 2
except Exception as exc:
print(f"[USER] Could not reach the database ({type(exc).__name__}) "
f"— run tools\\sql\\create_tables.sql once and check "
f"RESULTS_DB_CONN in .env")
return 1
print(f"[USER] {user['username']} added as {user['role']}. Sign in at "
f"http://127.0.0.1:8000/signin")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))