add auth
This commit is contained in:
22 files changed
+1034
-25
No files matched your search
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import getpass
|
||||
import json
|
||||
from datetime import date
|
||||
|
||||
@@ -27,6 +28,9 @@ def main() -> int:
|
||||
report_cmd.add_argument("--print", action="store_true", help="print, do not send")
|
||||
sub.add_parser("stats", help="print a summary as JSON")
|
||||
|
||||
setpw = sub.add_parser("set-password", help="set or replace the web login password")
|
||||
setpw.add_argument("--username", default=None, help="defaults to the current one")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "serve":
|
||||
@@ -69,6 +73,21 @@ def main() -> int:
|
||||
ensure_ascii=False,
|
||||
)
|
||||
)
|
||||
elif args.command == "set-password":
|
||||
from app.services import auth_service
|
||||
|
||||
password = getpass.getpass("New web login password: ")
|
||||
if password != getpass.getpass("Confirm: "):
|
||||
print("Passwords did not match.")
|
||||
return 1
|
||||
if len(password) < 8:
|
||||
print("Use at least 8 characters.")
|
||||
return 1
|
||||
if args.username:
|
||||
settings.auth.username = args.username
|
||||
settings.auth.password_hash = auth_service.hash_password(password)
|
||||
settings_service.save_settings(session, settings)
|
||||
print(f"Password set for {settings.auth.username!r}.")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user