Skip to content

Commit

Permalink
Add create_matrix_client class method to AuthenticatedController
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-russell committed Aug 21, 2024
1 parent e9698fb commit 802b95a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion fractal/cli/controllers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from clicz import cli_method
from django.db import transaction
from fractal.cli.utils import read_user_data, write_user_data
from fractal.matrix import MatrixClient, get_homeserver_for_matrix_id
from fractal.matrix import (
FractalAsyncClient,
MatrixClient,
get_homeserver_for_matrix_id,
)
from fractal.matrix.utils import parse_matrix_id, prompt_matrix_password
from fractal_database.utils import is_db_initialized
from nio import LoginError, WhoamiError
Expand Down Expand Up @@ -258,6 +262,19 @@ def get_creds(cls) -> Optional[Tuple[str, str, str]]:

return access_token, homeserver_url, matrix_id

@classmethod
def create_matrix_client(cls) -> FractalAsyncClient:
"""
Creates a matrix client with the current user's credentials.
"""
creds = cls.get_creds()
if not creds:
print("You must be logged in to use this command.")
print("Login with fractal login.")
exit(1)
access_token, homeserver_url, matrix_id = creds
return FractalAsyncClient(homeserver_url, access_token)

def check_if_user_is_authenticated(self) -> bool:
"""
Checks to see if the user is logged in.
Expand Down

0 comments on commit 802b95a

Please sign in to comment.