diff --git a/allgo/__init__.py b/allgo/__init__.py index fe9a79adaac7271adf23c963c30b318f70b74aee..b72714f651886c96886c8cf66a9d3856abaa5aaa 100644 --- a/allgo/__init__.py +++ b/allgo/__init__.py @@ -24,6 +24,34 @@ def local_token(): with open(filetoken) as f: return f.read() +class Init: + """ + manage initialization of the API. + check if there is an existing token + | No: generate a temporary token and return the allgo login page + | Yes: Display "Allgo is already initialized" + + """ + + def __init__(self): + """Initialization of Allgo-instance. + + Parameters + ---------- + Returns + ------- + string + allgo login page link or already initialized message + """ + self._token = token or os.getenv('ALLGO_TOKEN') or _local_token() + if None is self._token: + tmp_token = get_random_string(length=32) + msg = "allgo_token = " + tmp_token + msg += "<p>Sign in with your existing <a href=\"https://allgo18.inria.fr/accounts/login/?token=" + tmp_token+ "\">A||GO account </a></p>" + return msg + else: + msg = "<p>A||GO already initialized</p>" + return msg class App: """