From 84993c76f6337ff2ebc2893f2ec2e7be0fda9e93 Mon Sep 17 00:00:00 2001
From: GARNIER Laurent <laurent.garnier@irisa.fr>
Date: Tue, 19 Oct 2021 09:41:57 +0000
Subject: [PATCH] Update allgo/__init__.py

---
 allgo/__init__.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/allgo/__init__.py b/allgo/__init__.py
index fe9a79a..b72714f 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:
     """
-- 
GitLab