<jupyter_start><jupyter_text>Accessing a logged sessionOnce a user logs into a domain, their session is a saved for the next 24 hours.We will explore how a user can access a saved domain session.<jupyter_code>import syft as sy
# Let's login into a domain via `url`

ca_domain_client = sy.login(
    url="https://ca.openmined.com",
    email="<EMAIL>",
    password="<PASSWORD>",
    save_session=True,
)<jupyter_output><empty_output><jupyter_text>Connecting to Canada Domain...  Connected 🥰!    Logging in as <EMAIL>...  Logged in 🥳!    Saving your current session ... Saved 💾! When a user logs into a domain, a `session token` is generated w.r.t to that domain and user. This token can be used to authenticate a user into a domain without asking for username or password. This token has an auto-expiration time of `72 hrs (3 days)`. Once the session expires, then the user has to re-login into the domain via `username` and `password`. Since, currently we don't capture the user's timezone, therefore all datetime/timestamps are in `UTC`.<jupyter_code># Let's list all the saved sessions against each of the domains
sy.logins<jupyter_output><empty_output><jupyter_text>A user can select a saved session via its `Request Id`<jupyter_code># Let's a select a saved login session
# If the session is not expired, then an authenticated domain client is returned. 
ca_domain_client = sy.logins["<KEY>"]

# Or selecting the session via the Domain Name
ca_domain_client = sy.logins["Canada Domain"]
# If the session has expired, then the same is indicated
sy.logins["<KEY>"]
# If multiple sessions are present for the same Domain Name
# then raise an error and ask the user to select the session using the Session Id
sy.logins["Canada Domain"]<jupyter_output>[91mMutipleSessionsException[0m:
            Hi, mutiple sessions exists for the same Domain Name.
            Please select the session you want to login via the `Session Id`.<jupyter_text>Dummy Data Creation<jupyter_code>import datetime
import pandas as pd
from enum import Enum
import uuid


class bcolors(Enum):
    HEADER = "\033[95m"
    OKBLUE = "\033[94m"
    OKCYAN = "\033[96m"
    OKGREEN = "\033[92m"
    WARNING = "\033[93m"
    FAIL = "\033[91m"
    ENDC = "\033[0m"
    BOLD = "\033[1m"
    UNDERLINE = "\033[4m"

saved_logins = [
    {
        "Session Id": uuid.uuid4().hex,
        "Domain Name": "Canada Domain",
        "Last Login": datetime.datetime.now().strftime("%b %d %Y %I:%M%p"),
    },
    {
        "Session Id": uuid.uuid4().hex,
        "Domain Name": "Italy Domain",
        "Last Login": datetime.datetime.now().replace(hour=12).strftime("%b %d %Y %I:%M%p"),
    },
    {
        "Session Id": uuid.uuid4().hex,
        "Domain Name": "WHO",
        "Last Login": datetime.datetime.now().replace(hour=9).strftime("%b %d %Y %I:%M%p"),
    },
    {
        "Session Id": uuid.uuid4().hex,
        "Domain Name": "Stark Healthcare",
        "Last Login": datetime.datetime.now().replace(hour=11).strftime("%b %d %Y %I:%M%p"),
    },
]

saved_session_df = pd.DataFrame(saved_logins)
session_expiry_error = f"""
    {bcolors.FAIL.value}SessionExpiredException{bcolors.ENDC.value}:
        Hi !!! Your session with the {bcolors.BOLD.value}`Canada Domain`{bcolors.ENDC.value} has expired.
        Please re-login into the domain via {bcolors.WARNING.value}`username`{bcolors.ENDC.value} and {bcolors.WARNING.value}`password`{bcolors.ENDC.value}.    
"""

print(session_expiry_error)
mutiple_session_with_same_name = f"""
    {bcolors.FAIL.value}MutipleSessionsException{bcolors.ENDC.value}:
            Hi, mutiple sessions exists for the same Domain Name.
            Please select the session you want to login via the `Session Id`.
"""<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12056548412910109, 'fraction_numerical': 0.015737530008002133, 'mean_word_length': 3.734848484848485, 'pattern_counts': {'":': 12, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '611075', 'license': 'Apache-2.0', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1184, 'n_words': 393, 'path': 'notebooks/course3/mock_api_notebooks/DS Access a Logged Session.ipynb', 'repo_name': 'Noob-can-Compile/PySyft', 'size': '3824'}