Files
ecw-charge-validation/tools/add_portal_user.py
T
ManikandanandClaude Opus 5.5 ba15a574ab Initial import: eCW Charge Validation bot and results Portal
Snapshot of the working project as of 2026-10-23 (local 2d4d4fc), one
commit with no earlier history: the tracked files were de-identified
first (synthetic claim ids and patient data only; see Context.md
section 7). Credentials, run logs, screenshots, claim reports and client
workbooks are gitignored and not included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 18:38:17 +05:30

58 lines
2.1 KiB
Python

"""
Add a Portal User from this PC — the way the first Admin is made, when
nobody can sign in to the Portal yet (spec 2026-10-22 Stage 2, EEWA-32).
python tools\\add_portal_user.py (asks for everything)
python tools\\add_portal_user.py asha 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)}) [Admin]: ").strip() or "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:]))