Skip to content

Commit

Permalink
Fixes registration. register controller now logs you in
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-russell committed May 17, 2024
1 parent e309f0d commit 88924cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
12 changes: 7 additions & 5 deletions fractal/cli/controllers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions fractal/cli/controllers/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fractal-cli"
version = "0.1.3"
version = "0.1.4"
description = ""
authors = ["Mo Balaa <balaa@fractalnetworks.co>"]
readme = "README.md"
Expand Down

0 comments on commit 88924cb

Please sign in to comment.