From 88924cba61100659a87b1776150833466af9605f Mon Sep 17 00:00:00 2001 From: Justin Date: Fri, 17 May 2024 16:48:41 -0500 Subject: [PATCH] Fixes registration. register controller now logs you in --- fractal/cli/controllers/auth.py | 12 +++++++----- fractal/cli/controllers/registration.py | 12 ++++++++++-- pyproject.toml | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/fractal/cli/controllers/auth.py b/fractal/cli/controllers/auth.py index 5836bb1..659b4d4 100644 --- a/fractal/cli/controllers/auth.py +++ b/fractal/cli/controllers/auth.py @@ -172,7 +172,7 @@ def show(self, key: str): try: data, _ = read_user_data(self.TOKEN_FILE) except (KeyError, FileNotFoundError): - print(f"You are not logged in") + print("You are not logged in") exit(1) match key: @@ -206,15 +206,17 @@ def _login(self, homeserver_url: str): self.access_token = access_token @classmethod - def get_creds(cls) -> Optional[Tuple[Optional[str], Optional[str], Optional[str]]]: + def get_creds(cls) -> Optional[Tuple[str, str, str]]: """ Returns the access token of the logged in user. """ try: token_file, _ = read_user_data(cls.TOKEN_FILE) - access_token = token_file.get("access_token") - homeserver_url = token_file.get("homeserver_url") - matrix_id = token_file.get("matrix_id") + access_token = token_file["access_token"] + homeserver_url = token_file["homeserver_url"] + matrix_id = token_file["matrix_id"] + except KeyError: + return None except FileNotFoundError: return None diff --git a/fractal/cli/controllers/registration.py b/fractal/cli/controllers/registration.py index ec03114..595e13c 100644 --- a/fractal/cli/controllers/registration.py +++ b/fractal/cli/controllers/registration.py @@ -8,7 +8,11 @@ import docker from clicz import cli_method from docker.models.containers import Container -from fractal.cli.controllers.auth import AuthenticatedController, auth_required +from fractal.cli.controllers.auth import ( + AuthController, + AuthenticatedController, + auth_required, +) from fractal.matrix import MatrixClient, get_homeserver_for_matrix_id from fractal.matrix.utils import parse_matrix_id from nio import LoginError @@ -148,7 +152,11 @@ def register( local=local, ) ) - print(access_token) + + # login as the registered user + AuthController().login( + matrix_id, homeserver_url=homeserver_url, access_token=access_token + ) register.clicz_aliases = ["register"] diff --git a/pyproject.toml b/pyproject.toml index 724f5b2..de062f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fractal-cli" -version = "0.1.3" +version = "0.1.4" description = "" authors = ["Mo Balaa "] readme = "README.md"