mickael9 avatar mickael9 committed b0b603a

Add ability to use multiple accounts

Comments (0)

Files changed (1)

     other_group.add_argument('--list', nargs='*', dest='list', metavar='SHARE_NAME', help='List the files in the specified share. If no share is specified, list all your shares.')
 
     auth_group = parser.add_argument_group('Authentification')
+    auth_group.add_argument('-L', dest='ignore_token', action='store_true', help='Log-in with a different account than the stored one (if any)')
     auth_group.add_argument('-e', dest='email', help='Email to login with')
     auth_group.add_argument('-p', dest='password', help='Password to login with')
     auth_group.add_argument('-k', dest='tokenfile', help='Ge.tt token file path (~/.gett-token)', default=os.path.join(home, '.gett-token'))
         gett.DEBUG = True
 
     user = User()
+    logged = False
 
-    try:
-        # Try to log-in with the token
+    # If not logging-in with a different account
 
-        token = open(args.tokenfile, 'r').read()
-        user.login_token(token)
-    except:
-        # If it doesn't work, ask the user his email and password
+    if not args.ignore_token and not args.email:
+        try:
+            # Try to log-in with the token
 
+            token = open(args.tokenfile, 'r').read()
+            user.login_token(token)
+
+            logged = True
+        except:
+            pass
+
+    if not logged:
         if not args.email:
             args.email = input('Please enter your Ge.tt email: ')
 
             print('Unable to login: %s' % ex.args[0])
             sys.exit(1)
 
-    # Save the refreshtoken to the user's home directory
+        reply = input('Do you wish to store the session token? (y/n): ')
 
-    with open(args.tokenfile, 'w') as file:
-        file.write(user.rtoken)
+        if reply.lower() == 'y':
+            # Save the refreshtoken to the user's home directory (by default)
+
+            with open(args.tokenfile, 'w') as file:
+                file.write(user.rtoken)
 
 
     # --list command
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.